forked from kfrlib/kfr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
153 lines (121 loc) · 5 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Copyright (C) 2016 D Levin (http://www.kfrlib.com)
# This file is part of KFR
#
# KFR is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# KFR is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with KFR.
cmake_minimum_required(VERSION 2.8)
if (CMAKE_VERSION VERSION_LESS "2.8.12")
function(add_compile_options)
add_definitions(${ARGN})
endfunction(add_compile_options)
endif ()
#set(DISABLE_CLANG 1)
if(NOT CMAKE_CXX_COMPILER)
if (${CMAKE_GENERATOR} STREQUAL "MinGW Makefiles"
OR ${CMAKE_GENERATOR} STREQUAL "MSYS Makefiles"
OR ${CMAKE_GENERATOR} STREQUAL "Unix Makefiles"
OR ${CMAKE_GENERATOR} STREQUAL "Ninja")
# Find clang and set as c++ compiler for MinGW, MSYS and Unix
# If clang is not found, leave default compiler (usually GCC)
if(NOT DISABLE_CLANG)
find_program(CLANG_CXX_PATH clang++-4.0)
find_program(CLANG_CXX_PATH clang++-3.9)
find_program(CLANG_CXX_PATH clang++-3.8)
find_program(CLANG_CXX_PATH clang++-3.7)
find_program(CLANG_CXX_PATH clang++-3.6)
find_program(CLANG_CXX_PATH clang++)
# If clang is found
if(CLANG_CXX_PATH)
set(CMAKE_CXX_COMPILER ${CLANG_CXX_PATH})
message(STATUS "Clang found")
else()
message(STATUS "Clang not found")
endif()
else()
message(STATUS "Clang disabled")
endif()
elseif (${CMAKE_GENERATOR} STREQUAL "Visual Studio 14 2015"
OR ${CMAKE_GENERATOR} STREQUAL "Visual Studio 14 2015 Win64")
# Find LLVM-vs2014 toolset for MSVC
# If clang is not found, leave default Microsoft's cl.exe compiler
if(NOT DISABLE_CLANG)
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/test_toolset")
# Check if toolset can be set
execute_process(COMMAND "${CMAKE_COMMAND}" -G "Visual Studio 14 2015" -T LLVM-vs2014 "${CMAKE_SOURCE_DIR}/cmake/test_toolset" WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/test_toolset" RESULT_VARIABLE TOOLSET_EXISTS OUTPUT_QUIET ERROR_QUIET)
if(${TOOLSET_EXISTS} EQUAL 0)
set(CMAKE_GENERATOR_TOOLSET LLVM-vs2014)
message(STATUS "LLVM-vs2014 found")
else()
message(STATUS "LLVM-vs2014 not found")
endif()
else()
message(STATUS "LLVM-vs2014 disabled")
endif()
endif()
endif()
if (${CMAKE_GENERATOR} STREQUAL "MinGW Makefiles"
OR ${CMAKE_GENERATOR} STREQUAL "MSYS Makefiles"
OR ${CMAKE_GENERATOR} STREQUAL "Unix Makefiles"
OR ${CMAKE_GENERATOR} STREQUAL "Ninja")
if (CMAKE_CXX_COMPILER MATCHES "clang")
if (WIN32)
# On windows, clang requires --target
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --target=x86_64-w64-windows-gnu" CACHE STRING "cxx compile flags" FORCE)
endif()
endif()
endif()
####################################
# Release build by default
if (CMAKE_BUILD_TYPE_INITIALIZED_TO_DEFAULT)
set(CMAKE_BUILD_TYPE Release)
endif ()
# Only Debug and Release builds
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "config types" FORCE)
# Insert common c++ flags here
set(CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS}" CACHE STRING "compile flags" FORCE)
project(kfr CXX)
message(STATUS "C++ compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} ${CMAKE_CXX_COMPILER} ")
# Binary output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_BINARY_DIR}/bin/Debug)
# Include list of source files
include(sources.cmake)
if (IOS)
set(STD_LIB)
else ()
set(STD_LIB stdc++)
endif ()
if (NOT MSVC)
# Enable C++14, disable exceptions and rtti
add_compile_options(-std=c++1y -fno-exceptions -fno-rtti )
if (NOT ARCH_FLAGS)
add_compile_options(-march=native)
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mstackrealign -fno-asynchronous-unwind-tables")
endif()
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_FLAGS}")
endif ()
link_libraries(${STD_LIB} pthread m)
else ()
# Disable exceptions
add_compile_options(/EHsc /D_HAS_EXCEPTIONS=0 /D_CRT_SECURE_NO_WARNINGS=1)
add_compile_options(/arch:AVX)
endif ()
if ("${CMAKE_GENERATOR_TOOLSET}" STREQUAL "LLVM-vs2014")
add_compile_options( -Wno-unused-command-line-argument )
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/tests/cmake/")
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/svg)
add_subdirectory(examples)
add_subdirectory(tests)