-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
157 lines (125 loc) · 6.25 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
cmake_minimum_required(VERSION 3.9)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(DISTRAC_PROJECT OFF)
else()
set(DISTRAC_PROJECT ON)
endif()
if(DISTRAC_PROJECT)
project(distrac
LANGUAGES C CXX
VERSION 0.1.0)
set(BUILD_NUMBER "0" CACHE STRING "Build-Number")
set(BUILD_URL "" CACHE STRING "Unique URL to identify this build.")
set(VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}+${BUILD_NUMBER})
option(DEBUG_ENABLE_ADDRESS_SANITIZER "enable address sanitizer (GCC)" OFF)
option(DEBUG_ENABLE_CLANG_TIDY "enable clang-tidy check of source code" OFF)
option(DEBUG_ENABLE_CLANG_TIDY_WITH_FIX "allow clang-tidy to modify source files and automatically fix issues. Very likely leads to uncompilable code, use selectively." OFF)
option(DISTRAC_ENABLE_TESTS "enable building and integrating unit tests" ON)
endif()
# Libraries
if(NOT Threads_FOUND)
find_package(Threads)
endif()
# Generate Export Header
include(GenerateExportHeader)
if(DISTRAC_PROJECT)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
add_definitions(-DBOOST_ALL_DYN_LINK)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost COMPONENTS program_options filesystem system iostreams coroutine context REQUIRED)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
if ( CMAKE_COMPILER_IS_GNUCC )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
endif()
if ( MSVC )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
endif()
find_program(
CLANG_TIDY_EXE
NAMES "clang-tidy"
DOC "Path to clang-tidy executable"
)
if(NOT CLANG_TIDY_EXE)
message(STATUS "clang-tidy not found.")
else()
message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE} - Enable checking with -DDEBUG_ENABLE_CLANG_TIDY=ON in CMake. Warning: Compilation Overhead!")
set(CLANG_TIDY_ARG_FIX "")
if(DEBUG_ENABLE_CLANG_TIDY_WITH_FIX)
set(CLANG_TIDY_ARG_FIX "-fix")
endif()
set(DO_CLANG_TIDY "${CLANG_TIDY_EXE}" ${CLANG_TIDY_ARG_FIX} "-checks=*,-clang-analyzer-alpha.*,-llvm-namespace-comment,-google-readability-namespace-comments,-fuchsia*,-modernize-use-trailing-return-type,-hicpp-no-array-decay,-cppcoreguidelines-*,-modernize-use-equals-default,-*braces-around-statements,-hicpp-avoid-goto,-modernize-concat-nested-namespaces,-readability-implicit-bool-conversion")
if(DEBUG_ENABLE_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY ${DO_CLANG_TIDY})
endif()
endif()
find_program(CCACHE_PROGRAM ccache)
# Speed up compilations using ccache.
if(CCACHE_PROGRAM)
message(STATUS "Found ccache at ${CCACHE_PROGRAM} - using it to speed up compilations.")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
endif()
endif()
add_subdirectory(third_party)
# Add Catch2 unit testing framework.
if(DISTRAC_ENABLE_TESTS)
cmake_policy(SET CMP0079 NEW)
include(CTest)
include(${CMAKE_CURRENT_SOURCE_DIR}/third_party/catch/Catch2-2.13.0/contrib/Catch.cmake)
enable_testing()
endif()
if(DISTRAC_PROJECT)
# Address Sanitizer for Debug Builds
if(DEBUG_ENABLE_ADDRESS_SANITIZER)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined -fsanitize=address -fno-sanitize-recover=undefined -fno-sanitize=vptr")
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address -fsanitize=undefined -fsanitize=address -fno-sanitize-recover=undefined -fno-sanitize=vptr")
endif()
if(DISTRAC_ENABLE_TESTS)
set(distrac_test_libs "" CACHE INTERNAL "Libraries for Tests for Distrac")
endif()
endif()
add_subdirectory(src)
add_library(distrac STATIC ${DISTRAC_SRCS})
target_include_directories(distrac PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
set_property(TARGET distrac PROPERTY POSITION_INDEPENDENT_CODE ON)
generate_export_header(distrac)
target_include_directories(distrac PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(distrac PUBLIC Threads::Threads)
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
target_link_libraries(distrac PUBLIC -lstdthreads)
endif()
add_library(distrac-analysis SHARED ${DISTRAC_ANALYSIS_SRCS})
target_link_libraries(distrac-analysis PUBLIC distrac Boost::iostreams)
set_property(TARGET distrac-analysis PROPERTY CXX_STANDARD 17)
generate_export_header(distrac-analysis)
target_include_directories(distrac-analysis PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
add_library(distrac-codegen SHARED ${DISTRAC_CODEGEN_SRCS})
target_link_libraries(distrac-codegen PUBLIC distrac)
set_property(TARGET distrac-codegen PROPERTY CXX_STANDARD 17)
generate_export_header(distrac-codegen)
target_include_directories(distrac-codegen PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${Boost_INCLUDE_DIRS})
add_executable(distrac-bin ${DISTRAC_BIN_SRCS})
set_target_properties(distrac-bin
PROPERTIES OUTPUT_NAME distrac)
target_link_libraries(distrac-bin Boost::program_options Boost::filesystem Threads::Threads distrac-analysis)
add_executable(distrac-codegen-bin ${DISTRAC_CODEGEN_BIN_SRCS})
set_property(TARGET distrac-codegen-bin PROPERTY CXX_STANDARD 17)
set_target_properties(distrac-codegen-bin
PROPERTIES OUTPUT_NAME distrac-codegen)
target_link_libraries(distrac-codegen-bin Boost::program_options Boost::filesystem Threads::Threads distrac-codegen distrac-analysis)
if(DISTRAC_PROJECT)
if(DISTRAC_ENABLE_TESTS)
add_library(distrac_lib_test SHARED ${DISTRAC_TEST_SRCS})
set_property(TARGET distrac_lib_test PROPERTY CXX_STANDARD 17)
target_link_libraries(distrac_lib_test PUBLIC distrac Catch2::Catch2)
set(distrac_test_libs ${distrac_test_libs} distrac_lib_test CACHE INTERNAL "Libraries for Tests")
add_library(distrac_analysis_test SHARED ${DISTRAC_ANALYSIS_TEST_SRCS})
set_property(TARGET distrac_analysis_test PROPERTY CXX_STANDARD 17)
target_link_libraries(distrac_analysis_test PUBLIC distrac distrac-analysis Catch2::Catch2)
set(distrac_test_libs ${distrac_test_libs} distrac_analysis_test CACHE INTERNAL "Libraries for Tests")
add_subdirectory(test)
endif()
endif()