forked from USCiLab/cereal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
120 lines (90 loc) · 3.33 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
cmake_minimum_required(VERSION 3.6...3.15)
project(cereal LANGUAGES CXX VERSION 1.3.0)
if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(CEREAL_MASTER_PROJECT ON)
endif()
if(APPLE)
option(SKIP_PORTABILITY_TEST "Skip portability (32 bit) tests" ON)
endif()
option(SKIP_PERFORMANCE_COMPARISON "Skip building performance comparison (requires boost)" OFF)
# TODO: should not be needed! CK
if(NOT CMAKE_VERSION VERSION_LESS 3.0) # installing cereal requires INTERFACE lib
option(JUST_INSTALL_CEREAL "Don't do anything besides installing the library" OFF)
endif()
set(CEREAL_THREAD_LIBS)
if(UNIX)
option(THREAD_SAFE "Use mutexes to ensure thread safety" OFF)
if(THREAD_SAFE)
message(STATUS "Use mutexes")
add_definitions(-DCEREAL_THREAD_SAFE=1)
set(CEREAL_THREAD_LIBS pthread)
endif()
endif()
if(MSVC)
add_compile_options(/bigobj /W3 /WX)
else()
add_compile_options(-Wall -Wextra -pedantic -Wshadow -Wold-style-cast)
option(WITH_WERROR "Compile with '-Werror' C++ compiler flag" ON)
if(WITH_WERROR)
add_compile_options(-Werror)
endif()
option(CLANG_USE_LIBCPP "Use libc++ for clang compilation" OFF)
if(APPLE OR CLANG_USE_LIBCPP)
message(STATUS "Use libc++")
add_compile_options(-stdlib=libc++)
# TODO: use add_link_options(-stdlib=libc++ -lc++abi") bud this needs cmake 3.13! CK
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++ -lc++abi")
endif()
if(NOT DEFINED CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD STREQUAL "98")
set(CMAKE_CXX_STANDARD 11)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
add_library(cereal INTERFACE)
add_library(cereal::cereal ALIAS cereal)
target_include_directories(cereal INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
list(APPEND CEREAL_THREAD_LIBS cereal::cereal)
if(NOT CMAKE_VERSION VERSION_LESS 3.8)
target_compile_features(cereal INTERFACE cxx_std_11)
endif()
option(CEREAL_INSTALL "Generate the install target" ${CEREAL_MASTER_PROJECT})
if(CEREAL_INSTALL)
include(CMakePackageConfigHelpers)
install(TARGETS cereal EXPORT ${PROJECT_NAME}Targets)
install(DIRECTORY include/cereal DESTINATION include)
set(configFile ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake)
set(versionFile ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake)
set(configInstallDestination lib/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 "cereal::"
DESTINATION ${configInstallDestination}
)
endif()
if(JUST_INSTALL_CEREAL)
return()
endif()
if(NOT SKIP_PERFORMANCE_COMPARISON)
# Boost serialization for performance sandbox
find_package(Boost REQUIRED COMPONENTS serialization)
endif()
option(BUILD_TESTS "Build tests" ${CEREAL_MASTER_PROJECT})
if(BUILD_TESTS)
enable_testing()
add_subdirectory(unittests)
endif()
add_subdirectory(sandbox)
add_subdirectory(doc)