CMakeLists.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. cmake_minimum_required (VERSION 3.0)
  2. if (POLICY CMP0042)
  3. cmake_policy (SET CMP0042 NEW)
  4. endif (POLICY CMP0042)
  5. if (POLICY CMP0063)
  6. cmake_policy (SET CMP0063 NEW)
  7. endif (POLICY CMP0063)
  8. project (google-glog)
  9. enable_testing ()
  10. set (GLOG_MAJOR_VERSION 0)
  11. set (GLOG_MINOR_VERSION 3)
  12. set (GLOG_PATCH_VERSION 5)
  13. set (GLOG_VERSION
  14. ${GLOG_MAJOR_VERSION}.${GLOG_MINOR_VERSION}.${GLOG_PATCH_VERSION})
  15. set (CPACK_PACKAGE_NAME glog)
  16. set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "")
  17. set (CPACK_PACKAGE_VERSION_MAJOR ${GLOG_MAJOR_VERSION})
  18. set (CPACK_PACKAGE_VERSION_MINOR ${GLOG_MINOR_VERSION})
  19. set (CPACK_PACKAGE_VERSION_PATCH ${GLOG_PATCH_VERSION})
  20. set (CPACK_PACKAGE_VERSION ${GLOG_VERSION})
  21. option (WITH_GFLAGS "Use gflags" ON)
  22. option (WITH_THREADS "Enable multithreading support" ON)
  23. list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
  24. include (CheckCSourceCompiles)
  25. include (CheckCXXCompilerFlag)
  26. include (CheckCXXSourceCompiles)
  27. include (CheckFunctionExists)
  28. include (CheckIncludeFile)
  29. include (CheckIncludeFileCXX)
  30. include (CheckLibraryExists)
  31. include (CheckStructHasMember)
  32. include (CheckSymbolExists)
  33. include (CheckTypeSize)
  34. include (CMakePackageConfigHelpers)
  35. include (CPack)
  36. include (CTest)
  37. include (DetermineGflagsNamespace)
  38. set (CMAKE_THREAD_PREFER_PTHREAD 1)
  39. if (WITH_GFLAGS)
  40. find_package (gflags)
  41. if (gflags_FOUND)
  42. set (HAVE_LIB_GFLAGS 1)
  43. determine_gflags_namespace (gflags_NAMESPACE)
  44. endif (gflags_FOUND)
  45. endif (WITH_GFLAGS)
  46. if (WITH_THREADS)
  47. find_package (Threads)
  48. endif (WITH_THREADS)
  49. check_include_file (dlfcn.h HAVE_DLFCN_H)
  50. check_include_file (execinfo.h HAVE_EXECINFO_H)
  51. check_include_file (glob.h HAVE_GLOB_H)
  52. check_include_file (inttypes.h HAVE_INTTYPES_H)
  53. check_include_file (libunwind.h HAVE_LIBUNWIND_H)
  54. check_include_file (memory.h HAVE_MEMORY_H)
  55. check_include_file (pwd.h HAVE_PWD_H)
  56. check_include_file (stdint.h HAVE_STDINT_H)
  57. check_include_file (stdlib.h HAVE_STDLIB_H)
  58. check_include_file (string.h HAVE_STRING_H)
  59. check_include_file (strings.h HAVE_STRINGS_H)
  60. check_include_file (sys/stat.h HAVE_SYS_STAT_H)
  61. check_include_file (sys/syscall.h HAVE_SYS_SYSCALL_H)
  62. check_include_file (sys/time.h HAVE_SYS_TIME_H)
  63. check_include_file (sys/types.h HAVE_SYS_TYPES_H)
  64. check_include_file (sys/utsname.h HAVE_SYS_UTSNAME_H)
  65. check_include_file (syscall.h HAVE_SYSCALL_H)
  66. check_include_file (syslog.h HAVE_SYSLOG_H)
  67. check_include_file (ucontext.h HAVE_UCONTEXT_H)
  68. check_include_file (unistd.h HAVE_UNISTD_H)
  69. check_include_file (unwind.h HAVE_UNWIND_H)
  70. check_include_file_cxx ("ext/hash_map" HAVE_EXT_HASH_MAP)
  71. check_include_file_cxx ("ext/hash_set" HAVE_EXT_HASH_SET)
  72. check_include_file_cxx ("ext/slist" HAVE_EXT_SLIST)
  73. check_include_file_cxx ("tr1/unordered_map" HAVE_TR1_UNORDERED_MAP)
  74. check_include_file_cxx ("tr1/unordered_set" HAVE_TR1_UNORDERED_SET)
  75. check_include_file_cxx ("unordered_map" HAVE_UNORDERED_MAP)
  76. check_include_file_cxx ("unordered_set" HAVE_UNORDERED_SET)
  77. check_type_size ("unsigned __int16" HAVE___UINT16)
  78. check_type_size (u_int16_t HAVE_U_INT16_T)
  79. check_type_size (uint16_t HAVE_UINT16_T)
  80. check_function_exists (dladdr HAVE_DLADDR)
  81. check_function_exists (fcntl HAVE_FCNTL)
  82. check_function_exists (pread HAVE_PREAD)
  83. check_function_exists (pwrite HAVE_PWRITE)
  84. check_function_exists (sigaction HAVE_SIGACTION)
  85. check_function_exists (sigaltstack HAVE_SIGALSTACK)
  86. # NOTE gcc does not fail if you pass a non-existent -Wno-* option as an
  87. # argument. However, it will happily fail if you pass the corresponding -W*
  88. # option. So, we check whether options that disable warnings exist by testing
  89. # the availability of the corresponding option that enables the warning. This
  90. # eliminates the need to check for compiler for several (mainly Clang) options.
  91. check_cxx_compiler_flag (-Wdeprecated HAVE_NO_DEPRECATED)
  92. check_cxx_compiler_flag (-Wunnamed-type-template-args
  93. HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS)
  94. # NOTE: Cannot use check_function_exists here since >=vc-14.0 can define
  95. # snprintf as an inline function
  96. check_symbol_exists (snprintf stdio.h HAVE_SNPRINTF)
  97. check_library_exists (unwind get_static_proc_name "" HAVE_LIB_UNWIND)
  98. find_library (UNWIND_LIBRARY NAMES unwind DOC "unwind library")
  99. mark_as_advanced (UNWIND_LIBRARY)
  100. check_c_source_compiles ("
  101. #include <stdlib.h>
  102. static void foo(void) __attribute__ ((unused));
  103. int main(void) { return 0; }
  104. " HAVE___ATTRIBUTE__)
  105. check_c_source_compiles ("
  106. #include <stdlib.h>
  107. static void foo(void) __attribute__ ((visibility(\"default\")));
  108. int main(void) { return 0; }
  109. " HAVE___ATTRIBUTE__VISIBILITY_DEFAULT)
  110. check_c_source_compiles ("
  111. #include <stdlib.h>
  112. static void foo(void) __attribute__ ((visibility(\"hidden\")));
  113. int main(void) { return 0; }
  114. " HAVE___ATTRIBUTE__VISIBILITY_HIDDEN)
  115. check_c_source_compiles ("
  116. int main(void) { if (__builtin_expect(0, 0)) return 1; return 0; }
  117. " HAVE___BUILTIN_EXPECT)
  118. check_c_source_compiles ("
  119. int main(void)
  120. {
  121. int a; if (__sync_val_compare_and_swap(&a, 0, 1)) return 1; return 0;
  122. }
  123. " HAVE___SYNC_VAL_COMPARE_AND_SWAP)
  124. check_c_source_compiles ("
  125. #define _XOPEN_SOURCE 500
  126. #include <pthread.h>
  127. int main(void)
  128. {
  129. pthread_rwlock_t l;
  130. pthread_rwlock_init(&l, NULL);
  131. pthread_rwlock_rdlock(&l);
  132. return 0;
  133. }
  134. " HAVE_RWLOCK)
  135. check_c_source_compiles ("
  136. __declspec(selectany) int a;
  137. int main(void) { return 0; }
  138. " HAVE___DECLSPEC)
  139. check_cxx_source_compiles ("
  140. #include <vector>
  141. vector<int> t; int main() { }
  142. " STL_NO_NAMESPACE)
  143. check_cxx_source_compiles ("
  144. #include <vector>
  145. std::vector<int> t; int main() { }
  146. " STL_STD_NAMESPACE)
  147. check_cxx_source_compiles ("
  148. #include <iostream>
  149. std::ostream& operator<<(std::ostream&, struct s);
  150. using ::operator<<;
  151. int main() { }
  152. " HAVE_USING_OPERATOR)
  153. check_cxx_source_compiles ("
  154. namespace Outer { namespace Inner { int i = 0; }}
  155. using namespace Outer::Inner;;
  156. int main() { return i; }
  157. " HAVE_NAMESPACES)
  158. set (_PC_FIELDS
  159. "gregs[REG_PC]"
  160. "gregs[REG_EIP]"
  161. "gregs[REG_RIP]"
  162. "sc_ip"
  163. "uc_regs->gregs[PT_NIP]"
  164. "gregs[R15]"
  165. "arm_pc"
  166. "mc_eip"
  167. "mc_rip"
  168. "__gregs[REG_EIP]"
  169. "__gregs[REG_RIP]"
  170. "ss.eip"
  171. "__ss.__eip"
  172. "ss.rip"
  173. "__ss.__rip"
  174. "ss.srr0"
  175. "__ss.__srr0"
  176. )
  177. set (_PC_HEADERS ucontext.h signal.h)
  178. if (HAVE_UCONTEXT_H AND NOT PC_FROM_UCONTEXT)
  179. foreach (_PC_FIELD ${_PC_FIELDS})
  180. foreach (_PC_HEADER ${_PC_HEADERS})
  181. set (_TMP
  182. ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/uctfield.c)
  183. file (WRITE ${_TMP} "
  184. #define _GNU_SOURCE 1
  185. #include <${_PC_HEADER}>
  186. int main(void)
  187. {
  188. ucontext_t u;
  189. return u.${_PC_FIELD} == 0;
  190. }
  191. ")
  192. try_compile (HAVE_PC_FROM_UCONTEXT ${CMAKE_CURRENT_BINARY_DIR} ${_TMP}
  193. COMPILE_DEFINITIONS _GNU_SOURCE=1)
  194. if (HAVE_PC_FROM_UCONTEXT)
  195. set (PC_FROM_UCONTEXT ${_PC_FIELD} CACHE)
  196. endif (HAVE_PC_FROM_UCONTEXT)
  197. endforeach (_PC_HEADER)
  198. endforeach (_PC_FIELD)
  199. endif (HAVE_UCONTEXT_H AND NOT PC_FROM_UCONTEXT)
  200. if (STL_STD_NAMESPACE)
  201. set (STL_NAMESPACE std)
  202. else (STL_STD_NAMESPACE)
  203. set (STL_NAMESPACE "")
  204. endif (STL_STD_NAMESPACE)
  205. set (GOOGLE_NAMESPACE google)
  206. set (_START_GOOGLE_NAMESPACE_ "namespace ${GOOGLE_NAMESPACE} {")
  207. set (_END_GOOGLE_NAMESPACE_ "}")
  208. if (HAVE___UINT16)
  209. set (ac_cv_have___uint16 1)
  210. else (HAVE___UINT16)
  211. set (ac_cv_have___uint16 0)
  212. endif (HAVE___UINT16)
  213. if (HAVE_INTTYPES_H)
  214. set (ac_cv_have_inttypes_h 1)
  215. else (HAVE_INTTYPES_H)
  216. set (ac_cv_have_inttypes_h 0)
  217. endif (HAVE_INTTYPES_H)
  218. if (HAVE_LIB_GFLAGS)
  219. set (ac_cv_have_libgflags 1)
  220. else (HAVE_LIB_GFLAGS)
  221. set (ac_cv_have_libgflags 0)
  222. endif (HAVE_LIB_GFLAGS)
  223. if (HAVE_STDINT_H)
  224. set (ac_cv_have_stdint_h 1)
  225. else (HAVE_STDINT_H)
  226. set (ac_cv_have_stdint_h 0)
  227. endif (HAVE_STDINT_H)
  228. if (HAVE_SYS_TYPES_H)
  229. set (ac_cv_have_systypes_h 1)
  230. else (HAVE_SYS_TYPES_H)
  231. set (ac_cv_have_systypes_h 0)
  232. endif (HAVE_SYS_TYPES_H)
  233. if (HAVE_U_INT16_T)
  234. set (ac_cv_have_u_int16_t 1)
  235. else (HAVE_U_INT16_T)
  236. set (ac_cv_have_u_int16_t 0)
  237. endif (HAVE_U_INT16_T)
  238. if (HAVE_UINT16_T)
  239. set (ac_cv_have_uint16_t 1)
  240. else (HAVE_UINT16_T)
  241. set (ac_cv_have_uint16_t 0)
  242. endif (HAVE_UINT16_T)
  243. if (HAVE_UNISTD_H)
  244. set (ac_cv_have_unistd_h 1)
  245. else (HAVE_UNISTD_H)
  246. set (ac_cv_have_unistd_h 0)
  247. endif (HAVE_UNISTD_H)
  248. set (ac_google_namespace ${GOOGLE_NAMESPACE})
  249. set (ac_google_end_namespace ${_END_GOOGLE_NAMESPACE_})
  250. set (ac_google_start_namespace ${_START_GOOGLE_NAMESPACE_})
  251. if (HAVE___ATTRIBUTE__)
  252. set (ac_cv___attribute___noreturn "__attribute__((noreturn))")
  253. set (ac_cv___attribute___noinline "__attribute__((noinline))")
  254. elseif (HAVE___DECLSPEC)
  255. set (ac_cv___attribute___noreturn "__declspec(noreturn)")
  256. #set (ac_cv___attribute___noinline "__declspec(noinline)")
  257. endif (HAVE___ATTRIBUTE__)
  258. if (HAVE___BUILTIN_EXPECT)
  259. set (ac_cv_have___builtin_expect 1)
  260. else (HAVE___BUILTIN_EXPECT)
  261. set (ac_cv_have___builtin_expect 0)
  262. endif (HAVE___BUILTIN_EXPECT)
  263. if (HAVE_USING_OPERATOR)
  264. set (ac_cv_cxx_using_operator 1)
  265. else (HAVE_USING_OPERATOR)
  266. set (ac_cv_cxx_using_operator 0)
  267. endif (HAVE_USING_OPERATOR)
  268. set (SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
  269. if (WITH_THREADS AND Threads_FOUND)
  270. if (CMAKE_USE_PTHREADS_INIT)
  271. set (HAVE_PTHREAD 1)
  272. endif (CMAKE_USE_PTHREADS_INIT)
  273. else (WITH_THREADS AND Threads_FOUND)
  274. set (NO_THREADS 1)
  275. endif (WITH_THREADS AND Threads_FOUND)
  276. set (TEST_SRC_DIR \"${CMAKE_CURRENT_SOURCE_DIR}\")
  277. configure_file (src/config.h.cmake.in config.h)
  278. configure_file (src/glog/logging.h.in glog/logging.h @ONLY)
  279. configure_file (src/glog/raw_logging.h.in glog/raw_logging.h @ONLY)
  280. configure_file (src/glog/stl_logging.h.in glog/stl_logging.h @ONLY)
  281. configure_file (src/glog/vlog_is_on.h.in glog/vlog_is_on.h @ONLY)
  282. set (CMAKE_CXX_VISIBILITY_PRESET default)
  283. set (CMAKE_VISIBILITY_INLINES_HIDDEN 1)
  284. set (GLOG_PUBLIC_H
  285. ${CMAKE_CURRENT_BINARY_DIR}/config.h
  286. ${CMAKE_CURRENT_BINARY_DIR}/glog/logging.h
  287. ${CMAKE_CURRENT_BINARY_DIR}/glog/raw_logging.h
  288. ${CMAKE_CURRENT_BINARY_DIR}/glog/stl_logging.h
  289. ${CMAKE_CURRENT_BINARY_DIR}/glog/vlog_is_on.h
  290. src/glog/log_severity.h
  291. )
  292. set (GLOG_SRCS
  293. ${GLOG_PUBLIC_H}
  294. src/base/commandlineflags.h
  295. src/base/googleinit.h
  296. src/base/mutex.h
  297. src/demangle.cc
  298. src/demangle.h
  299. src/logging.cc
  300. src/raw_logging.cc
  301. src/symbolize.cc
  302. src/symbolize.h
  303. src/utilities.cc
  304. src/utilities.h
  305. src/vlog_is_on.cc
  306. )
  307. if (HAVE_PTHREAD)
  308. list (APPEND GLOG_SRCS src/signalhandler.cc)
  309. endif (HAVE_PTHREAD)
  310. if (WIN32)
  311. list (APPEND GLOG_SRCS
  312. src/windows/port.cc
  313. src/windows/port.h
  314. )
  315. endif (WIN32)
  316. add_compile_options ($<$<BOOL:${HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS}>:-Wno-unnamed-type-template-args>)
  317. add_library (glog
  318. ${GLOG_SRCS}
  319. )
  320. set_target_properties (glog PROPERTIES POSITION_INDEPENDENT_CODE ON)
  321. if (UNWIND_LIBRARY)
  322. target_link_libraries (glog PUBLIC ${UNWIND_LIBRARY})
  323. endif (UNWIND_LIBRARY)
  324. if (HAVE_PTHREAD)
  325. target_link_libraries (glog PUBLIC ${CMAKE_THREAD_LIBS_INIT})
  326. endif (HAVE_PTHREAD)
  327. if (WIN32 AND HAVE_SNPRINTF)
  328. set_property (SOURCE src/windows/port.cc APPEND PROPERTY COMPILE_DEFINITIONS
  329. HAVE_SNPRINTF)
  330. endif (WIN32 AND HAVE_SNPRINTF)
  331. if (gflags_FOUND)
  332. target_include_directories (glog PUBLIC $<BUILD_INTERFACE:${gflags_INCLUDE_DIR}>)
  333. target_link_libraries (glog PUBLIC ${gflags_LIBRARIES})
  334. if (NOT BUILD_SHARED_LIBS)
  335. # Don't use __declspec(dllexport|dllimport) if this is a static build
  336. targeT_compile_definitions (glog PUBLIC GFLAGS_DLL_DECLARE_FLAG= GFLAGS_DLL_DEFINE_FLAG=)
  337. endif (NOT BUILD_SHARED_LIBS)
  338. endif (gflags_FOUND)
  339. set_target_properties (glog PROPERTIES VERSION ${GLOG_MAJOR_VERSION})
  340. set_target_properties (glog PROPERTIES SOVERSION ${GLOG_VERSION})
  341. if (WIN32)
  342. target_compile_definitions (glog PUBLIC GLOG_NO_ABBREVIATED_SEVERITIES)
  343. endif (WIN32)
  344. set_target_properties (glog PROPERTIES PUBLIC_HEADER "${GLOG_PUBLIC_H}")
  345. target_include_directories (glog BEFORE PUBLIC
  346. "$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
  347. "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
  348. "$<INSTALL_INTERFACE:include>"
  349. PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
  350. PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
  351. if (WIN32)
  352. target_include_directories (glog PUBLIC
  353. "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/windows>"
  354. PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/windows)
  355. endif (WIN32)
  356. set_target_properties (glog PROPERTIES DEFINE_SYMBOL LIBGLOG_EXPORTS)
  357. if (NOT BUILD_SHARED_LIBS)
  358. target_compile_definitions (glog PUBLIC GOOGLE_GLOG_DLL_DECL=)
  359. else (NOT BUILD_SHARED_LIBS)
  360. target_compile_definitions (glog PRIVATE GOOGLE_GLOG_IS_A_DLL=1)
  361. if (HAVE___ATTRIBUTE__VISIBILITY_DEFAULT)
  362. set (_EXPORT "__attribute__((visibility(\"default\")))")
  363. set (_IMPORT "")
  364. elseif (HAVE___DECLSPEC)
  365. set (_EXPORT "__declspec(dllexport)")
  366. set (_IMPORT "__declspec(dllimport)")
  367. endif (HAVE___ATTRIBUTE__VISIBILITY_DEFAULT)
  368. target_compile_definitions (glog PRIVATE
  369. "GOOGLE_GLOG_DLL_DECL=${_EXPORT}")
  370. target_compile_definitions (glog INTERFACE
  371. "GOOGLE_GLOG_DLL_DECL=${_IMPORT}")
  372. target_compile_definitions (glog INTERFACE
  373. "GOOGLE_GLOG_DLL_DECL_FOR_UNITTESTS=${_IMPORT}")
  374. endif (NOT BUILD_SHARED_LIBS)
  375. if (HAVE_EXECINFO_H)
  376. set (HAVE_STACKTRACE 1)
  377. endif (HAVE_EXECINFO_H)
  378. if (UNIX OR (APPLE AND HAVE_DLADDR))
  379. set (HAVE_SYMBOLIZE 1)
  380. endif (UNIX OR (APPLE AND HAVE_DLADDR))
  381. # Unit testing
  382. if (BUILD_TESTING)
  383. add_executable (logging_unittest
  384. src/logging_unittest.cc
  385. )
  386. target_link_libraries (logging_unittest PRIVATE glog)
  387. add_executable (stl_logging_unittest
  388. src/stl_logging_unittest.cc
  389. )
  390. target_link_libraries (stl_logging_unittest PRIVATE glog)
  391. if (HAVE_NO_DEPRECATED)
  392. set_property (TARGET stl_logging_unittest APPEND PROPERTY COMPILE_OPTIONS
  393. -Wno-deprecated)
  394. endif (HAVE_NO_DEPRECATED)
  395. if (HAVE_UNORDERED_MAP AND HAVE_UNORDERED_SET)
  396. target_compile_definitions (stl_logging_unittest PRIVATE
  397. GLOG_STL_LOGGING_FOR_UNORDERED)
  398. endif (HAVE_UNORDERED_MAP AND HAVE_UNORDERED_SET)
  399. if (HAVE_TR1_UNORDERED_MAP AND HAVE_TR1_UNORDERED_SET)
  400. target_compile_definitions (stl_logging_unittest PRIVATE
  401. GLOG_STL_LOGGING_FOR_TR1_UNORDERED)
  402. endif (HAVE_TR1_UNORDERED_MAP AND HAVE_TR1_UNORDERED_SET)
  403. if (HAVE_EXT_HASH_MAP AND HAVE_EXT_HASH_SET)
  404. target_compile_definitions (stl_logging_unittest PRIVATE
  405. GLOG_STL_LOGGING_FOR_EXT_HASH)
  406. endif (HAVE_EXT_HASH_MAP AND HAVE_EXT_HASH_SET)
  407. if (HAVE_EXT_SLIST)
  408. target_compile_definitions (stl_logging_unittest PRIVATE
  409. GLOG_STL_LOGGING_FOR_EXT_SLIST)
  410. endif (HAVE_EXT_SLIST)
  411. if (HAVE_SYMBOLIZE)
  412. add_executable (symbolize_unittest
  413. src/symbolize_unittest.cc
  414. )
  415. target_link_libraries (symbolize_unittest PRIVATE glog)
  416. endif (HAVE_SYMBOLIZE)
  417. add_executable (demangle_unittest
  418. src/demangle_unittest.cc
  419. )
  420. target_link_libraries (demangle_unittest PRIVATE glog)
  421. if (HAVE_STACKTRACE)
  422. add_executable (stacktrace_unittest
  423. src/stacktrace_unittest.cc
  424. )
  425. target_link_libraries (stacktrace_unittest PRIVATE glog)
  426. endif (HAVE_STACKTRACE)
  427. add_executable (utilities_unittest
  428. src/utilities_unittest.cc
  429. )
  430. target_link_libraries (utilities_unittest PRIVATE glog)
  431. if (HAVE_STACKTRACE AND HAVE_SYMBOLIZE)
  432. add_executable (signalhandler_unittest
  433. src/signalhandler_unittest.cc
  434. )
  435. target_link_libraries (signalhandler_unittest PRIVATE glog)
  436. endif (HAVE_STACKTRACE AND HAVE_SYMBOLIZE)
  437. add_test (NAME demangle COMMAND demangle_unittest)
  438. add_test (NAME logging COMMAND logging_unittest)
  439. if (TARGET signalhandler_unittest)
  440. add_test (NAME signalhandler COMMAND signalhandler_unittest)
  441. endif (TARGET signalhandler_unittest)
  442. if (TARGET stacktrace_unittest)
  443. add_test (NAME stacktrace COMMAND stacktrace_unittest)
  444. endif (TARGET stacktrace_unittest)
  445. add_test (NAME stl_logging COMMAND stl_logging_unittest)
  446. if (TARGET symbolize_unittest)
  447. add_test (NAME symbolize COMMAND symbolize_unittest)
  448. endif (TARGET symbolize_unittest)
  449. endif (BUILD_TESTING)
  450. install (TARGETS glog
  451. EXPORT glog-targets
  452. RUNTIME DESTINATION bin
  453. PUBLIC_HEADER DESTINATION include/glog
  454. LIBRARY DESTINATION lib
  455. ARCHIVE DESTINATION lib)
  456. if (gflags_FOUND)
  457. set (gflags_DEPENDENCY "find_dependency (gflags ${gflags_VERSION})")
  458. endif (gflags_FOUND)
  459. configure_package_config_file (glog-config.cmake.in
  460. ${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake
  461. INSTALL_DESTINATION lib/cmake/glog
  462. NO_CHECK_REQUIRED_COMPONENTS_MACRO)
  463. write_basic_package_version_file (glog-config-version.cmake VERSION
  464. ${GLOG_VERSION} COMPATIBILITY SameMajorVersion)
  465. export (TARGETS glog NAMESPACE glog:: FILE glog-targets.cmake)
  466. export (PACKAGE glog)
  467. install (FILES
  468. ${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake
  469. ${CMAKE_CURRENT_BINARY_DIR}/glog-config-version.cmake
  470. DESTINATION lib/cmake/glog)
  471. install (EXPORT glog-targets NAMESPACE glog:: DESTINATION lib/cmake/glog)