Skip to content

Commit 9a43cfb

Browse files
committed
install unwind find module alongside glog
1 parent 19570c6 commit 9a43cfb

File tree

4 files changed

+120
-20
lines changed

4 files changed

+120
-20
lines changed

CMakeLists.txt

Lines changed: 98 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ option (WITH_TLS "Enable Thread Local Storage (TLS) support" ON)
2323
option (BUILD_SHARED_LIBS "Build shared libraries" OFF)
2424
option (PRINT_UNSYMBOLIZED_STACK_TRACES
2525
"Print raw pc values on symbolization failure" OFF)
26-
option (WITH_PKGCONFIG " Enable pkg-config support" ON)
26+
option (WITH_PKGCONFIG "Enable pkg-config support" ON)
27+
option (WITH_UNWIND "Enable libunwind support" ON)
28+
29+
if (NOT WITH_UNWIND)
30+
set (CMAKE_DISABLE_FIND_PACKAGE_Unwind ON)
31+
endif (NOT WITH_UNWIND)
32+
33+
if (NOT WITH_THREADS)
34+
set (CMAKE_DISABLE_FIND_PACKAGE_Threads ON)
35+
endif (NOT WITH_THREADS)
2736

2837
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
2938

@@ -57,9 +66,13 @@ if (WITH_GFLAGS)
5766
endif (gflags_FOUND)
5867
endif (WITH_GFLAGS)
5968

60-
if (WITH_THREADS)
61-
find_package (Threads)
62-
endif (WITH_THREADS)
69+
find_package (Threads)
70+
find_package (Unwind)
71+
72+
if (Unwind_FOUND)
73+
set (HAVE_LIB_UNWIND 1)
74+
set (HAVE_UNWIND_H 1)
75+
endif (Unwind_FOUND)
6376

6477
check_include_file (dlfcn.h HAVE_DLFCN_H)
6578
check_include_file (execinfo.h HAVE_EXECINFO_H)
@@ -117,8 +130,6 @@ check_symbol_exists (snprintf stdio.h HAVE_SNPRINTF)
117130

118131
check_library_exists (dbghelp UnDecorateSymbolName "" HAVE_DBGHELP)
119132

120-
find_package (Unwind)
121-
122133
check_c_source_compiles ("
123134
#include <stdlib.h>
124135
static void foo(void) __attribute__ ((unused));
@@ -480,16 +491,57 @@ endif (WIN32)
480491

481492
add_compile_options ($<$<AND:$<BOOL:${HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS}>,$<NOT:$<CXX_COMPILER_ID:GNU>>>:-Wno-unnamed-type-template-args>)
482493

494+
set (_glog_CMake_BINDIR ${CMAKE_INSTALL_BINDIR})
495+
set (_glog_CMake_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR})
496+
set (_glog_CMake_LIBDIR ${CMAKE_INSTALL_LIBDIR})
497+
set (_glog_CMake_INSTALLDIR ${_glog_CMake_LIBDIR}/cmake/glog)
498+
499+
set (_glog_CMake_DIR glog/cmake)
500+
set (_glog_CMake_DATADIR ${CMAKE_INSTALL_DATAROOTDIR}/${_glog_CMake_DIR})
501+
set (_glog_BINARY_CMake_DATADIR
502+
${CMAKE_CURRENT_BINARY_DIR}/${_glog_CMake_DATADIR})
503+
504+
# Add additional CMake find modules here.
505+
set (_glog_CMake_MODULES)
506+
507+
if (Unwind_FOUND)
508+
# Copy the module only if libunwind is actually used.
509+
list (APPEND _glog_CMake_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindUnwind.cmake)
510+
endif (Unwind_FOUND)
511+
512+
# Generate file name for each module in the binary directory
513+
foreach (_file ${_glog_CMake_MODULES})
514+
get_filename_component (_module "${_file}" NAME)
515+
516+
list (APPEND _glog_BINARY_CMake_MODULES
517+
${_glog_BINARY_CMake_DATADIR}/${_module})
518+
endforeach (_file)
519+
520+
if (_glog_CMake_MODULES)
521+
# Copy modules to binary directory during the build
522+
add_custom_command (OUTPUT ${_glog_BINARY_CMake_MODULES}
523+
COMMAND ${CMAKE_COMMAND} -E make_directory
524+
${_glog_BINARY_CMake_DATADIR}
525+
COMMAND ${CMAKE_COMMAND} -E copy ${_glog_CMake_MODULES}
526+
${_glog_BINARY_CMake_DATADIR}
527+
DEPENDS ${_glog_CMake_MODULES}
528+
COMMENT "Copying find modules..."
529+
)
530+
endif (_glog_CMake_MODULES)
531+
483532
add_library (glog
484533
${GLOG_SRCS}
534+
${_glog_BINARY_CMake_MODULES}
485535
)
536+
486537
add_library(glog::glog ALIAS glog)
487538

488539
set_target_properties (glog PROPERTIES POSITION_INDEPENDENT_CODE ON)
489540

490-
if (Libunwind_FOUND)
491-
target_link_libraries (glog PUBLIC unwind)
492-
endif (Libunwind_FOUND)
541+
if (Unwind_FOUND)
542+
target_link_libraries (glog PUBLIC unwind::unwind)
543+
set (Unwind_DEPENDENCY "find_dependency (Unwind ${Unwind_VERSION})")
544+
endif (Unwind_FOUND)
493545

