-
Notifications
You must be signed in to change notification settings - Fork 33
/
CMakeLists.txt
154 lines (139 loc) · 6.19 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
cmake_minimum_required (VERSION 2.8)
project(ScatteredContainers)
# Module path
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
set(COMMON_INCLUDES ${PROJECT_SOURCE_DIR})
set(EXT_PROJECTS_DIR ${PROJECT_SOURCE_DIR}/ext)
# Environment
set(CMAKE_OSX_SYSROOT $ENV{SDKROOT})
# Configure compiler:
message("Build type: ${CMAKE_BUILD_TYPE}")
message("The compiler is: ${CMAKE_CXX_COMPILER}")
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# libcxx:
include_directories(SYSTEM ${LIBCXX_INCLUDE_DIR})
message("libcxx_include: ${LIBCXX_INCLUDE_DIR} | libcxx_lib: ${LIBCXX_LIBRARY}")
set(CMAKE_EXE_LINKER_FLAGS " ${CMAKE_EXE_LINKER_FLAGS} -L${LIBCXX_LIBRARY} -lc++")
message("linker flags: ${CMAKE_EXE_LINKER_FLAGS}")
# compiler flags:
set(CMAKE_CXX_FLAGS_LIST
"-arch x86_64" "-Wall" "-Wextra" "-std=c++1y" "-stdlib=libc++"
"-pedantic" "-Wshadow" "-Woverloaded-virtual"
"-pedantic-errors" "-Wcast-align" "-Wcomment" "-Wcast-qual"
"-Wchar-subscripts" "-Wdisabled-optimization" "-Wfloat-equal" "-Wformat=2"
"-Winvalid-pch" "-Wformat-nonliteral" "-Wformat-security" "-Wformat-y2k"
"-Wimport" "-Winit-self" "-Winline" "-Wreturn-type" "-Wmissing-braces"
"-Wmissing-field-initializers" "-Wmissing-include-dirs" "-Wredundant-decls"
"-Wpacked" "-Wparentheses" "-Wpointer-arith" "-Wsequence-point"
"-Wsign-compare" "-Wstack-protector" "-Wstrict-aliasing=2" "-Wswitch"
"-Wswitch-default" "-Wtrigraphs" "-Wuninitialized" "-Wunknown-pragmas"
"-Wunreachable-code" "-Wunused" "-Wunused-function" "-Wunused-label"
"-Wunused-parameter" "-Wunused-value" "-Wunused-variable"
"-Wvariadic-macros" "-Wvolatile-register-var" "-Wwrite-strings"
"-Woverloaded-virtual" "-Wsign-promo" "-Wstrict-overflow=5"
"-Wswitch-default" "-DGTEST_USE_OWN_TR1_TUPLE=1"
"-fdiagnostics-show-template-tree" "-ftemplate-backtrace-limit=0"
"-Wno-attributes" "-DFUSION_MAX_MAP_SIZE=40" "-DFUSION_MAX_VECTOR_SIZE=40"
)
set(CMAKE_CXX_FLAGS_DEBUG_LIST
"-O1" "-g3" "-fstack-protector-all"
"-fsanitize=address" "-fno-omit-frame-pointer"
) # -D_LIBCPP_DEBUG2=1
set(CMAKE_CXX_FLAGS_RELEASE_LIST
"-O3" "-DNDEBUG" "-march=native" "-mtune=native" "-fstrict-aliasing"
"-fomit-frame-pointer" "-pipe" "-fdata-sections" "-ffunction-sections"
"-fvectorize" "-fslp-vectorize-aggressive" "-DEIGEN_FAST_MATH"
"-DEIGEN_NO_DEBUG" "-ffast-math"
) # -fno-rtti -fno-exceptions
set(CMAKE_CXX_FLAGS_ASAN_LIST
${CMAKE_CXX_FLAGS_RELEASE_LIST}
"-fsanitize=address" "-fno-omit-frame-pointer"
)
set(CMAKE_CXX_FLAGS_MSAN_LIST
${CMAKE_CXX_FLAGS_RELEASE_LIST}
"-fsanitize=memory" "-fno-omit-frame-pointer"
"-fsanitize-memory-track-origins"
)
set(CMAKE_CXX_FLAGS_TSAN_LIST
${CMAKE_CXX_FLAGS_RELEASE_LIST}
"-fsanitize=thread" "-fno-omit-frame-pointer"
"-fsanitize-memory-track-origins"
)
# set flags:
string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_LIST}")
string(REPLACE ";" " " CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG_LIST}")
string(REPLACE ";" " " CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE_LIST}")
string(REPLACE ";" " " CMAKE_CXX_FLAGS_ASAN "${CMAKE_CXX_FLAGS_ASAN_LIST}")
string(REPLACE ";" " " CMAKE_CXX_FLAGS_MSAN "${CMAKE_CXX_FLAGS_MSAN_LIST}")
string(REPLACE ";" " " CMAKE_CXX_FLAGS_TSAN "${CMAKE_CXX_FLAGS_TSAN_LIST}")
# output flags:
message("...clang flags set: " ${CMAKE_CXX_FLAGS})
if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
message("...clang optimization flags set: ${CMAKE_CXX_FLAGS_DEBUG}")
elseif("${CMAKE_BUILD_TYPE}" MATCHES "Release")
message("...clang optimization flags set: ${CMAKE_CXX_FLAGS_RELEASE}")
elseif("${CMAKE_BUILD_TYPE}" MATCHES "Asan")
message("...clang optimization flags set: ${CMAKE_CXX_FLAGS_ASAN}")
set(CMAKE_EXE_LINKER_FLAGS " ${CMAKE_EXE_LINKER_FLAGS} -L${LIBCXX_LIBRARY} -lc++")
elseif("${CMAKE_BUILD_TYPE}" MATCHES "Msan")
message("...clang optimization flags set: ${CMAKE_CXX_FLAGS_MSAN}")
elseif("${CMAKE_BUILD_TYPE}" MATCHES "Tsan")
message("...clang optimization flags set: ${CMAKE_CXX_FLAGS_TSAN}")
else()
message(FATAL_ERROR "Unknown build type. Options are \"Debug\" and \"Release\". Quit.")
endif()
message("...linker flags set: ${CMAKE_EXE_LINKER_FLAGS}")
else()
message(FATAL_ERROR "Unknown compiler, quit.")
endif()
# boost
#set(Boost_USE_STATIC_LIBS OFF)
#set(Boost_USE_MULTITHREADED ON)
#set(Boost_USE_STATIC_RUNTIME ON)
#find_package(Boost 1.55 REQUIRED)
#include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
include_directories(SYSTEM ${BOOST_DIRS})
include_directories(SYSTEM ./)
# Catch (and enables unit testing)
add_subdirectory(${EXT_PROJECTS_DIR}/catch)
include_directories(${CATCH_INCLUDE_DIR} ${COMMON_INCLUDES})
enable_testing(true)
set(TESTING_INCLUDES ${CATCH_INCLUDE_DIR} )
function(add_scattered_test name)
include_directories(${TESTING_INCLUDES} ${COMMON_INCLUDES})
add_executable(${name}_test ${name}_test.cpp)
add_test(${name}_test ${name}_test)
endfunction(add_scattered_test)
function(add_benchmark name)
include_directories(${TESTING_INCLUDES} ${COMMON_INCLUDES})
add_executable(${name}_benchmark ${name}_benchmark.cpp)
add_test(${name}_benchmark ${name}_benchmark)
endfunction(add_benchmark)
# Doxygen (optional) - Enables "make docs"
option(BUILD_DOCUMENTATION "Use Doxygen to create the HTML documentation" ON)
if(BUILD_DOCUMENTATION)
find_package(Doxygen)
if (NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen can't be found.")
endif()
configure_file(Doxyfile.in ${PROJECT_BINARY_DIR}/Doxyfile @ONLY IMMEDIATE)
add_custom_target (docs
${DOXYGEN_EXECUTABLE}
${PROJECT_BINARY_DIR}/Doxyfile
SOURCES
${PROJECT_BINARY_DIR}/Doxyfile)
endif()
# Clean-up - enables "make clean"
set(CLEANUP_SCRIPT ${PROJECT_BINARY_DIR}/tools/cleanup.sh)
add_custom_target (clean ${CLEANUP_SCRIPT})
# Subdirectories:
add_subdirectory (./tests)
add_subdirectory (./benchmarks)
# Clang format
file(GLOB_RECURSE files *.hpp *.cpp)
add_custom_command(OUTPUT formatting COMMAND
${CMAKE_CURRENT_SOURCE_DIR}/tools/check_format.sh ${files})
add_custom_target(check-format DEPENDS formatting)
add_custom_command(OUTPUT formatting-update COMMAND
${CMAKE_CURRENT_SOURCE_DIR}/tools/update_format.sh ${files})
add_custom_target(update-format DEPENDS formatting-update)