-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
111 lines (85 loc) · 3.2 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
cmake_minimum_required(VERSION 3.20)
project(ser20 LANGUAGES CXX VERSION 1.4.0)
if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(SER20_MASTER_PROJECT ON)
endif()
option(BUILD_DOC "Build documentation" ${SER20_MASTER_PROJECT})
option(BUILD_SANDBOX "Build sandbox examples" ${SER20_MASTER_PROJECT})
option(BUILD_TESTS "Build tests" ${SER20_MASTER_PROJECT})
option(SKIP_PERFORMANCE_COMPARISON "Skip building performance sandbox comparison (requires boost)" ON)
if(NOT DEFINED CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD STREQUAL "98")
set(CMAKE_CXX_STANDARD 20)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SER20_SOURCES "src/ser20.cpp" "src/polymorphic_impl.cpp")
add_library(ser20 ${SER20_SOURCES})
add_library(ser20::ser20 ALIAS ser20)
target_include_directories(ser20 SYSTEM PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
if(MSVC)
target_compile_options(ser20 PRIVATE /bigobj /W3 /WX)
else()
target_compile_options(ser20 PRIVATE -Wall -Wextra -pedantic -Wshadow -Wold-style-cast)
option(WITH_WERROR "Compile with '-Werror' C++ compiler flag" ON)
if(WITH_WERROR)
target_compile_options(ser20 PRIVATE -Werror)
endif()
option(CLANG_USE_LIBCPP "Use libc++ for clang compilation" OFF)
if(APPLE OR CLANG_USE_LIBCPP)
message(STATUS "Use libc++")
target_compile_options(ser20 PUBLIC -stdlib=libc++)
target_link_options(ser20 PUBLIC -stdlib=libc++ -lc++abi)
endif()
endif()
set(SER20_THREAD_LIBS)
if(UNIX)
option(THREAD_SAFE "Use mutexes to ensure thread safety" OFF)
if(THREAD_SAFE)
message(STATUS "Use mutexes")
target_compile_definitions(ser20 PUBLIC SER20_THREAD_SAFE=1)
set(SER20_THREAD_LIBS pthread)
endif()
endif()
list(APPEND SER20_THREAD_LIBS ser20::ser20)
target_compile_features(ser20 INTERFACE cxx_std_20)
option(SER20_INSTALL "Generate the install target" ${SER20_MASTER_PROJECT})
if(SER20_INSTALL)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
install(TARGETS ser20 EXPORT ${PROJECT_NAME}Targets)
install(DIRECTORY include/ser20 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
set(configFile ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake)
set(versionFile ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake)
set(configInstallDestination ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
configure_package_config_file(
${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in
${configFile}
INSTALL_DESTINATION ${configInstallDestination}
)
write_basic_package_version_file(
${versionFile}
COMPATIBILITY SameMajorVersion
)
install(FILES ${configFile} ${versionFile} DESTINATION ${configInstallDestination})
install(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE "ser20::"
DESTINATION ${configInstallDestination}
)
endif()
if(NOT SKIP_PERFORMANCE_COMPARISON)
# Boost serialization for performance sandbox
find_package(Boost REQUIRED COMPONENTS serialization)
endif()
if(BUILD_TESTS)
enable_testing()
add_subdirectory(unittests)
endif()
if(BUILD_SANDBOX)
add_subdirectory(sandbox)
endif()
if(BUILD_DOC)
add_subdirectory(doc)
endif()