-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
147 lines (125 loc) · 5.28 KB
/
Copy pathCMakeLists.txt
File metadata and controls
147 lines (125 loc) · 5.28 KB
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
cmake_minimum_required(VERSION 3.29..4.1)
## Disable modules support, this is broken with clang-tidy at the moment
## ref: github.com/cpp-best-practices/cmake_template/blob/main/CMakeLists.txt
cmake_policy(SET CMP0155 OLD)
## ^ POLICIES
project(
wndx_algo
VERSION 0.2.0
LANGUAGES CXX
DESCRIPTION "[WIP] C++20 platform-agnostic DSA lib. (NOT FOR USE IN PRODUCTION CODEBASES)"
HOMEPAGE_URL "https://github.com/WANDEX/algorithms"
)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
set(CMAKE_CXX_EXTENSIONS OFF)
message(NOTICE "/**")
message(NOTICE " * PROJECT: ${PROJECT_NAME}")
message(NOTICE " * VERSION: ${PROJECT_VERSION}")
message(NOTICE " * DSCRPTN: ${PROJECT_DESCRIPTION}")
message(NOTICE " * HOMEURL: ${PROJECT_HOMEPAGE_URL}")
message(NOTICE " */")
option(WNDX_ALGO_DISABLE_TOP_PROJECT OFF)
if(PROJECT_IS_TOP_LEVEL AND NOT WNDX_ALGO_DISABLE_TOP_PROJECT)
set(WNDX_ALGO_IS_TOP_PROJECT ON)
else()
set(WNDX_ALGO_IS_TOP_PROJECT OFF)
endif()
## search path for cmake modules to be loaded by: include() find_package().
## NOTE: works properly only if defined at the top-level CMakeLists.txt.
list(APPEND CMAKE_MODULE_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/cmake" ## project modules
"${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/wndx/sane/cmake"
)
macro(targets_and_linking)
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/wndx/sane")
include(wndx_sane_create_targets)
## library targets & compilation options/flags
wndx_sane_create_targets(PFX wndx LIB algo
CXX_STD cxx_std_${CMAKE_CXX_STANDARD}
PHD "include/wndx/algo"
)
## inherit from wndx::sane targets
target_link_libraries(algo_core INTERFACE wndx::sane::core) # inherit core
target_link_libraries(algo_dev INTERFACE wndx::sane::dev ) # inherit dev
target_link_libraries(algo_deps PUBLIC wndx::sane::deps) # inherit deps
target_link_libraries(algo_src PUBLIC wndx::sane::src ) # inherit src
## link sources with project dependencies from the core library target
target_link_libraries(algo_src INTERFACE wndx::algo::core)
## link sources with project dev interface (for the compilation flags/options)
target_link_libraries(algo_src PRIVATE wndx::algo::dev)
## link sources with project dependencies
target_link_libraries(algo_src PUBLIC wndx::algo::deps)
if(WNDX_ALGO_BUILD_SRC OR NOT WNDX_ALGO_IS_TOP_PROJECT)
## find/fetch dependecies:
# add_subdirectory(src/wndx/algo)
endif()
endmacro(targets_and_linking)
if(NOT WNDX_ALGO_IS_TOP_PROJECT)
targets_and_linking()
return() ## finish processing of the file
endif()
option(WNDX_ALGO_BUILD_SRC "whether or not src should be built" ON)
option(WNDX_ALGO_BUILD_TESTS "whether or not tests should be built" OFF)
option(WNDX_ALGO_BUILD_PACKAGE "whether or not the package should be built" ON)
option(WNDX_ALGO_COVERAGE_ENABLE "whether or not to enable the tests coverage" OFF)
option(WNDX_ALGO_COVERAGE_CLEAN "clean coverage data before taking new" ON)
option(WNDX_ALGO_INSTALL_ENABLE "whether or not to enable the install rule" ON)
option(WNDX_ALGO_MEMCHECK_ENABLE "detect leaks via memcheck tool" OFF)
## for the list of supported compilers visit:
## https://cmake.org/cmake/help/latest/prop_tgt/COMPILE_WARNING_AS_ERROR.html
option(CMAKE_COMPILE_WARNING_AS_ERROR "treat compilation warnings as errors" OFF)
## output dir is correct by default for most build setups.
## however, when building lib as a DLL, it is important to have the DLL in the same dir
## as the executable using it. Thus, we put all executables in a single /bin dir.
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
## on macOS, property ignored for the linker import files
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
targets_and_linking()
if(WNDX_ALGO_COVERAGE_ENABLE)
include(wndx_sane_coverage)
wndx_sane_coverage(TGT_NAME code_coverage
CLEAN WNDX_ALGO_COVERAGE_CLEAN
)
endif(WNDX_ALGO_COVERAGE_ENABLE)
if(WNDX_ALGO_BUILD_TESTS)
add_subdirectory(tests/units)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
# target_link_libraries(tests_units PRIVATE debug -fsanitize=thread) # MutExc
# target_link_libraries(tests_units PRIVATE debug -fsanitize=address)
# target_link_libraries(tests_units PRIVATE debug -fsanitize=leak)
# target_link_libraries(tests_units PRIVATE debug -fsanitize=undefined)
endif()
endif(WNDX_ALGO_BUILD_TESTS)
if(WNDX_ALGO_BUILD_PACKAGE)
include(wndx_sane_package)
wndx_sane_package(SUFFIX src FILES
cmake/ include/ scripts/ tests/ CMakeLists.txt LICENSE README.md
)
endif(WNDX_ALGO_BUILD_PACKAGE)
if(WNDX_ALGO_MEMCHECK_ENABLE)
include(wndx_sane_memcheck)
wndx_sane_memcheck(TGT_NAME memcheck
TGT_EXEC tests_units --gtest_brief=1
# VALGRIND_OPTS --read-var-info=yes --show-leak-kinds=definite --track-origins=yes
# DRMEMORY_OPTS -brief -no_crash_at_error
# EXIT_ON_FIRST_ERROR
# FORCE_DRMEMORY
)
endif(WNDX_ALGO_MEMCHECK_ENABLE)
if(WNDX_ALGO_INSTALL_ENABLE)
include(wndx_sane_install)
wndx_sane_install(
TARGETS
# _algo_base algo_core algo_dev
# algo_deps algo_src
algo
PHD "include/wndx/algo"
PATTERNS "*.hpp"
NAMESPACE wndx::
# RUNTIME_DEPENDENCIES
)
endif(WNDX_ALGO_INSTALL_ENABLE)