-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
92 lines (77 loc) · 3.86 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
cmake_minimum_required(VERSION 3.25)
project(cpark VERSION 0.0.1 LANGUAGES CXX)
# C++ standard can be overridden when this is used as a sub-project.
if(NOT CMAKE_CXX_STANDARD)
# Currently this project requires and only supports C++20.
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif(NOT CMAKE_CXX_STANDARD)
# Options indicating whether certain components of the project should be built.
option(CPARK_BUILD_TESTS "Build cpark's unit tests" ON)
option(CPARK_BUILD_EXAMPLES "Build cpark's examples" ON)
option(CPARK_BUILD_DISTRIBUTED "Build cpark with distributed computing support" ON)
# Set directories in the project.
# User should only include files in this directory.
set(cpark_user_include_dir include/)
set(cpark_lib_sources_dir lib/)
set(cpark_lib_headers_dir lib/)
set(cpark_examples_sources_dir examples/)
set(cpark_tests_sources_dir tests/)
# Set concepts diagnostics depth for GCC.
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(-fconcepts-diagnostics-depth=3 -ftemplate-backtrace-limit=0)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options($<$<CONFIG:DEBUG>:-gdwarf-3>)
endif (CMAKE_BUILD_TYPE STREQUAL "Debug")
endif()
if(CPARK_BUILD_DISTRIBUTED)
add_definitions(-DCPARK_DISTRIBUTED)
endif (CPARK_BUILD_DISTRIBUTED)
# The cpark main library.
# (Perhaps we do not need a static library. This project is full of templates, so everything should be in header files.)
file(GLOB cpark_lib_sources CONFIGURE_DEPENDS ${cpark_lib_sources_dir}/*.cpp)
add_library(cpark)
target_sources(cpark PRIVATE ${cpark_lib_sources})
target_include_directories(cpark PUBLIC ${cpark_user_include_dir})
# Build the examples if its option is set.
if(CPARK_BUILD_EXAMPLES)
file(GLOB examples_sources ${cpark_examples_sources_dir}/*.cpp)
# Each example file will have one executable.
foreach (example_file ${examples_sources})
# Cut off the file extension and directory path.
get_filename_component(example_name ${example_file} NAME_WE )
add_executable(${example_name} ${example_file} )
target_link_libraries(${example_name} cpark )
target_include_directories(${example_name} PRIVATE ${cpark_user_include_dir} ${cpark_lib_sources_dir})
endforeach(example_file ${examples_sources})
endif(CPARK_BUILD_EXAMPLES)
# Build unit tests if its option is set.
if(CPARK_BUILD_TESTS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
enable_testing()
# Fetch googletest from its github repository.
# Not using locally installed googletest (by FindPackage) here because it may cause incompatibility.
# TODO: First use FindPackage to get locally installed googletest. Fetch googletest from remote only if
# the local one does not exist or is incompatible.
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.13.0
)
Fetchcontent_MakeAvailable(googletest)
# Let the user know about the information of the specifically populated googletest for this project.
if (googletest_POPULATED)
message("A googletest library specified for this project is already populated by cmake.")
elseif (googletest_POPULATED)
message("Newly populated a googletest library under this project.")
endif (googletest_POPULATED)
message("googletest source directory: ${googletest_SOURCE_DIR}")
file(GLOB cpark_tests_sources CONFIGURE_DEPENDS ${cpark_tests_sources_dir}/*.cpp)
add_executable(cpark_tests)
target_sources(cpark_tests PRIVATE ${cpark_tests_sources})
target_include_directories(cpark_tests PRIVATE ${cpark_user_include_dir} ${cpark_lib_headers_dir})
target_link_libraries(cpark_tests PRIVATE cpark GTest::gtest_main)
add_test(NAME basic_tests COMMAND cpark_tests)
endif(CPARK_BUILD_TESTS)