Austin Schuh | 906616c | 2019-01-21 20:25:11 -0800 | [diff] [blame] | 1 | cmake_minimum_required (VERSION 3.0) |
| 2 | |
| 3 | if (POLICY CMP0042) |
| 4 | cmake_policy (SET CMP0042 NEW) |
| 5 | endif (POLICY CMP0042) |
| 6 | |
| 7 | if (POLICY CMP0063) |
| 8 | cmake_policy (SET CMP0063 NEW) |
| 9 | endif (POLICY CMP0063) |
| 10 | |
| 11 | project(glog VERSION 0.3.5 LANGUAGES C CXX) |
| 12 | |
| 13 | set (CPACK_PACKAGE_NAME glog) |
| 14 | set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "") |
| 15 | set (CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR}) |
| 16 | set (CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR}) |
| 17 | set (CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH}) |
| 18 | set (CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) |
| 19 | |
| 20 | option (WITH_GFLAGS "Use gflags" ON) |
| 21 | option (WITH_THREADS "Enable multithreading support" ON) |
| 22 | option (WITH_TLS "Enable Thread Local Storage (TLS) support" ON) |
| 23 | option (BUILD_SHARED_LIBS "Build shared libraries" OFF) |
| 24 | option (PRINT_UNSYMBOLIZED_STACK_TRACES |
| 25 | "Print raw pc values on symbolization failure" OFF) |
| 26 | |
| 27 | list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) |
| 28 | |
| 29 | include (CheckCSourceCompiles) |
| 30 | include (CheckCXXCompilerFlag) |
| 31 | include (CheckCXXSourceCompiles) |
| 32 | include (CheckCXXSourceRuns) |
| 33 | include (CheckFunctionExists) |
| 34 | include (CheckIncludeFile) |
| 35 | include (CheckIncludeFileCXX) |
| 36 | include (CheckLibraryExists) |
| 37 | include (CheckStructHasMember) |
| 38 | include (CheckSymbolExists) |
| 39 | include (CheckTypeSize) |
| 40 | include (CMakePackageConfigHelpers) |
| 41 | include (CMakePushCheckState) |
| 42 | include (CPack) |
| 43 | include (CTest) |
| 44 | include (DetermineGflagsNamespace) |
| 45 | include (GNUInstallDirs) |
| 46 | |
| 47 | set (CMAKE_DEBUG_POSTFIX d) |
| 48 | set (CMAKE_THREAD_PREFER_PTHREAD 1) |
| 49 | |
| 50 | if (WITH_GFLAGS) |
| 51 | find_package (gflags 2.2.0) |
| 52 | |
| 53 | if (gflags_FOUND) |
| 54 | set (HAVE_LIB_GFLAGS 1) |
| 55 | determine_gflags_namespace (gflags_NAMESPACE) |
| 56 | endif (gflags_FOUND) |
| 57 | endif (WITH_GFLAGS) |
| 58 | |
| 59 | if (WITH_THREADS) |
| 60 | find_package (Threads) |
| 61 | endif (WITH_THREADS) |
| 62 | |
| 63 | check_include_file (dlfcn.h HAVE_DLFCN_H) |
| 64 | check_include_file (execinfo.h HAVE_EXECINFO_H) |
| 65 | check_include_file (glob.h HAVE_GLOB_H) |
| 66 | check_include_file (inttypes.h HAVE_INTTYPES_H) |
| 67 | check_include_file (libunwind.h HAVE_LIBUNWIND_H) |
| 68 | check_include_file (memory.h HAVE_MEMORY_H) |
| 69 | check_include_file (pwd.h HAVE_PWD_H) |
| 70 | check_include_file (stdint.h HAVE_STDINT_H) |
| 71 | check_include_file (stdlib.h HAVE_STDLIB_H) |
| 72 | check_include_file (string.h HAVE_STRING_H) |
| 73 | check_include_file (strings.h HAVE_STRINGS_H) |
| 74 | check_include_file (sys/stat.h HAVE_SYS_STAT_H) |
| 75 | check_include_file (sys/syscall.h HAVE_SYS_SYSCALL_H) |
| 76 | check_include_file (sys/time.h HAVE_SYS_TIME_H) |
| 77 | check_include_file (sys/types.h HAVE_SYS_TYPES_H) |
| 78 | check_include_file (sys/utsname.h HAVE_SYS_UTSNAME_H) |
| 79 | check_include_file (syscall.h HAVE_SYSCALL_H) |
| 80 | check_include_file (syslog.h HAVE_SYSLOG_H) |
| 81 | check_include_file (ucontext.h HAVE_UCONTEXT_H) |
| 82 | check_include_file (unistd.h HAVE_UNISTD_H) |
| 83 | check_include_file (unwind.h HAVE_UNWIND_H) |
| 84 | check_include_file (pwd.h HAVE_PWD_H) |
| 85 | |
| 86 | check_include_file_cxx ("ext/hash_map" HAVE_EXT_HASH_MAP) |
| 87 | check_include_file_cxx ("ext/hash_set" HAVE_EXT_HASH_SET) |
| 88 | check_include_file_cxx ("ext/slist" HAVE_EXT_SLIST) |
| 89 | check_include_file_cxx ("tr1/unordered_map" HAVE_TR1_UNORDERED_MAP) |
| 90 | check_include_file_cxx ("tr1/unordered_set" HAVE_TR1_UNORDERED_SET) |
| 91 | check_include_file_cxx ("unordered_map" HAVE_UNORDERED_MAP) |
| 92 | check_include_file_cxx ("unordered_set" HAVE_UNORDERED_SET) |
| 93 | |
| 94 | check_type_size ("unsigned __int16" HAVE___UINT16) |
| 95 | check_type_size (u_int16_t HAVE_U_INT16_T) |
| 96 | check_type_size (uint16_t HAVE_UINT16_T) |
| 97 | |
| 98 | check_function_exists (dladdr HAVE_DLADDR) |
| 99 | check_function_exists (fcntl HAVE_FCNTL) |
| 100 | check_function_exists (pread HAVE_PREAD) |
| 101 | check_function_exists (pwrite HAVE_PWRITE) |
| 102 | check_function_exists (sigaction HAVE_SIGACTION) |
| 103 | check_function_exists (sigaltstack HAVE_SIGALSTACK) |
| 104 | |
| 105 | # NOTE gcc does not fail if you pass a non-existent -Wno-* option as an |
| 106 | # argument. However, it will happily fail if you pass the corresponding -W* |
| 107 | # option. So, we check whether options that disable warnings exist by testing |
| 108 | # the availability of the corresponding option that enables the warning. This |
| 109 | # eliminates the need to check for compiler for several (mainly Clang) options. |
| 110 | |
| 111 | check_cxx_compiler_flag (-Wdeprecated HAVE_NO_DEPRECATED) |
| 112 | check_cxx_compiler_flag (-Wunnamed-type-template-args |
| 113 | HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS) |
| 114 | |
| 115 | # NOTE: Cannot use check_function_exists here since >=vc-14.0 can define |
| 116 | # snprintf as an inline function |
| 117 | check_symbol_exists (snprintf stdio.h HAVE_SNPRINTF) |
| 118 | |
| 119 | check_library_exists (unwind get_static_proc_name "" HAVE_LIB_UNWIND) |
| 120 | check_library_exists (dbghelp UnDecorateSymbolName "" HAVE_DBGHELP) |
| 121 | |
| 122 | find_library (UNWIND_LIBRARY NAMES unwind DOC "unwind library") |
| 123 | mark_as_advanced (UNWIND_LIBRARY) |
| 124 | |
| 125 | check_c_source_compiles (" |
| 126 | #include <stdlib.h> |
| 127 | static void foo(void) __attribute__ ((unused)); |
| 128 | int main(void) { return 0; } |
| 129 | " HAVE___ATTRIBUTE__) |
| 130 | |
| 131 | check_c_source_compiles (" |
| 132 | #include <stdlib.h> |
| 133 | static void foo(void) __attribute__ ((visibility(\"default\"))); |
| 134 | int main(void) { return 0; } |
| 135 | " HAVE___ATTRIBUTE__VISIBILITY_DEFAULT) |
| 136 | |
| 137 | check_c_source_compiles (" |
| 138 | #include <stdlib.h> |
| 139 | static void foo(void) __attribute__ ((visibility(\"hidden\"))); |
| 140 | int main(void) { return 0; } |
| 141 | " HAVE___ATTRIBUTE__VISIBILITY_HIDDEN) |
| 142 | |
| 143 | check_c_source_compiles (" |
| 144 | int main(void) { if (__builtin_expect(0, 0)) return 1; return 0; } |
| 145 | " HAVE___BUILTIN_EXPECT) |
| 146 | |
| 147 | check_c_source_compiles (" |
| 148 | int main(void) |
| 149 | { |
| 150 | int a; if (__sync_val_compare_and_swap(&a, 0, 1)) return 1; return 0; |
| 151 | } |
| 152 | " HAVE___SYNC_VAL_COMPARE_AND_SWAP) |
| 153 | |
| 154 | check_c_source_compiles (" |
| 155 | #define _XOPEN_SOURCE 500 |
| 156 | #include <pthread.h> |
| 157 | int main(void) |
| 158 | { |
| 159 | pthread_rwlock_t l; |
| 160 | pthread_rwlock_init(&l, NULL); |
| 161 | pthread_rwlock_rdlock(&l); |
| 162 | return 0; |
| 163 | } |
| 164 | " HAVE_RWLOCK) |
| 165 | |
| 166 | check_c_source_compiles (" |
| 167 | __declspec(selectany) int a; |
| 168 | int main(void) { return 0; } |
| 169 | " HAVE___DECLSPEC) |
| 170 | |
| 171 | check_cxx_source_compiles (" |
| 172 | #include <vector> |
| 173 | vector<int> t; int main() { } |
| 174 | " STL_NO_NAMESPACE) |
| 175 | |
| 176 | check_cxx_source_compiles (" |
| 177 | #include <vector> |
| 178 | std::vector<int> t; int main() { } |
| 179 | " STL_STD_NAMESPACE) |
| 180 | |
| 181 | check_cxx_source_compiles (" |
| 182 | #include <iostream> |
| 183 | std::ostream& operator<<(std::ostream&, struct s); |
| 184 | using ::operator<<; |
| 185 | int main() { } |
| 186 | " HAVE_USING_OPERATOR) |
| 187 | |
| 188 | check_cxx_source_compiles (" |
| 189 | namespace Outer { namespace Inner { int i = 0; }} |
| 190 | using namespace Outer::Inner;; |
| 191 | int main() { return i; } |
| 192 | " HAVE_NAMESPACES) |
| 193 | |
| 194 | check_cxx_source_compiles (" |
| 195 | __thread int tls; |
| 196 | int main() { } |
| 197 | " HAVE_GCC_TLS) |
| 198 | |
| 199 | check_cxx_source_compiles (" |
| 200 | __declspec(thread) int tls; |
| 201 | int main() { } |
| 202 | " HAVE_MSVC_TLS) |
| 203 | |
| 204 | check_cxx_source_compiles (" |
| 205 | thread_local int tls; |
| 206 | int main() { } |
| 207 | " HAVE_CXX11_TLS) |
| 208 | |
| 209 | check_cxx_source_compiles (" |
| 210 | #include <type_traits> |
| 211 | std::aligned_storage<sizeof(char), alignof(char)>::type data; |
| 212 | int main() { } |
| 213 | " HAVE_ALIGNED_STORAGE) |
| 214 | |
| 215 | if (WITH_TLS) |
| 216 | # Cygwin does not support the thread attribute. Don't bother. |
| 217 | if (HAVE_GCC_TLS) |
| 218 | set (GLOG_THREAD_LOCAL_STORAGE "__thread") |
| 219 | elseif (HAVE_MSVC_TLS) |
| 220 | set (GLOG_THREAD_LOCAL_STORAGE "__declspec(thread)") |
| 221 | elseif (HAVE_CXX11_TLS) |
| 222 | set (GLOG_THREAD_LOCAL_STORAGE thread_local) |
| 223 | endif (HAVE_GCC_TLS) |
| 224 | endif (WITH_TLS) |
| 225 | |
| 226 | set (_PC_FIELDS |
| 227 | "gregs[REG_PC]" |
| 228 | "gregs[REG_EIP]" |
| 229 | "gregs[REG_RIP]" |
| 230 | "sc_ip" |
| 231 | "uc_regs->gregs[PT_NIP]" |
| 232 | "gregs[R15]" |
| 233 | "arm_pc" |
| 234 | "mc_eip" |
| 235 | "mc_rip" |
| 236 | "__gregs[REG_EIP]" |
| 237 | "__gregs[REG_RIP]" |
| 238 | "ss.eip" |
| 239 | "__ss.__eip" |
| 240 | "ss.rip" |
| 241 | "__ss.__rip" |
| 242 | "ss.srr0" |
| 243 | "__ss.__srr0" |
| 244 | ) |
| 245 | |
| 246 | set (_PC_HEADERS ucontext.h signal.h) |
| 247 | |
| 248 | if (HAVE_UCONTEXT_H AND NOT PC_FROM_UCONTEXT) |
| 249 | foreach (_PC_FIELD ${_PC_FIELDS}) |
| 250 | foreach (_PC_HEADER ${_PC_HEADERS}) |
| 251 | set (_TMP |
| 252 | ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/uctfield.c) |
| 253 | file (WRITE ${_TMP} " |
| 254 | #define _GNU_SOURCE 1 |
| 255 | #include <${_PC_HEADER}> |
| 256 | int main(void) |
| 257 | { |
| 258 | ucontext_t u; |
| 259 | return u.${_PC_FIELD} == 0; |
| 260 | } |
| 261 | ") |
| 262 | try_compile (HAVE_PC_FROM_UCONTEXT ${CMAKE_CURRENT_BINARY_DIR} ${_TMP} |
| 263 | COMPILE_DEFINITIONS _GNU_SOURCE=1) |
| 264 | |
| 265 | if (HAVE_PC_FROM_UCONTEXT) |
| 266 | set (PC_FROM_UCONTEXT ${_PC_FIELD} CACHE) |
| 267 | endif (HAVE_PC_FROM_UCONTEXT) |
| 268 | endforeach (_PC_HEADER) |
| 269 | endforeach (_PC_FIELD) |
| 270 | endif (HAVE_UCONTEXT_H AND NOT PC_FROM_UCONTEXT) |
| 271 | |
| 272 | if (STL_STD_NAMESPACE) |
| 273 | set (STL_NAMESPACE std) |
| 274 | else (STL_STD_NAMESPACE) |
| 275 | set (STL_NAMESPACE "") |
| 276 | endif (STL_STD_NAMESPACE) |
| 277 | |
| 278 | set (GOOGLE_NAMESPACE google) |
| 279 | set (_START_GOOGLE_NAMESPACE_ "namespace ${GOOGLE_NAMESPACE} {") |
| 280 | set (_END_GOOGLE_NAMESPACE_ "}") |
| 281 | |
| 282 | if (HAVE___UINT16) |
| 283 | set (ac_cv_have___uint16 1) |
| 284 | else (HAVE___UINT16) |
| 285 | set (ac_cv_have___uint16 0) |
| 286 | endif (HAVE___UINT16) |
| 287 | |
| 288 | if (HAVE_INTTYPES_H) |
| 289 | set (ac_cv_have_inttypes_h 1) |
| 290 | else (HAVE_INTTYPES_H) |
| 291 | set (ac_cv_have_inttypes_h 0) |
| 292 | endif (HAVE_INTTYPES_H) |
| 293 | |
| 294 | if (HAVE_LIB_GFLAGS) |
| 295 | set (ac_cv_have_libgflags 1) |
| 296 | else (HAVE_LIB_GFLAGS) |
| 297 | set (ac_cv_have_libgflags 0) |
| 298 | endif (HAVE_LIB_GFLAGS) |
| 299 | |
| 300 | if (HAVE_STDINT_H) |
| 301 | set (ac_cv_have_stdint_h 1) |
| 302 | else (HAVE_STDINT_H) |
| 303 | set (ac_cv_have_stdint_h 0) |
| 304 | endif (HAVE_STDINT_H) |
| 305 | |
| 306 | if (HAVE_SYS_TYPES_H) |
| 307 | set (ac_cv_have_systypes_h 1) |
| 308 | else (HAVE_SYS_TYPES_H) |
| 309 | set (ac_cv_have_systypes_h 0) |
| 310 | endif (HAVE_SYS_TYPES_H) |
| 311 | |
| 312 | if (HAVE_U_INT16_T) |
| 313 | set (ac_cv_have_u_int16_t 1) |
| 314 | else (HAVE_U_INT16_T) |
| 315 | set (ac_cv_have_u_int16_t 0) |
| 316 | endif (HAVE_U_INT16_T) |
| 317 | |
| 318 | if (HAVE_UINT16_T) |
| 319 | set (ac_cv_have_uint16_t 1) |
| 320 | else (HAVE_UINT16_T) |
| 321 | set (ac_cv_have_uint16_t 0) |
| 322 | endif (HAVE_UINT16_T) |
| 323 | |
| 324 | if (HAVE_UNISTD_H) |
| 325 | set (ac_cv_have_unistd_h 1) |
| 326 | else (HAVE_UNISTD_H) |
| 327 | set (ac_cv_have_unistd_h 0) |
| 328 | endif (HAVE_UNISTD_H) |
| 329 | |
| 330 | set (ac_google_namespace ${GOOGLE_NAMESPACE}) |
| 331 | set (ac_google_end_namespace ${_END_GOOGLE_NAMESPACE_}) |
| 332 | set (ac_google_start_namespace ${_START_GOOGLE_NAMESPACE_}) |
| 333 | |
| 334 | if (HAVE___ATTRIBUTE__) |
| 335 | set (ac_cv___attribute___noreturn "__attribute__((noreturn))") |
| 336 | set (ac_cv___attribute___noinline "__attribute__((noinline))") |
| 337 | elseif (HAVE___DECLSPEC) |
| 338 | set (ac_cv___attribute___noreturn "__declspec(noreturn)") |
| 339 | #set (ac_cv___attribute___noinline "__declspec(noinline)") |
| 340 | endif (HAVE___ATTRIBUTE__) |
| 341 | |
| 342 | if (HAVE___BUILTIN_EXPECT) |
| 343 | set (ac_cv_have___builtin_expect 1) |
| 344 | else (HAVE___BUILTIN_EXPECT) |
| 345 | set (ac_cv_have___builtin_expect 0) |
| 346 | endif (HAVE___BUILTIN_EXPECT) |
| 347 | |
| 348 | if (HAVE_USING_OPERATOR) |
| 349 | set (ac_cv_cxx_using_operator 1) |
| 350 | else (HAVE_USING_OPERATOR) |
| 351 | set (ac_cv_cxx_using_operator 0) |
| 352 | endif (HAVE_USING_OPERATOR) |
| 353 | |
| 354 | if (HAVE_EXECINFO_H) |
| 355 | set (HAVE_STACKTRACE 1) |
| 356 | endif (HAVE_EXECINFO_H) |
| 357 | |
| 358 | if (WIN32 OR CYGWIN) |
| 359 | cmake_push_check_state (RESET) |
| 360 | set (CMAKE_REQUIRED_LIBRARIES DbgHelp) |
| 361 | |
| 362 | check_cxx_source_runs ([=[ |
| 363 | #include <windows.h> |
| 364 | #include <dbghelp.h> |
| 365 | #include <cstdlib> |
| 366 | |
| 367 | void foobar() { } |
| 368 | |
| 369 | int main() |
| 370 | { |
| 371 | HANDLE process = GetCurrentProcess(); |
| 372 | |
| 373 | if (!SymInitialize(process, NULL, TRUE)) |
| 374 | return EXIT_FAILURE; |
| 375 | |
| 376 | char buf[sizeof(SYMBOL_INFO) + MAX_SYM_NAME]; |
| 377 | SYMBOL_INFO *symbol = reinterpret_cast<SYMBOL_INFO *>(buf); |
| 378 | symbol->SizeOfStruct = sizeof(SYMBOL_INFO); |
| 379 | symbol->MaxNameLen = MAX_SYM_NAME; |
| 380 | |
| 381 | void* const pc = reinterpret_cast<void*>(&foobar); |
| 382 | BOOL ret = SymFromAddr(process, reinterpret_cast<DWORD64>(pc), 0, symbol); |
| 383 | |
| 384 | return ret ? EXIT_SUCCESS : EXIT_FAILURE; |
| 385 | } |
| 386 | ]=] HAVE_SYMBOLIZE) |
| 387 | |
| 388 | cmake_pop_check_state () |
| 389 | |
| 390 | if (HAVE_SYMBOLIZE) |
| 391 | set (HAVE_STACKTRACE 1) |
| 392 | endif (HAVE_SYMBOLIZE) |
| 393 | elseif (UNIX OR (APPLE AND HAVE_DLADDR)) |
| 394 | set (HAVE_SYMBOLIZE 1) |
| 395 | endif (WIN32 OR CYGWIN) |
| 396 | |
| 397 | check_cxx_source_compiles (" |
| 398 | #include <cstdlib> |
| 399 | #include <time.h> |
| 400 | int main() |
| 401 | { |
| 402 | time_t timep; |
| 403 | struct tm result; |
| 404 | localtime_r(&timep, &result); |
| 405 | return EXIT_SUCCESS; |
| 406 | } |
| 407 | " HAVE_LOCALTIME_R) |
| 408 | |
| 409 | set (SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) |
| 410 | |
| 411 | if (WITH_THREADS AND Threads_FOUND) |
| 412 | if (CMAKE_USE_PTHREADS_INIT) |
| 413 | set (HAVE_PTHREAD 1) |
| 414 | endif (CMAKE_USE_PTHREADS_INIT) |
| 415 | else (WITH_THREADS AND Threads_FOUND) |
| 416 | set (NO_THREADS 1) |
| 417 | endif (WITH_THREADS AND Threads_FOUND) |
| 418 | |
| 419 | set (TEST_SRC_DIR \"${CMAKE_CURRENT_SOURCE_DIR}\") |
| 420 | |
| 421 | configure_file (src/config.h.cmake.in config.h) |
| 422 | configure_file (src/glog/logging.h.in glog/logging.h @ONLY) |
| 423 | configure_file (src/glog/raw_logging.h.in glog/raw_logging.h @ONLY) |
| 424 | configure_file (src/glog/stl_logging.h.in glog/stl_logging.h @ONLY) |
| 425 | configure_file (src/glog/vlog_is_on.h.in glog/vlog_is_on.h @ONLY) |
| 426 | |
| 427 | set (CMAKE_CXX_VISIBILITY_PRESET default) |
| 428 | set (CMAKE_VISIBILITY_INLINES_HIDDEN 1) |
| 429 | |
| 430 | set (GLOG_PUBLIC_H |
| 431 | ${CMAKE_CURRENT_BINARY_DIR}/glog/logging.h |
| 432 | ${CMAKE_CURRENT_BINARY_DIR}/glog/raw_logging.h |
| 433 | ${CMAKE_CURRENT_BINARY_DIR}/glog/stl_logging.h |
| 434 | ${CMAKE_CURRENT_BINARY_DIR}/glog/vlog_is_on.h |
| 435 | src/glog/log_severity.h |
| 436 | ) |
| 437 | |
| 438 | set (GLOG_SRCS |
| 439 | ${GLOG_PUBLIC_H} |
| 440 | src/base/commandlineflags.h |
| 441 | src/base/googleinit.h |
| 442 | src/base/mutex.h |
| 443 | src/demangle.cc |
| 444 | src/demangle.h |
| 445 | src/logging.cc |
| 446 | src/raw_logging.cc |
| 447 | src/symbolize.cc |
| 448 | src/symbolize.h |
| 449 | src/utilities.cc |
| 450 | src/utilities.h |
| 451 | src/vlog_is_on.cc |
| 452 | ) |
| 453 | |
| 454 | if (HAVE_PTHREAD OR WIN32) |
| 455 | list (APPEND GLOG_SRCS src/signalhandler.cc) |
| 456 | endif (HAVE_PTHREAD OR WIN32) |
| 457 | |
| 458 | if (WIN32) |
| 459 | list (APPEND GLOG_SRCS |
| 460 | src/windows/port.cc |
| 461 | src/windows/port.h |
| 462 | ) |
| 463 | endif (WIN32) |
| 464 | |
| 465 | add_compile_options ($<$<AND:$<BOOL:${HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS}>,$<NOT:$<CXX_COMPILER_ID:GNU>>>:-Wno-unnamed-type-template-args>) |
| 466 | |
| 467 | add_library (glog |
| 468 | ${GLOG_SRCS} |
| 469 | ) |
| 470 | add_library(glog::glog ALIAS glog) |
| 471 | |
| 472 | set_target_properties (glog PROPERTIES POSITION_INDEPENDENT_CODE ON) |
| 473 | |
| 474 | if (UNWIND_LIBRARY) |
| 475 | target_link_libraries (glog PUBLIC ${UNWIND_LIBRARY}) |
| 476 | endif (UNWIND_LIBRARY) |
| 477 | |
| 478 | if (HAVE_DBGHELP) |
| 479 | target_link_libraries (glog PUBLIC dbghelp) |
| 480 | endif (HAVE_DBGHELP) |
| 481 | |
| 482 | if (HAVE_PTHREAD) |
| 483 | target_link_libraries (glog PUBLIC ${CMAKE_THREAD_LIBS_INIT}) |
| 484 | endif (HAVE_PTHREAD) |
| 485 | |
| 486 | if (WIN32 AND HAVE_SNPRINTF) |
| 487 | set_property (SOURCE src/windows/port.cc APPEND PROPERTY COMPILE_DEFINITIONS |
| 488 | HAVE_SNPRINTF) |
| 489 | endif (WIN32 AND HAVE_SNPRINTF) |
| 490 | |
| 491 | if (gflags_FOUND) |
| 492 | target_link_libraries (glog PUBLIC gflags) |
| 493 | |
| 494 | if (NOT BUILD_SHARED_LIBS) |
| 495 | # Don't use __declspec(dllexport|dllimport) if this is a static build |
| 496 | targeT_compile_definitions (glog PUBLIC GFLAGS_DLL_DECLARE_FLAG= GFLAGS_DLL_DEFINE_FLAG=) |
| 497 | endif (NOT BUILD_SHARED_LIBS) |
| 498 | endif (gflags_FOUND) |
| 499 | |
| 500 | set_target_properties (glog PROPERTIES VERSION ${PROJECT_VERSION}) |
| 501 | set_target_properties (glog PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR}) |
| 502 | |
| 503 | if (WIN32) |
| 504 | target_compile_definitions (glog PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES) |
| 505 | endif (WIN32) |
| 506 | |
| 507 | set_target_properties (glog PROPERTIES PUBLIC_HEADER "${GLOG_PUBLIC_H}") |
| 508 | |
| 509 | set (_glog_CMake_BINDIR ${CMAKE_INSTALL_BINDIR}) |
| 510 | set (_glog_CMake_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}) |
| 511 | set (_glog_CMake_LIBDIR ${CMAKE_INSTALL_LIBDIR}) |
| 512 | set (_glog_CMake_INSTALLDIR ${_glog_CMake_LIBDIR}/cmake/glog) |
| 513 | |
| 514 | target_include_directories (glog BEFORE PUBLIC |
| 515 | "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>" |
| 516 | "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>" |
| 517 | "$<INSTALL_INTERFACE:${_glog_CMake_INCLUDE_DIR}>" |
| 518 | PRIVATE ${CMAKE_CURRENT_BINARY_DIR} |
| 519 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src) |
| 520 | |
| 521 | if (WIN32) |
| 522 | target_include_directories (glog PUBLIC |
| 523 | "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/windows>" |
| 524 | PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/windows) |
| 525 | endif (WIN32) |
| 526 | |
| 527 | set_target_properties (glog PROPERTIES DEFINE_SYMBOL LIBGLOG_EXPORTS) |
| 528 | |
| 529 | if (NOT BUILD_SHARED_LIBS) |
| 530 | target_compile_definitions (glog PUBLIC GOOGLE_GLOG_DLL_DECL=) |
| 531 | else (NOT BUILD_SHARED_LIBS) |
| 532 | target_compile_definitions (glog PRIVATE GOOGLE_GLOG_IS_A_DLL=1) |
| 533 | |
| 534 | if (HAVE___ATTRIBUTE__VISIBILITY_DEFAULT) |
| 535 | set (_EXPORT "__attribute__((visibility(\"default\")))") |
| 536 | set (_IMPORT "") |
| 537 | elseif (HAVE___DECLSPEC) |
| 538 | set (_EXPORT "__declspec(dllexport)") |
| 539 | set (_IMPORT "__declspec(dllimport)") |
| 540 | endif (HAVE___ATTRIBUTE__VISIBILITY_DEFAULT) |
| 541 | |
| 542 | target_compile_definitions (glog PRIVATE |
| 543 | "GOOGLE_GLOG_DLL_DECL=${_EXPORT}") |
| 544 | target_compile_definitions (glog INTERFACE |
| 545 | "GOOGLE_GLOG_DLL_DECL=${_IMPORT}") |
| 546 | target_compile_definitions (glog INTERFACE |
| 547 | "GOOGLE_GLOG_DLL_DECL_FOR_UNITTESTS=${_IMPORT}") |
| 548 | endif (NOT BUILD_SHARED_LIBS) |
| 549 | |
| 550 | # Unit testing |
| 551 | |
| 552 | if (BUILD_TESTING) |
| 553 | add_executable (logging_unittest |
| 554 | src/logging_unittest.cc |
| 555 | ) |
| 556 | |
| 557 | target_link_libraries (logging_unittest PRIVATE glog) |
| 558 | |
| 559 | add_executable (stl_logging_unittest |
| 560 | src/stl_logging_unittest.cc |
| 561 | ) |
| 562 | |
| 563 | target_link_libraries (stl_logging_unittest PRIVATE glog) |
| 564 | |
| 565 | if (HAVE_NO_DEPRECATED) |
| 566 | set_property (TARGET stl_logging_unittest APPEND PROPERTY COMPILE_OPTIONS |
| 567 | -Wno-deprecated) |
| 568 | endif (HAVE_NO_DEPRECATED) |
| 569 | |
| 570 | if (HAVE_UNORDERED_MAP AND HAVE_UNORDERED_SET) |
| 571 | target_compile_definitions (stl_logging_unittest PRIVATE |
| 572 | GLOG_STL_LOGGING_FOR_UNORDERED) |
| 573 | endif (HAVE_UNORDERED_MAP AND HAVE_UNORDERED_SET) |
| 574 | |
| 575 | if (HAVE_TR1_UNORDERED_MAP AND HAVE_TR1_UNORDERED_SET) |
| 576 | target_compile_definitions (stl_logging_unittest PRIVATE |
| 577 | GLOG_STL_LOGGING_FOR_TR1_UNORDERED) |
| 578 | endif (HAVE_TR1_UNORDERED_MAP AND HAVE_TR1_UNORDERED_SET) |
| 579 | |
| 580 | if (HAVE_EXT_HASH_MAP AND HAVE_EXT_HASH_SET) |
| 581 | target_compile_definitions (stl_logging_unittest PRIVATE |
| 582 | GLOG_STL_LOGGING_FOR_EXT_HASH) |
| 583 | endif (HAVE_EXT_HASH_MAP AND HAVE_EXT_HASH_SET) |
| 584 | |
| 585 | if (HAVE_EXT_SLIST) |
| 586 | target_compile_definitions (stl_logging_unittest PRIVATE |
| 587 | GLOG_STL_LOGGING_FOR_EXT_SLIST) |
| 588 | endif (HAVE_EXT_SLIST) |
| 589 | |
| 590 | if (HAVE_SYMBOLIZE) |
| 591 | add_executable (symbolize_unittest |
| 592 | src/symbolize_unittest.cc |
| 593 | ) |
| 594 | |
| 595 | target_link_libraries (symbolize_unittest PRIVATE glog) |
| 596 | endif (HAVE_SYMBOLIZE) |
| 597 | |
| 598 | add_executable (demangle_unittest |
| 599 | src/demangle_unittest.cc |
| 600 | ) |
| 601 | |
| 602 | target_link_libraries (demangle_unittest PRIVATE glog) |
| 603 | |
| 604 | if (HAVE_STACKTRACE) |
| 605 | add_executable (stacktrace_unittest |
| 606 | src/stacktrace_unittest.cc |
| 607 | ) |
| 608 | |
| 609 | target_link_libraries (stacktrace_unittest PRIVATE glog) |
| 610 | endif (HAVE_STACKTRACE) |
| 611 | |
| 612 | add_executable (utilities_unittest |
| 613 | src/utilities_unittest.cc |
| 614 | ) |
| 615 | |
| 616 | target_link_libraries (utilities_unittest PRIVATE glog) |
| 617 | |
| 618 | if (HAVE_STACKTRACE AND HAVE_SYMBOLIZE) |
| 619 | add_executable (signalhandler_unittest |
| 620 | src/signalhandler_unittest.cc |
| 621 | ) |
| 622 | |
| 623 | target_link_libraries (signalhandler_unittest PRIVATE glog) |
| 624 | endif (HAVE_STACKTRACE AND HAVE_SYMBOLIZE) |
| 625 | |
| 626 | add_test (NAME demangle COMMAND demangle_unittest) |
| 627 | add_test (NAME logging COMMAND logging_unittest) |
| 628 | |
| 629 | if (TARGET signalhandler_unittest) |
| 630 | add_test (NAME signalhandler COMMAND signalhandler_unittest) |
| 631 | endif (TARGET signalhandler_unittest) |
| 632 | |
| 633 | if (TARGET stacktrace_unittest) |
| 634 | add_test (NAME stacktrace COMMAND stacktrace_unittest) |
| 635 | set_tests_properties(stacktrace PROPERTIES TIMEOUT 30) |
| 636 | endif (TARGET stacktrace_unittest) |
| 637 | |
| 638 | add_test (NAME stl_logging COMMAND stl_logging_unittest) |
| 639 | |
| 640 | if (TARGET symbolize_unittest) |
| 641 | add_test (NAME symbolize COMMAND symbolize_unittest) |
| 642 | endif (TARGET symbolize_unittest) |
| 643 | endif (BUILD_TESTING) |
| 644 | |
| 645 | install (TARGETS glog |
| 646 | EXPORT glog-targets |
| 647 | RUNTIME DESTINATION ${_glog_CMake_BINDIR} |
| 648 | PUBLIC_HEADER DESTINATION ${_glog_CMake_INCLUDE_DIR}/glog |
| 649 | LIBRARY DESTINATION ${_glog_CMake_LIBDIR} |
| 650 | ARCHIVE DESTINATION ${_glog_CMake_LIBDIR}) |
| 651 | |
| 652 | set (glog_CMake_VERSION 3.0) |
| 653 | |
| 654 | if (gflags_FOUND) |
| 655 | # Ensure clients locate only the package config and not third party find |
| 656 | # modules having the same name. This avoid cmake_policy PUSH/POP errors. |
| 657 | if (CMAKE_VERSION VERSION_LESS 3.9) |
| 658 | set (gflags_DEPENDENCY "find_dependency (gflags ${gflags_VERSION})") |
| 659 | else (CMAKE_VERSION VERSION_LESS 3.9) |
| 660 | # Passing additional find_package arguments to find_dependency is possible |
| 661 | # starting with CMake 3.9. |
| 662 | set (glog_CMake_VERSION 3.9) |
| 663 | set (gflags_DEPENDENCY "find_dependency (gflags ${gflags_VERSION} NO_MODULE)") |
| 664 | endif (CMAKE_VERSION VERSION_LESS 3.9) |
| 665 | endif (gflags_FOUND) |
| 666 | |
| 667 | configure_package_config_file (glog-config.cmake.in |
| 668 | ${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake |
| 669 | INSTALL_DESTINATION ${_glog_CMake_INSTALLDIR} |
| 670 | NO_CHECK_REQUIRED_COMPONENTS_MACRO) |
| 671 | |
| 672 | write_basic_package_version_file (glog-config-version.cmake VERSION |
| 673 | ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion) |
| 674 | |
| 675 | export (TARGETS glog NAMESPACE glog:: FILE glog-targets.cmake) |
| 676 | export (PACKAGE glog) |
| 677 | |
| 678 | install (FILES |
| 679 | ${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake |
| 680 | ${CMAKE_CURRENT_BINARY_DIR}/glog-config-version.cmake |
| 681 | DESTINATION ${_glog_CMake_INSTALLDIR}) |
| 682 | |
| 683 | install (EXPORT glog-targets NAMESPACE glog:: DESTINATION |
| 684 | ${_glog_CMake_INSTALLDIR}) |