-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
76 lines (67 loc) · 3.07 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
cmake_minimum_required(VERSION 3.22)
project(SerialisePP VERSION 1.0.0 LANGUAGES CXX)
# TODO: update version when making changes.
add_library(SerialisePP INTERFACE)
target_include_directories(SerialisePP INTERFACE
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
$<INSTALL_INTERFACE:include>)
# We don't use C++23 features, but certain C++20 features are only implemented in some compilers' "latest" Standard
# mode, which currently corresponds to C++23.
target_compile_features(SerialisePP INTERFACE cxx_std_23)
set_target_properties(SerialisePP PROPERTIES CXX_EXTENSIONS OFF)
# Only build test code if specifically requested.
option(SERIALISEPP_BUILD_TEST "Build test executable" OFF)
if(SERIALISEPP_BUILD_TEST)
message("Configuring to build SerialisePPTest")
find_package(SimpleTest 1.1.0 REQUIRED)
add_executable(SerialisePPTest
test/test_buffers.cpp
test/test_common.cpp
test/test_compound.cpp
test/test_dynamic_array.cpp
test/test_optional.cpp
test/test_pair.cpp
test/test_record.cpp
test/test_scalar.cpp
test/test_static_array.cpp
test/test_tuple.cpp
test/test_utility.cpp
test/test_variant.cpp
)
target_include_directories(SerialisePPTest PRIVATE test/)
target_link_libraries(SerialisePPTest PRIVATE SerialisePP SimpleTest::SimpleTest)
target_compile_features(SerialisePPTest PUBLIC cxx_std_23)
set_target_properties(SerialisePPTest PROPERTIES CXX_EXTENSIONS OFF)
endif()
# Only build benchmark code if specifically requested.
option(SERIALISEPP_BUILD_BENCHMARK "Build benchmark executable" OFF)
if(SERIALISEPP_BUILD_BENCHMARK)
message("Configuring to build SerialisePPBenchmark")
add_executable(SerialisePPBenchmark
benchmark/helpers/utility.cpp
benchmark/main.cpp
)
target_include_directories(SerialisePPBenchmark PRIVATE test/)
target_link_libraries(SerialisePPBenchmark PRIVATE SerialisePP)
target_compile_features(SerialisePPBenchmark PUBLIC cxx_std_23)
set_target_properties(SerialisePPBenchmark PROPERTIES CXX_EXTENSIONS OFF)
endif()
# Don't configure installation if we're part of another project.
if(PROJECT_IS_TOP_LEVEL)
# Set up targets for installation.
include(GNUInstallDirs)
install(TARGETS SerialisePP EXPORT "${PROJECT_NAME}Targets")
install(EXPORT "${PROJECT_NAME}Targets" NAMESPACE "${PROJECT_NAME}::" DESTINATION cmake)
# Copy source files.
install(DIRECTORY include/ DESTINATION include)
# Set up Config.cmake and ConfigVersion.cmake files for usage with find_package().
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION cmake)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" COMPATIBILITY SameMajorVersion)
install(FILES
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION cmake)
endif()