-
Notifications
You must be signed in to change notification settings - Fork 23
/
CMakeLists.txt
189 lines (164 loc) · 6.11 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#structure inspired on duckdb
cmake_minimum_required(VERSION 2.8.12)
cmake_policy(SET CMP0026 NEW)
cmake_policy(SET CMP0051 NEW)
project(GPGOMEA)
find_package(Armadillo REQUIRED)
find_package(PythonInterp REQUIRED)
find_package(PythonLibs REQUIRED)
# Extract major/minor python version
string(REPLACE "." ";" VERSION_LIST ${PYTHONLIBS_VERSION_STRING})
list(GET VERSION_LIST 0 PYTHONLIBS_VERSION_MAJOR)
list(GET VERSION_LIST 1 PYTHONLIBS_VERSION_MINOR)
find_package(Boost COMPONENTS system filesystem program_options python${PYTHONLIBS_VERSION_MAJOR}${PYTHONLIBS_VERSION_MINOR} numpy${PYTHONLIBS_VERSION_MAJOR}${PYTHONLIBS_VERSION_MINOR} REQUIRED)
find_package(OpenMP REQUIRED)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_VERBOSE_MAKEFILE OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()
# Determine install paths
set(INSTALL_LIB_DIR
lib
CACHE PATH "Installation directory for libraries")
set(INSTALL_BIN_DIR
bin
CACHE PATH "Installation directory for executables")
set(INSTALL_INCLUDE_DIR
Include
CACHE PATH "Installation directory for header files")
set(DEF_INSTALL_CMAKE_DIR lib/cmake/GPGOMEA)
set(INSTALL_CMAKE_DIR
${DEF_INSTALL_CMAKE_DIR}
CACHE PATH "Installation directory for CMake files")
# Make relative install paths absolute
foreach(p LIB BIN INCLUDE CMAKE)
set(var INSTALL_${p}_DIR)
if(NOT IS_ABSOLUTE "${${var}}")
set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
endif()
endforeach()
option(FORCE_COLORED_OUTPUT
"Always produce ANSI-colored output (GNU/Clang only)." FALSE)
if(${FORCE_COLORED_OUTPUT})
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-fdiagnostics-color=always)
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options(-fcolor-diagnostics)
endif()
endif()
option(ENABLE_SANITIZER "Enable address sanitizer." TRUE)
option(ENABLE_UBSAN "Enable undefined behavior sanitizer." TRUE)
if(${ENABLE_SANITIZER})
if(FORCE_ASSERT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
else()
set(CXX_EXTRA_DEBUG "${CXX_EXTRA_DEBUG} -fsanitize=address")
endif()
endif()
if(${ENABLE_UBSAN})
if(FORCE_ASSERT)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
else()
set(CXX_EXTRA_DEBUG "${CXX_EXTRA_DEBUG} -fsanitize=undefined")
endif()
endif()
option(EXPLICIT_EXCEPTIONS "Explicitly enable C++ exceptions." FALSE)
if(${EXPLICIT_EXCEPTIONS})
set(CXX_EXTRA "${CXX_EXTRA} -fexceptions")
endif()
set(CMAKE_CXX_FLAGS_DEBUG
"${CMAKE_CXX_FLAGS_DEBUG} -g -O0 -DDEBUG -Wall ${M32_FLAG} ${CXX_EXTRA}")
set(CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG ${M32_FLAG} ${CXX_EXTRA}")
set(CXX_EXTRA_DEBUG
"${CXX_EXTRA_DEBUG} -Wunused-variable -Wunused-const-variable -Wnarrowing"
)
if(TREAT_WARNINGS_AS_ERRORS)
set(CXX_EXTRA_DEBUG "${CXX_EXTRA_DEBUG} -Werror")
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION
VERSION_GREATER 8.0)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CXX_EXTRA_DEBUG}")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang"
AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${CXX_EXTRA_DEBUG}")
else()
message(WARNING "Please use a recent compiler for debug builds")
endif()
function(enable_unity_build UB_SUFFIX SOURCE_VARIABLE_NAME)
set(files ${${SOURCE_VARIABLE_NAME}})
# Generate a unique filename for the unity build translation unit
set(unit_build_file ${CMAKE_CURRENT_BINARY_DIR}/ub_${UB_SUFFIX}.cpp)
set(temp_unit_build_file ${CMAKE_CURRENT_BINARY_DIR}/ub_${UB_SUFFIX}.cpp.tmp)
# Exclude all translation units from compilation
set_source_files_properties(${files} PROPERTIES HEADER_FILE_ONLY true)
set(rebuild FALSE)
# check if any of the source files have changed
foreach(source_file ${files})
if(${CMAKE_CURRENT_SOURCE_DIR}/${source_file} IS_NEWER_THAN
${unit_build_file})
set(rebuild TRUE)
endif()
endforeach(source_file)
# write a temporary file
file(WRITE ${temp_unit_build_file} "// Unity Build generated by CMake\n")
foreach(source_file ${files})
file(
APPEND ${temp_unit_build_file}
"#include <${CMAKE_CURRENT_SOURCE_DIR}/${source_file}>\n"
)
endforeach(source_file)
execute_process(
COMMAND ${CMAKE_COMMAND} -E compare_files ${unit_build_file}
${temp_unit_build_file}
RESULT_VARIABLE compare_result
OUTPUT_VARIABLE bla
ERROR_VARIABLE bla)
if(compare_result EQUAL 0)
# files are identical: do nothing
elseif(compare_result EQUAL 1)
# files are different: rebuild
set(rebuild TRUE)
else()
# error while compiling: rebuild
set(rebuild TRUE)
endif()
if(${rebuild})
file(WRITE ${unit_build_file} "// Unity Build generated by CMake\n")
foreach(source_file ${files})
file(
APPEND ${unit_build_file}
"#include <${CMAKE_CURRENT_SOURCE_DIR}/${source_file}>\n"
)
endforeach(source_file)
endif()
# Complement list of translation units with the name of ub
set(${SOURCE_VARIABLE_NAME}
${${SOURCE_VARIABLE_NAME}} ${unit_build_file}
PARENT_SCOPE)
endfunction(enable_unity_build)
function(add_library_unity NAME MODE)
set(SRCS ${ARGN})
if(NOT DISABLE_UNITY)
enable_unity_build(${NAME} SRCS)
endif()
add_library(${NAME} OBJECT ${SRCS})
endfunction()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(DEFAULT_BUILD_TYPE "Release")
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}'.")
set(CMAKE_BUILD_TYPE
"${DEFAULT_BUILD_TYPE}"
CACHE STRING "Choose the type of build." FORCE)
endif()
include_directories(src/Include)
include_directories(${ARMADILLO_INCLUDE_DIR})
include_directories(${Boost_INCLUDE_DIR})
include_directories(${PYTHON_INCLUDE_PATH})
add_compile_options(${OpenMP_CXX_FLAGS})
add_subdirectory(src)