James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 1 | cmake_minimum_required (VERSION 3.16) |
| 2 | project (glog |
| 3 | VERSION 0.7.0 |
| 4 | DESCRIPTION "C++ implementation of the Google logging module" |
| 5 | HOMEPAGE_URL https://github.com/google/glog |
| 6 | LANGUAGES CXX |
| 7 | ) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 8 | |
| 9 | set (CPACK_PACKAGE_NAME glog) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 10 | set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Google logging library") |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 11 | set (CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) |
| 12 | set (CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) |
| 13 | set (CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) |
| 14 | set (CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) |
| 15 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 16 | list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) |
| 17 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 18 | include (CheckCXXCompilerFlag) |
| 19 | include (CheckCXXSourceCompiles) |
| 20 | include (CheckCXXSourceRuns) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 21 | include (CheckCXXSymbolExists) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 22 | include (CheckFunctionExists) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 23 | include (CheckIncludeFileCXX) |
| 24 | include (CheckLibraryExists) |
| 25 | include (CheckStructHasMember) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 26 | include (CheckTypeSize) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 27 | include (CMakeDependentOption) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 28 | include (CMakePackageConfigHelpers) |
| 29 | include (CMakePushCheckState) |
| 30 | include (CPack) |
| 31 | include (CTest) |
| 32 | include (DetermineGflagsNamespace) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 33 | include (GenerateExportHeader) |
| 34 | include (GetCacheVariables) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 35 | include (GNUInstallDirs) |
| 36 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 37 | option (BUILD_SHARED_LIBS "Build shared libraries" ON) |
| 38 | option (PRINT_UNSYMBOLIZED_STACK_TRACES |
| 39 | "Print file offsets in traces instead of symbolizing" OFF) |
| 40 | option (WITH_CUSTOM_PREFIX "Enable support for user-generated message prefixes" ON) |
| 41 | option (WITH_GFLAGS "Use gflags" ON) |
| 42 | option (WITH_GTEST "Use Google Test" ON) |
| 43 | option (WITH_PKGCONFIG "Enable pkg-config support" ON) |
| 44 | option (WITH_SYMBOLIZE "Enable symbolize module" ON) |
| 45 | option (WITH_THREADS "Enable multithreading support" ON) |
| 46 | option (WITH_TLS "Enable Thread Local Storage (TLS) support" ON) |
| 47 | option (WITH_UNWIND "Enable libunwind support" ON) |
| 48 | |
| 49 | cmake_dependent_option (WITH_GMOCK "Use Google Mock" ON WITH_GTEST OFF) |
| 50 | |
| 51 | if (NOT WITH_UNWIND) |
| 52 | set (CMAKE_DISABLE_FIND_PACKAGE_Unwind ON) |
| 53 | endif (NOT WITH_UNWIND) |
| 54 | |
| 55 | if (NOT WITH_GTEST) |
| 56 | set (CMAKE_DISABLE_FIND_PACKAGE_GTest ON) |
| 57 | endif (NOT WITH_GTEST) |
| 58 | |
| 59 | if (NOT WITH_THREADS) |
| 60 | set (CMAKE_DISABLE_FIND_PACKAGE_Threads ON) |
| 61 | endif (NOT WITH_THREADS) |
| 62 | |
| 63 | set (CMAKE_C_VISIBILITY_PRESET hidden) |
| 64 | set (CMAKE_CXX_VISIBILITY_PRESET hidden) |
| 65 | set (CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 66 | set (CMAKE_VISIBILITY_INLINES_HIDDEN ON) |
| 67 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 68 | set (CMAKE_DEBUG_POSTFIX d) |
| 69 | set (CMAKE_THREAD_PREFER_PTHREAD 1) |
| 70 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 71 | find_package (GTest NO_MODULE) |
| 72 | |
| 73 | if (GTest_FOUND) |
| 74 | set (HAVE_LIB_GTEST 1) |
| 75 | endif (GTest_FOUND) |
| 76 | |
| 77 | if (WITH_GMOCK AND TARGET GTest::gmock) |
| 78 | set (HAVE_LIB_GMOCK 1) |
| 79 | endif (WITH_GMOCK AND TARGET GTest::gmock) |
| 80 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 81 | if (WITH_GFLAGS) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 82 | find_package (gflags 2.2.2) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 83 | |
| 84 | if (gflags_FOUND) |
| 85 | set (HAVE_LIB_GFLAGS 1) |
| 86 | determine_gflags_namespace (gflags_NAMESPACE) |
| 87 | endif (gflags_FOUND) |
| 88 | endif (WITH_GFLAGS) |
| 89 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 90 | find_package (Threads) |
| 91 | find_package (Unwind) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 92 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 93 | if (Unwind_FOUND) |
| 94 | set (HAVE_LIB_UNWIND 1) |
| 95 | else (Unwind_FOUND) |
| 96 | # Check whether linking actually succeeds. ARM toolchains of LLVM unwind |
| 97 | # implementation do not necessarily provide the _Unwind_Backtrace function |
| 98 | # which causes the previous check to succeed but the linking to fail. |
| 99 | check_cxx_symbol_exists (_Unwind_Backtrace unwind.h HAVE__UNWIND_BACKTRACE) |
| 100 | check_cxx_symbol_exists (_Unwind_GetIP unwind.h HAVE__UNWIND_GETIP) |
| 101 | endif (Unwind_FOUND) |
| 102 | |
| 103 | check_include_file_cxx (dlfcn.h HAVE_DLFCN_H) |
| 104 | check_include_file_cxx (glob.h HAVE_GLOB_H) |
| 105 | check_include_file_cxx (inttypes.h HAVE_INTTYPES_H) |
| 106 | check_include_file_cxx (memory.h HAVE_MEMORY_H) |
| 107 | check_include_file_cxx (pwd.h HAVE_PWD_H) |
| 108 | check_include_file_cxx (stdint.h HAVE_STDINT_H) |
| 109 | check_include_file_cxx (strings.h HAVE_STRINGS_H) |
| 110 | check_include_file_cxx (sys/stat.h HAVE_SYS_STAT_H) |
| 111 | check_include_file_cxx (sys/syscall.h HAVE_SYS_SYSCALL_H) |
| 112 | check_include_file_cxx (sys/time.h HAVE_SYS_TIME_H) |
| 113 | check_include_file_cxx (sys/types.h HAVE_SYS_TYPES_H) |
| 114 | check_include_file_cxx (sys/utsname.h HAVE_SYS_UTSNAME_H) |
| 115 | check_include_file_cxx (sys/wait.h HAVE_SYS_WAIT_H) |
| 116 | check_include_file_cxx (syscall.h HAVE_SYSCALL_H) |
| 117 | check_include_file_cxx (syslog.h HAVE_SYSLOG_H) |
| 118 | check_include_file_cxx (ucontext.h HAVE_UCONTEXT_H) |
| 119 | check_include_file_cxx (unistd.h HAVE_UNISTD_H) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 120 | |
| 121 | check_include_file_cxx ("ext/hash_map" HAVE_EXT_HASH_MAP) |
| 122 | check_include_file_cxx ("ext/hash_set" HAVE_EXT_HASH_SET) |
| 123 | check_include_file_cxx ("ext/slist" HAVE_EXT_SLIST) |
| 124 | check_include_file_cxx ("tr1/unordered_map" HAVE_TR1_UNORDERED_MAP) |
| 125 | check_include_file_cxx ("tr1/unordered_set" HAVE_TR1_UNORDERED_SET) |
| 126 | check_include_file_cxx ("unordered_map" HAVE_UNORDERED_MAP) |
| 127 | check_include_file_cxx ("unordered_set" HAVE_UNORDERED_SET) |
| 128 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 129 | check_type_size ("unsigned __int16" HAVE___UINT16 LANGUAGE CXX) |
| 130 | check_type_size (mode_t HAVE_MODE_T LANGUAGE CXX) |
| 131 | check_type_size (ssize_t HAVE_SSIZE_T LANGUAGE CXX) |
| 132 | check_type_size (u_int16_t HAVE_U_INT16_T LANGUAGE CXX) |
| 133 | check_type_size (uint16_t HAVE_UINT16_T LANGUAGE CXX) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 134 | |
| 135 | check_function_exists (dladdr HAVE_DLADDR) |
| 136 | check_function_exists (fcntl HAVE_FCNTL) |
| 137 | check_function_exists (pread HAVE_PREAD) |
| 138 | check_function_exists (pwrite HAVE_PWRITE) |
| 139 | check_function_exists (sigaction HAVE_SIGACTION) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 140 | check_function_exists (sigaltstack HAVE_SIGALTSTACK) |
| 141 | |
| 142 | check_cxx_symbol_exists (backtrace execinfo.h HAVE_EXECINFO_BACKTRACE) |
| 143 | check_cxx_symbol_exists (backtrace_symbols execinfo.h |
| 144 | HAVE_EXECINFO_BACKTRACE_SYMBOLS) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 145 | |
| 146 | # NOTE gcc does not fail if you pass a non-existent -Wno-* option as an |
| 147 | # argument. However, it will happily fail if you pass the corresponding -W* |
| 148 | # option. So, we check whether options that disable warnings exist by testing |
| 149 | # the availability of the corresponding option that enables the warning. This |
| 150 | # eliminates the need to check for compiler for several (mainly Clang) options. |
| 151 | |
| 152 | check_cxx_compiler_flag (-Wdeprecated HAVE_NO_DEPRECATED) |
| 153 | check_cxx_compiler_flag (-Wunnamed-type-template-args |
| 154 | HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS) |
| 155 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 156 | cmake_push_check_state (RESET) |
| 157 | |
| 158 | if (Threads_FOUND) |
| 159 | set (CMAKE_REQUIRED_LIBRARIES Threads::Threads) |
| 160 | endif (Threads_FOUND) |
| 161 | |
| 162 | check_cxx_symbol_exists (pthread_threadid_np "pthread.h" HAVE_PTHREAD_THREADID_NP) |
| 163 | cmake_pop_check_state () |
| 164 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 165 | # NOTE: Cannot use check_function_exists here since >=vc-14.0 can define |
| 166 | # snprintf as an inline function |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 167 | check_cxx_symbol_exists (snprintf cstdio HAVE_SNPRINTF) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 168 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 169 | check_library_exists (dbghelp UnDecorateSymbolName "" HAVE_DBGHELP) |
| 170 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 171 | check_cxx_source_compiles (" |
| 172 | #include <cstdlib> |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 173 | static void foo(void) __attribute__ ((unused)); |
| 174 | int main(void) { return 0; } |
| 175 | " HAVE___ATTRIBUTE__) |
| 176 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 177 | check_cxx_source_compiles (" |
| 178 | #include <cstdlib> |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 179 | static void foo(void) __attribute__ ((visibility(\"default\"))); |
| 180 | int main(void) { return 0; } |
| 181 | " HAVE___ATTRIBUTE__VISIBILITY_DEFAULT) |
| 182 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 183 | check_cxx_source_compiles (" |
| 184 | #include <cstdlib> |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 185 | static void foo(void) __attribute__ ((visibility(\"hidden\"))); |
| 186 | int main(void) { return 0; } |
| 187 | " HAVE___ATTRIBUTE__VISIBILITY_HIDDEN) |
| 188 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 189 | check_cxx_source_compiles (" |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 190 | int main(void) { if (__builtin_expect(0, 0)) return 1; return 0; } |
| 191 | " HAVE___BUILTIN_EXPECT) |
| 192 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 193 | check_cxx_source_compiles (" |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 194 | int main(void) |
| 195 | { |
| 196 | int a; if (__sync_val_compare_and_swap(&a, 0, 1)) return 1; return 0; |
| 197 | } |
| 198 | " HAVE___SYNC_VAL_COMPARE_AND_SWAP) |
| 199 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 200 | if (Threads_FOUND) |
| 201 | cmake_push_check_state (RESET) |
| 202 | set (CMAKE_REQUIRED_LIBRARIES Threads::Threads) |
| 203 | check_cxx_source_compiles (" |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 204 | #define _XOPEN_SOURCE 500 |
| 205 | #include <pthread.h> |
| 206 | int main(void) |
| 207 | { |
| 208 | pthread_rwlock_t l; |
| 209 | pthread_rwlock_init(&l, NULL); |
| 210 | pthread_rwlock_rdlock(&l); |
| 211 | return 0; |
| 212 | } |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 213 | " HAVE_RWLOCK) |
| 214 | cmake_pop_check_state () |
| 215 | endif (Threads_FOUND) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 216 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 217 | check_cxx_source_compiles (" |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 218 | __declspec(selectany) int a; |
| 219 | int main(void) { return 0; } |
| 220 | " HAVE___DECLSPEC) |
| 221 | |
| 222 | check_cxx_source_compiles (" |
| 223 | #include <vector> |
| 224 | vector<int> t; int main() { } |
| 225 | " STL_NO_NAMESPACE) |
| 226 | |
| 227 | check_cxx_source_compiles (" |
| 228 | #include <vector> |
| 229 | std::vector<int> t; int main() { } |
| 230 | " STL_STD_NAMESPACE) |
| 231 | |
| 232 | check_cxx_source_compiles (" |
| 233 | #include <iostream> |
| 234 | std::ostream& operator<<(std::ostream&, struct s); |
| 235 | using ::operator<<; |
| 236 | int main() { } |
| 237 | " HAVE_USING_OPERATOR) |
| 238 | |
| 239 | check_cxx_source_compiles (" |
| 240 | namespace Outer { namespace Inner { int i = 0; }} |
| 241 | using namespace Outer::Inner;; |
| 242 | int main() { return i; } |
| 243 | " HAVE_NAMESPACES) |
| 244 | |
| 245 | check_cxx_source_compiles (" |
| 246 | __thread int tls; |
| 247 | int main() { } |
| 248 | " HAVE_GCC_TLS) |
| 249 | |
| 250 | check_cxx_source_compiles (" |
| 251 | __declspec(thread) int tls; |
| 252 | int main() { } |
| 253 | " HAVE_MSVC_TLS) |
| 254 | |
| 255 | check_cxx_source_compiles (" |
| 256 | thread_local int tls; |
| 257 | int main() { } |
| 258 | " HAVE_CXX11_TLS) |
| 259 | |
| 260 | check_cxx_source_compiles (" |
| 261 | #include <type_traits> |
| 262 | std::aligned_storage<sizeof(char), alignof(char)>::type data; |
| 263 | int main() { } |
| 264 | " HAVE_ALIGNED_STORAGE) |
| 265 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 266 | check_cxx_source_compiles (" |
| 267 | #include <atomic> |
| 268 | std::atomic<int> i; |
| 269 | int main() { } |
| 270 | " HAVE_CXX11_ATOMIC) |
| 271 | |
| 272 | check_cxx_source_compiles (" |
| 273 | constexpr int x = 0; |
| 274 | int main() { } |
| 275 | " HAVE_CXX11_CONSTEXPR) |
| 276 | |
| 277 | check_cxx_source_compiles (" |
| 278 | #include <chrono> |
| 279 | std::chrono::seconds s; |
| 280 | int main() { } |
| 281 | " HAVE_CXX11_CHRONO) |
| 282 | |
| 283 | check_cxx_source_compiles (" |
| 284 | #include <cstddef> |
| 285 | void foo(std::nullptr_t) {} |
| 286 | int main(void) { foo(nullptr); } |
| 287 | " HAVE_CXX11_NULLPTR_T) |
| 288 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 289 | if (WITH_TLS) |
| 290 | # Cygwin does not support the thread attribute. Don't bother. |
| 291 | if (HAVE_GCC_TLS) |
| 292 | set (GLOG_THREAD_LOCAL_STORAGE "__thread") |
| 293 | elseif (HAVE_MSVC_TLS) |
| 294 | set (GLOG_THREAD_LOCAL_STORAGE "__declspec(thread)") |
| 295 | elseif (HAVE_CXX11_TLS) |
| 296 | set (GLOG_THREAD_LOCAL_STORAGE thread_local) |
| 297 | endif (HAVE_GCC_TLS) |
| 298 | endif (WITH_TLS) |
| 299 | |
| 300 | set (_PC_FIELDS |
| 301 | "gregs[REG_PC]" |
| 302 | "gregs[REG_EIP]" |
| 303 | "gregs[REG_RIP]" |
| 304 | "sc_ip" |
| 305 | "uc_regs->gregs[PT_NIP]" |
| 306 | "gregs[R15]" |
| 307 | "arm_pc" |
| 308 | "mc_eip" |
| 309 | "mc_rip" |
| 310 | "__gregs[REG_EIP]" |
| 311 | "__gregs[REG_RIP]" |
| 312 | "ss.eip" |
| 313 | "__ss.__eip" |
| 314 | "ss.rip" |
| 315 | "__ss.__rip" |
| 316 | "ss.srr0" |
| 317 | "__ss.__srr0" |
| 318 | ) |
| 319 | |
| 320 | set (_PC_HEADERS ucontext.h signal.h) |
| 321 | |
| 322 | if (HAVE_UCONTEXT_H AND NOT PC_FROM_UCONTEXT) |
| 323 | foreach (_PC_FIELD ${_PC_FIELDS}) |
| 324 | foreach (_PC_HEADER ${_PC_HEADERS}) |
| 325 | set (_TMP |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 326 | ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/uctfield.cpp) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 327 | file (WRITE ${_TMP} " |
| 328 | #define _GNU_SOURCE 1 |
| 329 | #include <${_PC_HEADER}> |
| 330 | int main(void) |
| 331 | { |
| 332 | ucontext_t u; |
| 333 | return u.${_PC_FIELD} == 0; |
| 334 | } |
| 335 | ") |
| 336 | try_compile (HAVE_PC_FROM_UCONTEXT ${CMAKE_CURRENT_BINARY_DIR} ${_TMP} |
| 337 | COMPILE_DEFINITIONS _GNU_SOURCE=1) |
| 338 | |
| 339 | if (HAVE_PC_FROM_UCONTEXT) |
| 340 | set (PC_FROM_UCONTEXT ${_PC_FIELD} CACHE) |
| 341 | endif (HAVE_PC_FROM_UCONTEXT) |
| 342 | endforeach (_PC_HEADER) |
| 343 | endforeach (_PC_FIELD) |
| 344 | endif (HAVE_UCONTEXT_H AND NOT PC_FROM_UCONTEXT) |
| 345 | |
| 346 | if (STL_STD_NAMESPACE) |
| 347 | set (STL_NAMESPACE std) |
| 348 | else (STL_STD_NAMESPACE) |
| 349 | set (STL_NAMESPACE "") |
| 350 | endif (STL_STD_NAMESPACE) |
| 351 | |
| 352 | set (GOOGLE_NAMESPACE google) |
| 353 | set (_START_GOOGLE_NAMESPACE_ "namespace ${GOOGLE_NAMESPACE} {") |
| 354 | set (_END_GOOGLE_NAMESPACE_ "}") |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 355 | set (ac_cv_have_glog_export 1) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 356 | |
| 357 | if (HAVE___UINT16) |
| 358 | set (ac_cv_have___uint16 1) |
| 359 | else (HAVE___UINT16) |
| 360 | set (ac_cv_have___uint16 0) |
| 361 | endif (HAVE___UINT16) |
| 362 | |
| 363 | if (HAVE_INTTYPES_H) |
| 364 | set (ac_cv_have_inttypes_h 1) |
| 365 | else (HAVE_INTTYPES_H) |
| 366 | set (ac_cv_have_inttypes_h 0) |
| 367 | endif (HAVE_INTTYPES_H) |
| 368 | |
| 369 | if (HAVE_LIB_GFLAGS) |
| 370 | set (ac_cv_have_libgflags 1) |
| 371 | else (HAVE_LIB_GFLAGS) |
| 372 | set (ac_cv_have_libgflags 0) |
| 373 | endif (HAVE_LIB_GFLAGS) |
| 374 | |
| 375 | if (HAVE_STDINT_H) |
| 376 | set (ac_cv_have_stdint_h 1) |
| 377 | else (HAVE_STDINT_H) |
| 378 | set (ac_cv_have_stdint_h 0) |
| 379 | endif (HAVE_STDINT_H) |
| 380 | |
| 381 | if (HAVE_SYS_TYPES_H) |
| 382 | set (ac_cv_have_systypes_h 1) |
| 383 | else (HAVE_SYS_TYPES_H) |
| 384 | set (ac_cv_have_systypes_h 0) |
| 385 | endif (HAVE_SYS_TYPES_H) |
| 386 | |
| 387 | if (HAVE_U_INT16_T) |
| 388 | set (ac_cv_have_u_int16_t 1) |
| 389 | else (HAVE_U_INT16_T) |
| 390 | set (ac_cv_have_u_int16_t 0) |
| 391 | endif (HAVE_U_INT16_T) |
| 392 | |
| 393 | if (HAVE_UINT16_T) |
| 394 | set (ac_cv_have_uint16_t 1) |
| 395 | else (HAVE_UINT16_T) |
| 396 | set (ac_cv_have_uint16_t 0) |
| 397 | endif (HAVE_UINT16_T) |
| 398 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 399 | if (HAVE_SSIZE_T) |
| 400 | set (ac_cv_have_ssize_t 1) |
| 401 | else (HAVE_SSIZE_T) |
| 402 | set (ac_cv_have_ssize_t 0) |
| 403 | endif (HAVE_SSIZE_T) |
| 404 | |
| 405 | if (HAVE_MODE_T) |
| 406 | set (ac_cv_have_mode_t 1) |
| 407 | else (HAVE_MODE_T) |
| 408 | set (ac_cv_have_mode_t 0) |
| 409 | endif (HAVE_MODE_T) |
| 410 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 411 | if (HAVE_UNISTD_H) |
| 412 | set (ac_cv_have_unistd_h 1) |
| 413 | else (HAVE_UNISTD_H) |
| 414 | set (ac_cv_have_unistd_h 0) |
| 415 | endif (HAVE_UNISTD_H) |
| 416 | |
| 417 | set (ac_google_namespace ${GOOGLE_NAMESPACE}) |
| 418 | set (ac_google_end_namespace ${_END_GOOGLE_NAMESPACE_}) |
| 419 | set (ac_google_start_namespace ${_START_GOOGLE_NAMESPACE_}) |
| 420 | |
| 421 | if (HAVE___ATTRIBUTE__) |
| 422 | set (ac_cv___attribute___noreturn "__attribute__((noreturn))") |
| 423 | set (ac_cv___attribute___noinline "__attribute__((noinline))") |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 424 | set (ac_cv___attribute___printf_4_5 "__attribute__((__format__(__printf__, 4, 5)))") |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 425 | elseif (HAVE___DECLSPEC) |
| 426 | set (ac_cv___attribute___noreturn "__declspec(noreturn)") |
| 427 | #set (ac_cv___attribute___noinline "__declspec(noinline)") |
| 428 | endif (HAVE___ATTRIBUTE__) |
| 429 | |
| 430 | if (HAVE___BUILTIN_EXPECT) |
| 431 | set (ac_cv_have___builtin_expect 1) |
| 432 | else (HAVE___BUILTIN_EXPECT) |
| 433 | set (ac_cv_have___builtin_expect 0) |
| 434 | endif (HAVE___BUILTIN_EXPECT) |
| 435 | |
| 436 | if (HAVE_USING_OPERATOR) |
| 437 | set (ac_cv_cxx_using_operator 1) |
| 438 | else (HAVE_USING_OPERATOR) |
| 439 | set (ac_cv_cxx_using_operator 0) |
| 440 | endif (HAVE_USING_OPERATOR) |
| 441 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 442 | if (HAVE_CXX11_CONSTEXPR) |
| 443 | set (ac_cv_cxx11_constexpr 1) |
| 444 | else (HAVE_CXX11_CONSTEXPR) |
| 445 | set (ac_cv_cxx11_constexpr 0) |
| 446 | endif (HAVE_CXX11_CONSTEXPR) |
| 447 | |
| 448 | if (HAVE_CXX11_CHRONO) |
| 449 | set (ac_cv_cxx11_chrono 1) |
| 450 | else (HAVE_CXX11_CHRONO) |
| 451 | set (ac_cv_cxx11_chrono 0) |
| 452 | endif (HAVE_CXX11_CHRONO) |
| 453 | |
| 454 | if (HAVE_CXX11_NULLPTR_T) |
| 455 | set (ac_cv_cxx11_nullptr_t 1) |
| 456 | else (HAVE_CXX11_NULLPTR_T) |
| 457 | set (ac_cv_cxx11_nullptr_t 0) |
| 458 | endif (HAVE_CXX11_NULLPTR_T) |
| 459 | |
| 460 | if (HAVE_EXECINFO_BACKTRACE AND HAVE_EXECINFO_BACKTRACE_SYMBOLS) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 461 | set (HAVE_STACKTRACE 1) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 462 | endif (HAVE_EXECINFO_BACKTRACE AND HAVE_EXECINFO_BACKTRACE_SYMBOLS) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 463 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 464 | if (HAVE_CXX11_ATOMIC) |
| 465 | set (ac_cv_cxx11_atomic 1) |
| 466 | else (HAVE_CXX11_ATOMIC) |
| 467 | set (ac_cv_cxx11_atomic 0) |
| 468 | endif (HAVE_CXX11_ATOMIC) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 469 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 470 | if (WITH_SYMBOLIZE) |
| 471 | if (WIN32 OR CYGWIN) |
| 472 | cmake_push_check_state (RESET) |
| 473 | set (CMAKE_REQUIRED_LIBRARIES DbgHelp) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 474 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 475 | check_cxx_source_runs ([=[ |
| 476 | #include <windows.h> |
| 477 | #include <dbghelp.h> |
| 478 | #include <cstdlib> |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 479 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 480 | void foobar() { } |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 481 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 482 | int main() |
| 483 | { |
| 484 | HANDLE process = GetCurrentProcess(); |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 485 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 486 | if (!SymInitialize(process, NULL, TRUE)) |
| 487 | return EXIT_FAILURE; |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 488 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 489 | char buf[sizeof(SYMBOL_INFO) + MAX_SYM_NAME]; |
| 490 | SYMBOL_INFO *symbol = reinterpret_cast<SYMBOL_INFO *>(buf); |
| 491 | symbol->SizeOfStruct = sizeof(SYMBOL_INFO); |
| 492 | symbol->MaxNameLen = MAX_SYM_NAME; |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 493 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 494 | void* const pc = reinterpret_cast<void*>(&foobar); |
| 495 | BOOL ret = SymFromAddr(process, reinterpret_cast<DWORD64>(pc), 0, symbol); |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 496 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 497 | return ret ? EXIT_SUCCESS : EXIT_FAILURE; |
| 498 | } |
| 499 | ]=] HAVE_SYMBOLIZE) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 500 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 501 | cmake_pop_check_state () |
| 502 | |
| 503 | if (HAVE_SYMBOLIZE) |
| 504 | set (HAVE_STACKTRACE 1) |
| 505 | endif (HAVE_SYMBOLIZE) |
| 506 | elseif (UNIX OR (APPLE AND HAVE_DLADDR)) |
| 507 | set (HAVE_SYMBOLIZE 1) |
| 508 | endif (WIN32 OR CYGWIN) |
| 509 | endif (WITH_SYMBOLIZE) |
| 510 | |
| 511 | # CMake manages symbolize availability. The definition is necessary only when |
| 512 | # building the library. Switch to add_compile_definitions once we drop support |
| 513 | # for CMake below version 3.12. |
| 514 | add_definitions (-DGLOG_NO_SYMBOLIZE_DETECTION) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 515 | |
| 516 | check_cxx_source_compiles (" |
| 517 | #include <cstdlib> |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 518 | #include <ctime> |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 519 | int main() |
| 520 | { |
| 521 | time_t timep; |
| 522 | struct tm result; |
| 523 | localtime_r(&timep, &result); |
| 524 | return EXIT_SUCCESS; |
| 525 | } |
| 526 | " HAVE_LOCALTIME_R) |
| 527 | |
| 528 | set (SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) |
| 529 | |
| 530 | if (WITH_THREADS AND Threads_FOUND) |
| 531 | if (CMAKE_USE_PTHREADS_INIT) |
| 532 | set (HAVE_PTHREAD 1) |
| 533 | endif (CMAKE_USE_PTHREADS_INIT) |
| 534 | else (WITH_THREADS AND Threads_FOUND) |
| 535 | set (NO_THREADS 1) |
| 536 | endif (WITH_THREADS AND Threads_FOUND) |
| 537 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 538 | # fopen/open on Cygwin can not handle unix-type paths like /home/.... |
| 539 | # therefore we translate TEST_SRC_DIR to windows-path. |
| 540 | if (CYGWIN) |
| 541 | execute_process (COMMAND cygpath.exe -m ${CMAKE_CURRENT_SOURCE_DIR} |
| 542 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 543 | OUTPUT_VARIABLE TEST_SRC_DIR) |
| 544 | set (TEST_SRC_DIR \"${TEST_SRC_DIR}\") |
| 545 | else (CYGWIN) |
| 546 | set (TEST_SRC_DIR \"${CMAKE_CURRENT_SOURCE_DIR}\") |
| 547 | endif (CYGWIN) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 548 | |
| 549 | configure_file (src/config.h.cmake.in config.h) |
| 550 | configure_file (src/glog/logging.h.in glog/logging.h @ONLY) |
| 551 | configure_file (src/glog/raw_logging.h.in glog/raw_logging.h @ONLY) |
| 552 | configure_file (src/glog/stl_logging.h.in glog/stl_logging.h @ONLY) |
| 553 | configure_file (src/glog/vlog_is_on.h.in glog/vlog_is_on.h @ONLY) |
| 554 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 555 | add_compile_options ($<$<AND:$<BOOL:${HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS}>,$<NOT:$<CXX_COMPILER_ID:GNU>>>:-Wno-unnamed-type-template-args>) |
| 556 | |
| 557 | set (_glog_CMake_BINDIR ${CMAKE_INSTALL_BINDIR}) |
| 558 | set (_glog_CMake_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}) |
| 559 | set (_glog_CMake_LIBDIR ${CMAKE_INSTALL_LIBDIR}) |
| 560 | set (_glog_CMake_INSTALLDIR ${_glog_CMake_LIBDIR}/cmake/glog) |
| 561 | |
| 562 | set (_glog_CMake_DIR glog/cmake) |
| 563 | set (_glog_CMake_DATADIR ${CMAKE_INSTALL_DATAROOTDIR}/${_glog_CMake_DIR}) |
| 564 | set (_glog_BINARY_CMake_DATADIR |
| 565 | ${CMAKE_CURRENT_BINARY_DIR}/${_glog_CMake_DATADIR}) |
| 566 | |
| 567 | # Add additional CMake find modules here. |
| 568 | set (_glog_CMake_MODULES) |
| 569 | |
| 570 | if (Unwind_FOUND) |
| 571 | # Copy the module only if libunwind is actually used. |
| 572 | list (APPEND _glog_CMake_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindUnwind.cmake) |
| 573 | endif (Unwind_FOUND) |
| 574 | |
| 575 | # Generate file name for each module in the binary directory |
| 576 | foreach (_file ${_glog_CMake_MODULES}) |
| 577 | get_filename_component (_module "${_file}" NAME) |
| 578 | |
| 579 | list (APPEND _glog_BINARY_CMake_MODULES |
| 580 | ${_glog_BINARY_CMake_DATADIR}/${_module}) |
| 581 | endforeach (_file) |
| 582 | |
| 583 | if (_glog_CMake_MODULES) |
| 584 | # Copy modules to binary directory during the build |
| 585 | add_custom_command (OUTPUT ${_glog_BINARY_CMake_MODULES} |
| 586 | COMMAND ${CMAKE_COMMAND} -E make_directory |
| 587 | ${_glog_BINARY_CMake_DATADIR} |
| 588 | COMMAND ${CMAKE_COMMAND} -E copy ${_glog_CMake_MODULES} |
| 589 | ${_glog_BINARY_CMake_DATADIR} |
| 590 | DEPENDS ${_glog_CMake_MODULES} |
| 591 | COMMENT "Copying find modules..." |
| 592 | ) |
| 593 | endif (_glog_CMake_MODULES) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 594 | |
| 595 | set (GLOG_PUBLIC_H |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 596 | ${CMAKE_CURRENT_BINARY_DIR}/glog/export.h |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 597 | ${CMAKE_CURRENT_BINARY_DIR}/glog/logging.h |
| 598 | ${CMAKE_CURRENT_BINARY_DIR}/glog/raw_logging.h |
| 599 | ${CMAKE_CURRENT_BINARY_DIR}/glog/stl_logging.h |
| 600 | ${CMAKE_CURRENT_BINARY_DIR}/glog/vlog_is_on.h |
| 601 | src/glog/log_severity.h |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 602 | src/glog/platform.h |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 603 | ) |
| 604 | |
| 605 | set (GLOG_SRCS |
| 606 | ${GLOG_PUBLIC_H} |
| 607 | src/base/commandlineflags.h |
| 608 | src/base/googleinit.h |
| 609 | src/base/mutex.h |
| 610 | src/demangle.cc |
| 611 | src/demangle.h |
| 612 | src/logging.cc |
| 613 | src/raw_logging.cc |
| 614 | src/symbolize.cc |
| 615 | src/symbolize.h |
| 616 | src/utilities.cc |
| 617 | src/utilities.h |
| 618 | src/vlog_is_on.cc |
| 619 | ) |
| 620 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 621 | if (HAVE_PTHREAD OR WIN32 OR CYGWIN) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 622 | list (APPEND GLOG_SRCS src/signalhandler.cc) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 623 | endif (HAVE_PTHREAD OR WIN32 OR CYGWIN) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 624 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 625 | if (CYGWIN OR WIN32) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 626 | list (APPEND GLOG_SRCS |
| 627 | src/windows/port.cc |
| 628 | src/windows/port.h |
| 629 | ) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 630 | endif (CYGWIN OR WIN32) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 631 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 632 | add_library (glogbase OBJECT |
| 633 | ${_glog_BINARY_CMake_MODULES} |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 634 | ${GLOG_SRCS} |
| 635 | ) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 636 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 637 | add_library (glog |
| 638 | $<TARGET_OBJECTS:glogbase> |
| 639 | ) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 640 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 641 | add_library (glog::glog ALIAS glog) |
| 642 | |
| 643 | set (glog_libraries_options_for_static_linking) |
| 644 | |
| 645 | if (Unwind_FOUND) |
| 646 | target_link_libraries (glog PRIVATE unwind::unwind) |
| 647 | set (glog_libraries_options_for_static_linking "${glog_libraries_options_for_static_linking} -lunwind") |
| 648 | set (Unwind_DEPENDENCY "find_dependency (Unwind ${Unwind_VERSION})") |
| 649 | endif (Unwind_FOUND) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 650 | |
| 651 | if (HAVE_DBGHELP) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 652 | target_link_libraries (glog PRIVATE dbghelp) |
| 653 | set (glog_libraries_options_for_static_linking "${glog_libraries_options_for_static_linking} -ldbghelp") |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 654 | endif (HAVE_DBGHELP) |
| 655 | |
| 656 | if (HAVE_PTHREAD) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 657 | target_link_libraries (glog PRIVATE ${CMAKE_THREAD_LIBS_INIT}) |
| 658 | |
| 659 | if (CMAKE_THREAD_LIBS_INIT) |
| 660 | set (glog_libraries_options_for_static_linking "${glog_libraries_options_for_static_linking} ${CMAKE_THREAD_LIBS_INIT}") |
| 661 | endif (CMAKE_THREAD_LIBS_INIT) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 662 | endif (HAVE_PTHREAD) |
| 663 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 664 | if (gflags_FOUND) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 665 | # Prefer the gflags target that uses double colon convention |
| 666 | if (TARGET gflags::gflags) |
| 667 | target_link_libraries (glog PUBLIC gflags::gflags) |
| 668 | else (TARGET gflags::gflags) |
| 669 | target_link_libraries (glog PUBLIC gflags) |
| 670 | endif (TARGET gflags::gflags) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 671 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 672 | set (glog_libraries_options_for_static_linking "${glog_libraries_options_for_static_linking} -lgflags") |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 673 | endif (gflags_FOUND) |
| 674 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 675 | if (ANDROID) |
| 676 | target_link_libraries (glog PRIVATE log) |
| 677 | set (glog_libraries_options_for_static_linking "${glog_libraries_options_for_static_linking} -llog") |
| 678 | endif (ANDROID) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 679 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 680 | set_target_properties (glog PROPERTIES VERSION ${PROJECT_VERSION}) |
| 681 | set_target_properties (glog PROPERTIES SOVERSION 1) |
| 682 | |
| 683 | if (CYGWIN OR WIN32) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 684 | target_compile_definitions (glog PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 685 | endif (CYGWIN OR WIN32) |
| 686 | |
| 687 | if (WITH_CUSTOM_PREFIX) |
| 688 | target_compile_definitions (glog PUBLIC GLOG_CUSTOM_PREFIX_SUPPORT) |
| 689 | endif (WITH_CUSTOM_PREFIX) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 690 | |
| 691 | set_target_properties (glog PROPERTIES PUBLIC_HEADER "${GLOG_PUBLIC_H}") |
| 692 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 693 | target_include_directories (glog BEFORE PUBLIC |
| 694 | "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>" |
| 695 | "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>" |
| 696 | "$<INSTALL_INTERFACE:${_glog_CMake_INCLUDE_DIR}>" |
| 697 | PRIVATE ${CMAKE_CURRENT_BINARY_DIR} |
| 698 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) |
| 699 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 700 | if (CYGWIN OR WIN32) |
| 701 | target_include_directories (glogbase PUBLIC |
| 702 | "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/windows>" |
| 703 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/windows) |
| 704 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 705 | target_include_directories (glog PUBLIC |
| 706 | "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/windows>" |
| 707 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/windows) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 708 | endif (CYGWIN OR WIN32) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 709 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 710 | set_target_properties (glog PROPERTIES DEFINE_SYMBOL GOOGLE_GLOG_IS_A_DLL) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 711 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 712 | target_include_directories (glogbase PUBLIC |
| 713 | $<TARGET_PROPERTY:glog,INCLUDE_DIRECTORIES>) |
| 714 | target_compile_definitions (glogbase PUBLIC |
| 715 | $<TARGET_PROPERTY:glog,COMPILE_DEFINITIONS> |
| 716 | PRIVATE GOOGLE_GLOG_IS_A_DLL) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 717 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 718 | generate_export_header (glog |
| 719 | EXPORT_MACRO_NAME GLOG_EXPORT |
| 720 | EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/glog/export.h) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 721 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 722 | string (STRIP "${glog_libraries_options_for_static_linking}" glog_libraries_options_for_static_linking) |
| 723 | |
| 724 | if (WITH_PKGCONFIG) |
| 725 | set (VERSION ${PROJECT_VERSION}) |
| 726 | set (prefix ${CMAKE_INSTALL_PREFIX}) |
| 727 | set (exec_prefix ${CMAKE_INSTALL_FULL_BINDIR}) |
| 728 | set (libdir ${CMAKE_INSTALL_FULL_LIBDIR}) |
| 729 | set (includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR}) |
| 730 | |
| 731 | configure_file ( |
| 732 | "${PROJECT_SOURCE_DIR}/libglog.pc.in" |
| 733 | "${PROJECT_BINARY_DIR}/libglog.pc" |
| 734 | @ONLY |
| 735 | ) |
| 736 | |
| 737 | unset (VERSION) |
| 738 | unset (prefix) |
| 739 | unset (exec_prefix) |
| 740 | unset (libdir) |
| 741 | unset (includedir) |
| 742 | endif (WITH_PKGCONFIG) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 743 | |
| 744 | # Unit testing |
| 745 | |
| 746 | if (BUILD_TESTING) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 747 | add_library (glogtest STATIC |
| 748 | $<TARGET_OBJECTS:glogbase> |
| 749 | ) |
| 750 | |
| 751 | target_include_directories (glogtest PUBLIC |
| 752 | $<TARGET_PROPERTY:glog,INCLUDE_DIRECTORIES>) |
| 753 | target_compile_definitions (glogtest PUBLIC |
| 754 | $<TARGET_PROPERTY:glog,COMPILE_DEFINITIONS> GLOG_STATIC_DEFINE) |
| 755 | target_link_libraries (glogtest PUBLIC |
| 756 | $<TARGET_PROPERTY:glog,LINK_LIBRARIES>) |
| 757 | |
| 758 | set (_GLOG_TEST_LIBS glogtest) |
| 759 | |
| 760 | if (HAVE_LIB_GTEST) |
| 761 | list (APPEND _GLOG_TEST_LIBS GTest::gtest) |
| 762 | endif (HAVE_LIB_GTEST) |
| 763 | |
| 764 | if (HAVE_LIB_GMOCK) |
| 765 | list (APPEND _GLOG_TEST_LIBS GTest::gmock) |
| 766 | endif (HAVE_LIB_GMOCK) |
| 767 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 768 | add_executable (logging_unittest |
| 769 | src/logging_unittest.cc |
| 770 | ) |
| 771 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 772 | target_link_libraries (logging_unittest PRIVATE ${_GLOG_TEST_LIBS}) |
| 773 | |
| 774 | if (WITH_CUSTOM_PREFIX) |
| 775 | add_executable (logging_custom_prefix_unittest |
| 776 | src/logging_custom_prefix_unittest.cc |
| 777 | ) |
| 778 | |
| 779 | target_link_libraries (logging_custom_prefix_unittest PRIVATE ${_GLOG_TEST_LIBS}) |
| 780 | |
| 781 | add_test (NAME logging_custom_prefix |
| 782 | COMMAND logging_custom_prefix_unittest) |
| 783 | |
| 784 | # FIXME: Skip flaky test |
| 785 | set_tests_properties (logging_custom_prefix PROPERTIES SKIP_REGULAR_EXPRESSION |
| 786 | "Check failed: time_ns within LogTimes::LOG_PERIOD_TOL_NS of LogTimes::LOG_PERIOD_NS") |
| 787 | |
| 788 | if (APPLE) |
| 789 | # FIXME: Skip flaky test |
| 790 | set_property (TEST logging_custom_prefix APPEND PROPERTY SKIP_REGULAR_EXPRESSION |
| 791 | "unexpected new.*PASS\nTest with golden file failed. We'll try to show the diff:") |
| 792 | endif (APPLE) |
| 793 | endif (WITH_CUSTOM_PREFIX) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 794 | |
| 795 | add_executable (stl_logging_unittest |
| 796 | src/stl_logging_unittest.cc |
| 797 | ) |
| 798 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 799 | target_link_libraries (stl_logging_unittest PRIVATE ${_GLOG_TEST_LIBS}) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 800 | |
| 801 | if (HAVE_NO_DEPRECATED) |
| 802 | set_property (TARGET stl_logging_unittest APPEND PROPERTY COMPILE_OPTIONS |
| 803 | -Wno-deprecated) |
| 804 | endif (HAVE_NO_DEPRECATED) |
| 805 | |
| 806 | if (HAVE_UNORDERED_MAP AND HAVE_UNORDERED_SET) |
| 807 | target_compile_definitions (stl_logging_unittest PRIVATE |
| 808 | GLOG_STL_LOGGING_FOR_UNORDERED) |
| 809 | endif (HAVE_UNORDERED_MAP AND HAVE_UNORDERED_SET) |
| 810 | |
| 811 | if (HAVE_TR1_UNORDERED_MAP AND HAVE_TR1_UNORDERED_SET) |
| 812 | target_compile_definitions (stl_logging_unittest PRIVATE |
| 813 | GLOG_STL_LOGGING_FOR_TR1_UNORDERED) |
| 814 | endif (HAVE_TR1_UNORDERED_MAP AND HAVE_TR1_UNORDERED_SET) |
| 815 | |
| 816 | if (HAVE_EXT_HASH_MAP AND HAVE_EXT_HASH_SET) |
| 817 | target_compile_definitions (stl_logging_unittest PRIVATE |
| 818 | GLOG_STL_LOGGING_FOR_EXT_HASH) |
| 819 | endif (HAVE_EXT_HASH_MAP AND HAVE_EXT_HASH_SET) |
| 820 | |
| 821 | if (HAVE_EXT_SLIST) |
| 822 | target_compile_definitions (stl_logging_unittest PRIVATE |
| 823 | GLOG_STL_LOGGING_FOR_EXT_SLIST) |
| 824 | endif (HAVE_EXT_SLIST) |
| 825 | |
| 826 | if (HAVE_SYMBOLIZE) |
| 827 | add_executable (symbolize_unittest |
| 828 | src/symbolize_unittest.cc |
| 829 | ) |
| 830 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 831 | target_link_libraries (symbolize_unittest PRIVATE ${_GLOG_TEST_LIBS}) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 832 | endif (HAVE_SYMBOLIZE) |
| 833 | |
| 834 | add_executable (demangle_unittest |
| 835 | src/demangle_unittest.cc |
| 836 | ) |
| 837 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 838 | target_link_libraries (demangle_unittest PRIVATE ${_GLOG_TEST_LIBS}) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 839 | |
| 840 | if (HAVE_STACKTRACE) |
| 841 | add_executable (stacktrace_unittest |
| 842 | src/stacktrace_unittest.cc |
| 843 | ) |
| 844 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 845 | target_link_libraries (stacktrace_unittest PRIVATE ${_GLOG_TEST_LIBS}) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 846 | endif (HAVE_STACKTRACE) |
| 847 | |
| 848 | add_executable (utilities_unittest |
| 849 | src/utilities_unittest.cc |
| 850 | ) |
| 851 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 852 | target_link_libraries (utilities_unittest PRIVATE ${_GLOG_TEST_LIBS}) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 853 | |
| 854 | if (HAVE_STACKTRACE AND HAVE_SYMBOLIZE) |
| 855 | add_executable (signalhandler_unittest |
| 856 | src/signalhandler_unittest.cc |
| 857 | ) |
| 858 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 859 | target_link_libraries (signalhandler_unittest PRIVATE ${_GLOG_TEST_LIBS}) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 860 | endif (HAVE_STACKTRACE AND HAVE_SYMBOLIZE) |
| 861 | |
| 862 | add_test (NAME demangle COMMAND demangle_unittest) |
| 863 | add_test (NAME logging COMMAND logging_unittest) |
| 864 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 865 | set_tests_properties (logging PROPERTIES TIMEOUT 30) |
| 866 | # MacOS diff is not deterministic: use the output to determine whether the |
| 867 | # test passed. |
| 868 | set_tests_properties (logging PROPERTIES PASS_REGULAR_EXPRESSION ".*\nPASS\n.*") |
| 869 | |
| 870 | # FIXME: Skip flaky test |
| 871 | set_tests_properties (logging PROPERTIES SKIP_REGULAR_EXPRESSION |
| 872 | "Check failed: time_ns within LogTimes::LOG_PERIOD_TOL_NS of LogTimes::LOG_PERIOD_NS") |
| 873 | |
| 874 | if (APPLE) |
| 875 | # FIXME: Skip flaky test |
| 876 | set_property (TEST logging APPEND PROPERTY SKIP_REGULAR_EXPRESSION |
| 877 | "unexpected new.*PASS\nTest with golden file failed. We'll try to show the diff:") |
| 878 | endif (APPLE) |
| 879 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 880 | if (TARGET signalhandler_unittest) |
| 881 | add_test (NAME signalhandler COMMAND signalhandler_unittest) |
| 882 | endif (TARGET signalhandler_unittest) |
| 883 | |
| 884 | if (TARGET stacktrace_unittest) |
| 885 | add_test (NAME stacktrace COMMAND stacktrace_unittest) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 886 | set_tests_properties (stacktrace PROPERTIES TIMEOUT 30) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 887 | endif (TARGET stacktrace_unittest) |
| 888 | |
| 889 | add_test (NAME stl_logging COMMAND stl_logging_unittest) |
| 890 | |
| 891 | if (TARGET symbolize_unittest) |
| 892 | add_test (NAME symbolize COMMAND symbolize_unittest) |
| 893 | endif (TARGET symbolize_unittest) |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 894 | |
| 895 | if (HAVE_LIB_GMOCK) |
| 896 | add_executable (mock-log_unittest |
| 897 | src/mock-log_unittest.cc |
| 898 | src/mock-log.h |
| 899 | ) |
| 900 | |
| 901 | target_link_libraries (mock-log_unittest PRIVATE ${_GLOG_TEST_LIBS}) |
| 902 | |
| 903 | add_test (NAME mock-log COMMAND mock-log_unittest) |
| 904 | endif (HAVE_LIB_GMOCK) |
| 905 | |
| 906 | # Generate an initial cache |
| 907 | |
| 908 | get_cache_variables (_CACHEVARS) |
| 909 | |
| 910 | set (_INITIAL_CACHE |
| 911 | ${CMAKE_CURRENT_BINARY_DIR}/test_package_config/glog_package_config_initial_cache.cmake) |
| 912 | |
| 913 | # Package config test |
| 914 | |
| 915 | add_test (NAME cmake_package_config_init COMMAND ${CMAKE_COMMAND} |
| 916 | -DTEST_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/test_package_config |
| 917 | -DINITIAL_CACHE=${_INITIAL_CACHE} |
| 918 | -DCACHEVARS=${_CACHEVARS} |
| 919 | -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestInitPackageConfig.cmake |
| 920 | ) |
| 921 | |
| 922 | add_test (NAME cmake_package_config_generate COMMAND ${CMAKE_COMMAND} |
| 923 | -DGENERATOR=${CMAKE_GENERATOR} |
| 924 | -DGENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} |
| 925 | -DGENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET} |
| 926 | -DINITIAL_CACHE=${_INITIAL_CACHE} |
| 927 | -DPACKAGE_DIR=${CMAKE_CURRENT_BINARY_DIR} |
| 928 | -DPATH=$ENV{PATH} |
| 929 | -DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/src/package_config_unittest/working_config |
| 930 | -DTEST_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/test_package_config/working_config |
| 931 | -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestPackageConfig.cmake |
| 932 | ) |
| 933 | |
| 934 | add_test (NAME cmake_package_config_build COMMAND |
| 935 | ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/test_package_config/working_config |
| 936 | --config $<CONFIG> |
| 937 | ) |
| 938 | |
| 939 | add_test (NAME cmake_package_config_cleanup COMMAND ${CMAKE_COMMAND} -E |
| 940 | remove_directory |
| 941 | ${CMAKE_CURRENT_BINARY_DIR}/test_package_config |
| 942 | ) |
| 943 | |
| 944 | # Fixtures setup |
| 945 | set_tests_properties (cmake_package_config_init PROPERTIES FIXTURES_SETUP |
| 946 | cmake_package_config) |
| 947 | set_tests_properties (cmake_package_config_generate PROPERTIES FIXTURES_SETUP |
| 948 | cmake_package_config_working) |
| 949 | |
| 950 | # Fixtures cleanup |
| 951 | set_tests_properties (cmake_package_config_cleanup PROPERTIES FIXTURES_CLEANUP |
| 952 | cmake_package_config) |
| 953 | |
| 954 | # Fixture requirements |
| 955 | set_tests_properties (cmake_package_config_generate PROPERTIES |
| 956 | FIXTURES_REQUIRED cmake_package_config) |
| 957 | set_tests_properties (cmake_package_config_build PROPERTIES |
| 958 | FIXTURES_REQUIRED "cmake_package_config;cmake_package_config_working") |
| 959 | |
| 960 | add_executable (cleanup_immediately_unittest |
| 961 | src/cleanup_immediately_unittest.cc) |
| 962 | |
| 963 | target_link_libraries (cleanup_immediately_unittest PRIVATE ${_GLOG_TEST_LIBS}) |
| 964 | |
| 965 | add_executable (cleanup_with_absolute_prefix_unittest |
| 966 | src/cleanup_with_absolute_prefix_unittest.cc) |
| 967 | |
| 968 | target_link_libraries (cleanup_with_absolute_prefix_unittest PRIVATE ${_GLOG_TEST_LIBS}) |
| 969 | |
| 970 | add_executable (cleanup_with_relative_prefix_unittest |
| 971 | src/cleanup_with_relative_prefix_unittest.cc) |
| 972 | |
| 973 | target_link_libraries (cleanup_with_relative_prefix_unittest PRIVATE ${_GLOG_TEST_LIBS}) |
| 974 | |
| 975 | set (CLEANUP_LOG_DIR ${CMAKE_CURRENT_BINARY_DIR}/cleanup_tests) |
| 976 | |
| 977 | add_test (NAME cleanup_init COMMAND |
| 978 | ${CMAKE_COMMAND} -E make_directory ${CLEANUP_LOG_DIR}) |
| 979 | add_test (NAME cleanup_logdir COMMAND |
| 980 | ${CMAKE_COMMAND} -E remove_directory ${CLEANUP_LOG_DIR}) |
| 981 | add_test (NAME cleanup_immediately COMMAND |
| 982 | ${CMAKE_COMMAND} |
| 983 | -DLOGCLEANUP=$<TARGET_FILE:cleanup_immediately_unittest> |
| 984 | # NOTE The trailing slash is important |
| 985 | -DTEST_DIR=${CLEANUP_LOG_DIR}/ |
| 986 | -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/RunCleanerTest1.cmake |
| 987 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
| 988 | add_test (NAME cleanup_with_absolute_prefix COMMAND |
| 989 | ${CMAKE_COMMAND} |
| 990 | -DLOGCLEANUP=$<TARGET_FILE:cleanup_with_absolute_prefix_unittest> |
| 991 | -DTEST_DIR=${CMAKE_CURRENT_BINARY_DIR}/ |
| 992 | -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/RunCleanerTest2.cmake |
| 993 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
| 994 | add_test (NAME cleanup_with_relative_prefix COMMAND |
| 995 | ${CMAKE_COMMAND} |
| 996 | -DLOGCLEANUP=$<TARGET_FILE:cleanup_with_relative_prefix_unittest> |
| 997 | -DTEST_DIR=${CMAKE_CURRENT_BINARY_DIR}/ |
| 998 | -DTEST_SUBDIR=test_subdir/ |
| 999 | -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/RunCleanerTest3.cmake |
| 1000 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) |
| 1001 | |
| 1002 | # Fixtures setup |
| 1003 | set_tests_properties (cleanup_init PROPERTIES FIXTURES_SETUP logcleanuptest) |
| 1004 | ## Fixtures cleanup |
| 1005 | set_tests_properties (cleanup_logdir PROPERTIES FIXTURES_CLEANUP logcleanuptest) |
| 1006 | # Fixture requirements |
| 1007 | set_tests_properties (cleanup_immediately PROPERTIES FIXTURES_REQUIRED logcleanuptest) |
| 1008 | set_tests_properties (cleanup_with_absolute_prefix PROPERTIES FIXTURES_REQUIRED logcleanuptest) |
| 1009 | set_tests_properties (cleanup_with_relative_prefix PROPERTIES FIXTURES_REQUIRED logcleanuptest) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 1010 | endif (BUILD_TESTING) |
| 1011 | |
| 1012 | install (TARGETS glog |
| 1013 | EXPORT glog-targets |
| 1014 | RUNTIME DESTINATION ${_glog_CMake_BINDIR} |
| 1015 | PUBLIC_HEADER DESTINATION ${_glog_CMake_INCLUDE_DIR}/glog |
| 1016 | LIBRARY DESTINATION ${_glog_CMake_LIBDIR} |
| 1017 | ARCHIVE DESTINATION ${_glog_CMake_LIBDIR}) |
| 1018 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 1019 | if (WITH_PKGCONFIG) |
| 1020 | install ( |
| 1021 | FILES "${PROJECT_BINARY_DIR}/libglog.pc" |
| 1022 | DESTINATION "${_glog_CMake_LIBDIR}/pkgconfig" |
| 1023 | ) |
| 1024 | endif (WITH_PKGCONFIG) |
| 1025 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 1026 | set (glog_CMake_VERSION 3.0) |
| 1027 | |
| 1028 | if (gflags_FOUND) |
| 1029 | # Ensure clients locate only the package config and not third party find |
| 1030 | # modules having the same name. This avoid cmake_policy PUSH/POP errors. |
| 1031 | if (CMAKE_VERSION VERSION_LESS 3.9) |
| 1032 | set (gflags_DEPENDENCY "find_dependency (gflags ${gflags_VERSION})") |
| 1033 | else (CMAKE_VERSION VERSION_LESS 3.9) |
| 1034 | # Passing additional find_package arguments to find_dependency is possible |
| 1035 | # starting with CMake 3.9. |
| 1036 | set (glog_CMake_VERSION 3.9) |
| 1037 | set (gflags_DEPENDENCY "find_dependency (gflags ${gflags_VERSION} NO_MODULE)") |
| 1038 | endif (CMAKE_VERSION VERSION_LESS 3.9) |
| 1039 | endif (gflags_FOUND) |
| 1040 | |
| 1041 | configure_package_config_file (glog-config.cmake.in |
| 1042 | ${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake |
| 1043 | INSTALL_DESTINATION ${_glog_CMake_INSTALLDIR} |
| 1044 | NO_CHECK_REQUIRED_COMPONENTS_MACRO) |
| 1045 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 1046 | write_basic_package_version_file ( |
| 1047 | ${CMAKE_CURRENT_BINARY_DIR}/glog-config-version.cmake |
| 1048 | COMPATIBILITY SameMajorVersion) |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 1049 | |
| 1050 | export (TARGETS glog NAMESPACE glog:: FILE glog-targets.cmake) |
| 1051 | export (PACKAGE glog) |
| 1052 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 1053 | get_filename_component (_PREFIX "${CMAKE_INSTALL_PREFIX}" ABSOLUTE) |
| 1054 | |
| 1055 | # Directory containing the find modules relative to the config install |
| 1056 | # directory. |
| 1057 | file (RELATIVE_PATH glog_REL_CMake_MODULES |
| 1058 | ${_PREFIX}/${_glog_CMake_INSTALLDIR} |
| 1059 | ${_PREFIX}/${_glog_CMake_DATADIR}/glog-modules.cmake) |
| 1060 | |
| 1061 | get_filename_component (glog_REL_CMake_DATADIR ${glog_REL_CMake_MODULES} |
| 1062 | DIRECTORY) |
| 1063 | |
| 1064 | set (glog_FULL_CMake_DATADIR |
| 1065 | ${CMAKE_CURRENT_BINARY_DIR}/${_glog_CMake_DATADIR}) |
| 1066 | |
| 1067 | configure_file (glog-modules.cmake.in |
| 1068 | ${CMAKE_CURRENT_BINARY_DIR}/glog-modules.cmake @ONLY) |
| 1069 | |
| 1070 | install (CODE |
| 1071 | " |
| 1072 | set (glog_FULL_CMake_DATADIR \"\\\${CMAKE_CURRENT_LIST_DIR}/${glog_REL_CMake_DATADIR}\") |
| 1073 | set (glog_DATADIR_DESTINATION ${_glog_CMake_INSTALLDIR}) |
| 1074 | |
| 1075 | if (NOT IS_ABSOLUTE ${_glog_CMake_INSTALLDIR}) |
| 1076 | set (glog_DATADIR_DESTINATION \"\${CMAKE_INSTALL_PREFIX}/\${glog_DATADIR_DESTINATION}\") |
| 1077 | endif (NOT IS_ABSOLUTE ${_glog_CMake_INSTALLDIR}) |
| 1078 | |
| 1079 | configure_file (\"${CMAKE_CURRENT_SOURCE_DIR}/glog-modules.cmake.in\" |
| 1080 | \"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/glog-modules.cmake\" @ONLY) |
| 1081 | file (INSTALL |
| 1082 | \"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/glog-modules.cmake\" |
| 1083 | DESTINATION |
| 1084 | \"\${glog_DATADIR_DESTINATION}\") |
| 1085 | " |
| 1086 | COMPONENT Development |
| 1087 | ) |
| 1088 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 1089 | install (FILES |
| 1090 | ${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake |
| 1091 | ${CMAKE_CURRENT_BINARY_DIR}/glog-config-version.cmake |
| 1092 | DESTINATION ${_glog_CMake_INSTALLDIR}) |
| 1093 | |
James Kuszmaul | ba0ac1a | 2022-08-12 16:29:30 -0700 | [diff] [blame^] | 1094 | # Find modules in share/glog/cmake |
| 1095 | install (DIRECTORY ${_glog_BINARY_CMake_DATADIR} |
| 1096 | DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/glog |
| 1097 | COMPONENT Development |
| 1098 | FILES_MATCHING PATTERN "*.cmake" |
| 1099 | ) |
| 1100 | |
Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 1101 | install (EXPORT glog-targets NAMESPACE glog:: DESTINATION |
| 1102 | ${_glog_CMake_INSTALLDIR}) |