494546
if (HAVE_DBGHELP)
495547
target_link_libraries (glog PUBLIC dbghelp)
@@ -522,11 +574,6 @@ endif (WIN32)
522574

523575
set_target_properties (glog PROPERTIES PUBLIC_HEADER "${GLOG_PUBLIC_H}")
524576

525-
set (_glog_CMake_BINDIR ${CMAKE_INSTALL_BINDIR})
526-
set (_glog_CMake_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR})
527-
set (_glog_CMake_LIBDIR ${CMAKE_INSTALL_LIBDIR})
528-
set (_glog_CMake_INSTALLDIR ${_glog_CMake_LIBDIR}/cmake/glog)
529-
530577
target_include_directories (glog BEFORE PUBLIC
531578
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
532579
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
@@ -698,11 +745,47 @@ write_basic_package_version_file (glog-config-version.cmake VERSION
698745
export (TARGETS glog NAMESPACE glog:: FILE glog-targets.cmake)
699746
export (PACKAGE glog)
700747

748+
get_filename_component (_PREFIX "${CMAKE_INSTALL_PREFIX}" ABSOLUTE)
749+
750+
# Directory containing the find modules relative to the config install
751+
# directory.
752+
file (RELATIVE_PATH glog_REL_CMake_MODULES
753+
${_PREFIX}/${_glog_CMake_INSTALLDIR}
754+
${_PREFIX}/${_glog_CMake_DATADIR}/glog-modules.cmake)
755+
756+
get_filename_component (glog_REL_CMake_DATADIR ${glog_REL_CMake_MODULES}
757+
DIRECTORY)
758+
759+
set (glog_FULL_CMake_DATADIR
760+
${CMAKE_CURRENT_BINARY_DIR}/${_glog_CMake_DATADIR})
761+
762+
configure_file (glog-modules.cmake.in
763+
${CMAKE_CURRENT_BINARY_DIR}/glog-modules.cmake @ONLY)
764+
765+
install (CODE
766+
"
767+
set (glog_FULL_CMake_DATADIR \"\\\${CMAKE_CURRENT_LIST_DIR}/${glog_REL_CMake_DATADIR}\")
768+
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/glog-modules.cmake.in
769+
\"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/glog-modules.cmake\" @ONLY)
770+
file (INSTALL
771+
\"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/glog-modules.cmake\"
772+
DESTINATION
773+
\"\${CMAKE_INSTALL_PREFIX}/${_glog_CMake_INSTALLDIR}\")
774+
"
775+
COMPONENT Development
776+
)
777+
701778
install (FILES
702779
${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake
703780
${CMAKE_CURRENT_BINARY_DIR}/glog-config-version.cmake
704-
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindLibunwind.cmake
705781
DESTINATION ${_glog_CMake_INSTALLDIR})
706782

783+
# Find modules in share/glog/cmake
784+
install (DIRECTORY ${_glog_BINARY_CMake_DATADIR}
785+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/glog
786+
COMPONENT Development
787+
FILES_MATCHING PATTERN "*.cmake"
788+
)
789+
707790
install (EXPORT glog-targets NAMESPACE glog:: DESTINATION
708791
${_glog_CMake_INSTALLDIR})

glog-config.cmake.in

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ endif (CMAKE_VERSION VERSION_LESS @glog_CMake_VERSION@)
55
@PACKAGE_INIT@
66

77
include (CMakeFindDependencyMacro)
8+
include (${CMAKE_CURRENT_LIST_DIR}/glog-modules.cmake)
89

910
@gflags_DEPENDENCY@
11+
@Unwind_DEPENDENCY@
1012

11-
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
12-
find_dependency (Libunwind)
13-
14-
include ("${CMAKE_CURRENT_LIST_DIR}/glog-targets.cmake")
13+
include (${CMAKE_CURRENT_LIST_DIR}/glog-targets.cmake)

glog-modules.cmake.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cmake_policy (PUSH)
2+
cmake_policy (SET CMP0057 NEW)
3+
4+
if (CMAKE_VERSION VERSION_LESS 3.3)
5+
message (FATAL_ERROR "glog-modules.cmake requires the consumer "
6+
"to use CMake 3.3 (or newer)")
7+
endif (CMAKE_VERSION VERSION_LESS 3.3)
8+
9+
set (glog_MODULE_PATH "@glog_FULL_CMake_DATADIR@")
10+
list (APPEND CMAKE_MODULE_PATH ${glog_MODULE_PATH})
11+
12+
if (NOT glog_MODULE_PATH IN_LIST CMAKE_MODULE_PATH)
13+
message (FATAL_ERROR "Cannot add '${glog_MODULE_PATH}' to "
14+
"CMAKE_MODULE_PATH. This will cause glog-config.cmake to fail at "
15+
"locating required find modules. Make sure CMAKE_MODULE_PATH is not a cache variable.")
16+
endif (NOT glog_MODULE_PATH IN_LIST CMAKE_MODULE_PATH)
17+
18+
cmake_policy (POP)

src/stacktrace_windows-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#include "config.h"
3535
#include "port.h"
3636
#include "stacktrace.h"
37-
#include <DbgHelp.h>
37+
#include <dbghelp.h>
3838

3939
_START_GOOGLE_NAMESPACE_
4040

0 commit comments

Comments
 (0)