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