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