-
Notifications
You must be signed in to change notification settings - Fork 165
/
CMakeLists.txt
186 lines (164 loc) · 5.11 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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md
# As of 2024-07-01, CMake 3.16 is the minimum supported version.
cmake_minimum_required(VERSION 3.16)
project(cctz)
set(CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/cmake
${PROJECT_SOURCE_DIR}/cmake/modules
${CMAKE_MODULE_PATH})
include(CTest)
include(FeatureSummary)
option(BUILD_TOOLS "Whether or not to build tools" ON)
option(BUILD_EXAMPLES "Whether or not to build examples" ON)
option(BUILD_BENCHMARK "Whether or not to build the benchmark application (has no effect if BUILD_TESTING is disabled)" ON)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ${BUILD_SHARED_LIBS})
if (BUILD_TESTING)
if (BUILD_BENCHMARK)
find_package(benchmark QUIET)
set_package_properties(benchmark PROPERTIES
TYPE REQUIRED
DESCRIPTION "a microbenchmark support library"
URL "https://github.com/google/benchmark"
)
endif()
find_package(GMock)
set_package_properties(GMock PROPERTIES
TYPE REQUIRED
DESCRIPTION "the Google C++ mocking framework"
URL "https://github.com/google/googletest"
)
find_package(GTest)
set_package_properties(GTest PROPERTIES
TYPE REQUIRED
DESCRIPTION "the Google C++ test framework"
URL "https://github.com/google/googletest"
)
find_package(Threads)
set_package_properties(Threads PROPERTIES
TYPE REQUIRED
DESCRIPTION "the system thread library"
)
endif()
# If a specific standard is required,
# it can be set from the command line with:
# cmake -DCMAKE_CXX_STANDARD=[11|14|17|20|23]
function(cctz_target_set_cxx_standard target)
set(cxx_standard 11)
target_compile_features(${target} PUBLIC cxx_std_${cxx_standard})
endfunction()
if(APPLE)
find_library(CoreFoundation CoreFoundation)
endif()
set(CCTZ_HDRS
include/cctz/time_zone.h
include/cctz/civil_time_detail.h
include/cctz/zone_info_source.h
include/cctz/civil_time.h
)
add_library(cctz
src/civil_time_detail.cc
src/time_zone_fixed.cc
src/time_zone_fixed.h
src/time_zone_format.cc
src/time_zone_if.cc
src/time_zone_if.h
src/time_zone_impl.cc
src/time_zone_impl.h
src/time_zone_info.cc
src/time_zone_info.h
src/time_zone_libc.cc
src/time_zone_libc.h
src/time_zone_lookup.cc
src/time_zone_posix.cc
src/time_zone_posix.h
src/tzfile.h
src/zone_info_source.cc
${CCTZ_HDRS}
)
cctz_target_set_cxx_standard(cctz)
target_include_directories(cctz PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
set_target_properties(cctz PROPERTIES
PUBLIC_HEADER "${CCTZ_HDRS}"
)
if(APPLE)
target_link_libraries(cctz PUBLIC ${CoreFoundation})
endif()
add_library(cctz::cctz ALIAS cctz)
if (BUILD_TOOLS)
add_executable(time_tool src/time_tool.cc)
cctz_target_set_cxx_standard(time_tool)
target_link_libraries(time_tool cctz::cctz)
endif()
if (BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if (BUILD_TESTING)
add_executable(civil_time_test src/civil_time_test.cc)
cctz_target_set_cxx_standard(civil_time_test)
target_include_directories(civil_time_test PRIVATE ${GTEST_INCLUDE_DIRS})
target_link_libraries(civil_time_test
cctz::cctz
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
add_test(civil_time_test civil_time_test)
add_executable(time_zone_lookup_test src/time_zone_lookup_test.cc)
cctz_target_set_cxx_standard(time_zone_lookup_test)
target_include_directories(time_zone_lookup_test PRIVATE ${GTEST_INCLUDE_DIRS})
target_link_libraries(time_zone_lookup_test
cctz::cctz
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
add_test(time_zone_lookup_test time_zone_lookup_test)
add_executable(time_zone_format_test src/time_zone_format_test.cc)
cctz_target_set_cxx_standard(time_zone_format_test)
target_link_libraries(time_zone_format_test
cctz::cctz
${CMAKE_THREAD_LIBS_INIT}
GMock::Main
)
add_test(time_zone_format_test time_zone_format_test)
# tests runs on testdata
set_property(
TEST
civil_time_test
time_zone_format_test
time_zone_lookup_test
PROPERTY
ENVIRONMENT "TZDIR=${CMAKE_CURRENT_SOURCE_DIR}/testdata/zoneinfo"
)
if (BUILD_BENCHMARK)
add_executable(cctz_benchmark src/cctz_benchmark.cc)
cctz_target_set_cxx_standard(cctz_benchmark)
target_link_libraries(cctz_benchmark cctz::cctz benchmark::benchmark_main)
endif()
endif()
# Install
include(GNUInstallDirs)
install(TARGETS cctz
EXPORT ${PROJECT_NAME}-targets
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cctz
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
if (BUILD_TOOLS)
install(TARGETS time_tool
EXPORT ${PROJECT_NAME}-targets
DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()
set(CMAKE_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
install(EXPORT ${PROJECT_NAME}-targets
NAMESPACE cctz::
DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
)
install(FILES cmake/${PROJECT_NAME}-config.cmake
DESTINATION ${CMAKE_INSTALL_CONFIGDIR}
)
set(quiet_on_empty QUIET_ON_EMPTY)
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES ${quiet_on_empty})