-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathCMakeLists.txt
131 lines (104 loc) · 5.06 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
# CMake file building demos and tests for the error correction library.
cmake_minimum_required(VERSION 3.19)
message("CMake version: ${CMAKE_VERSION}")
project(LDPC4QKD
VERSION 0.0.0 # This version is meaningless at the moment! TODO generate Cmake-Project-version dynamically
LANGUAGES C CXX
DESCRIPTION "Rate adaptive distributed source coding using LDPC codes."
)
# Enable testing. This is not necessary for using GTest,
# only provides integration with CTest (CMake test suite)
enable_testing()
# Allows `include`'ing custom CMake modules from this directory.
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
# ----------------------------------------------------------------------------------------------------------------------
# ----------------------------------------------- CMAKE OPTIONS --------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------
# !!!!!
# Note:
# CMake saves options in the cache (`CMakeCache.txt`).
# If CMake `option` default values are changed in this `CMakeLists.txt` file, the old values from the cache will
# continue to be used. Delete the cache for such changes to take effect.
# !!!!!
option(LDPC4QKD_HEADER_ONLY
"Enable this option if you don't want to build any executables.
This only creates a CMake target that ONLY points to where the header files are!"
OFF
)
add_subdirectory(src) # This contains header only library!
if (NOT LDPC4QKD_HEADER_ONLY)
option(LDPC4QKD_DEBUG_MESSAGES_ENABLED
"Enables the output debug messages (compile definitions using macros in the C++ code)
"
ON
)
option(BUILD_RUNTIME_BENCHMARKS
"Enables building of runtime performance benchmarks.
The benchmarks use the Google Benchmark framework, which must be installed.
"
OFF
)
option(LDPC4QKD_BUILD_ERROR_RATE_BENCHMARKS
"Enables building of error rate performance benchmarks.
"
ON
)
option(LDPC4QKD_BUILD_UNIT_TESTS
"Enables building unit tests.
The unit tests use the Google Test framework, which is downloaded and installed automatically!
"
ON
)
if (LDPC4QKD_DEBUG_MESSAGES_ENABLED)
message(STATUS "#define compile definition LDPC4QKD_DEBUG_MESSAGES_ENABLED.")
add_compile_definitions(LDPC4QKD_DEBUG_MESSAGES_ENABLED)
endif ()
# Interface library (without sources) that carries compiler/build flags.
add_library(project_options INTERFACE)
add_library(compiler_warnings INTERFACE)
include(BuildConfig) # custom CMake module (see folder `cmake/Modules`)
enable_sanitizers(project_options) # adds coverage if specified by flag ENABLE_COVERAGE
include(CompilerWarnings)
set_project_warnings(compiler_warnings)
# ------------------------------------------------------------------------------------------------------------------
# ---------------------------------------------------- MISCELLANEOUS -----------------------------------------------
# ------------------------------------------------------------------------------------------------------------------
# This will allow us to print a feature summary.
# https://cmake.org/cmake/help/v3.11/module/FeatureSummary.html
include(FeatureSummary)
# Required to enable testing for link-time optimization.
# https://cmake.org/cmake/help/v3.11/module/CheckIPOSupported.html
include(CheckIPOSupported)
# Use link-time optimization if allowed.
check_ipo_supported(RESULT ipo_supported)
if (ipo_supported)
set_property(GLOBAL PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
message(STATUS "Link-time optimization (IPO) is enabled.")
else ()
message(WARNING "Link-time optimization is not supported.")
endif ()
# We attempt to use ccache to speed up the build.
find_program(CCACHE_FOUND "ccache")
if (CCACHE_FOUND)
message(STATUS "Using ccache for building.")
set_property(GLOBAL PROPERTY LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
message(STATUS "ccache is being used to speed up the build.")
else ()
message(WARNING "Using ccache to speed up the build is not possible.")
endif (CCACHE_FOUND)
add_subdirectory(examples)
if (LDPC4QKD_BUILD_ERROR_RATE_BENCHMARKS)
add_subdirectory(benchmarks_error_rate)
endif (LDPC4QKD_BUILD_ERROR_RATE_BENCHMARKS)
if (LDPC4QKD_BUILD_UNIT_TESTS)
add_subdirectory(tests)
else (LDPC4QKD_BUILD_UNIT_TESTS)
message(STATUS "Unit tests are not built, as specified by user.")
endif (LDPC4QKD_BUILD_UNIT_TESTS)
if (BUILD_RUNTIME_BENCHMARKS)
add_subdirectory(benchmarks_runtime)
else (BUILD_RUNTIME_BENCHMARKS)
message(STATUS "Runtime performance benchmarks are not built, as specified by user.")
endif (BUILD_RUNTIME_BENCHMARKS)
endif (NOT LDPC4QKD_HEADER_ONLY)