Unverified Commit 1863b422 authored by Sergiu Deitsch's avatar Sergiu Deitsch Committed by GitHub

Merge pull request #368 from UVV-gh/cmake-sdk-fix

Use libunwind as an imported target
parents 58d7f873 c0463b17
/*.cmake
/*.filters
/*.sln
/*.vcxproj
autom4te.cache
glog-*.tar.gz
packages/rpm-unknown
packages/debian-*
bazel-*
CMakeCache.txt
CMakeFiles/
*.cmake
config.h
*.sln
*.vcxproj
*.filters
bazel-*
glog-*.tar.gz
packages/debian-*
packages/rpm-unknown
......@@ -23,7 +23,16 @@ option (WITH_TLS "Enable Thread Local Storage (TLS) support" ON)
option (BUILD_SHARED_LIBS "Build shared libraries" OFF)
option (PRINT_UNSYMBOLIZED_STACK_TRACES
"Print raw pc values on symbolization failure" OFF)
option (WITH_PKGCONFIG " Enable pkg-config support" ON)
option (WITH_PKGCONFIG "Enable pkg-config support" ON)
option (WITH_UNWIND "Enable libunwind support" ON)
if (NOT WITH_UNWIND)
set (CMAKE_DISABLE_FIND_PACKAGE_Unwind ON)
endif (NOT WITH_UNWIND)
if (NOT WITH_THREADS)
set (CMAKE_DISABLE_FIND_PACKAGE_Threads ON)
endif (NOT WITH_THREADS)
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
......@@ -43,6 +52,7 @@ include (CMakePushCheckState)
include (CPack)
include (CTest)
include (DetermineGflagsNamespace)
include (GetCacheVariables)
include (GNUInstallDirs)
set (CMAKE_DEBUG_POSTFIX d)
......@@ -57,15 +67,18 @@ if (WITH_GFLAGS)
endif (gflags_FOUND)
endif (WITH_GFLAGS)
if (WITH_THREADS)
find_package (Threads)
endif (WITH_THREADS)
find_package (Threads)
find_package (Unwind)
if (Unwind_FOUND)
set (HAVE_LIB_UNWIND 1)
set (HAVE_UNWIND_H 1)
endif (Unwind_FOUND)
check_include_file (dlfcn.h HAVE_DLFCN_H)
check_include_file (execinfo.h HAVE_EXECINFO_H)
check_include_file (glob.h HAVE_GLOB_H)
check_include_file (inttypes.h HAVE_INTTYPES_H)
check_include_file (libunwind.h HAVE_LIBUNWIND_H)
check_include_file (memory.h HAVE_MEMORY_H)
check_include_file (pwd.h HAVE_PWD_H)
check_include_file (stdint.h HAVE_STDINT_H)
......@@ -82,7 +95,6 @@ check_include_file (syscall.h HAVE_SYSCALL_H)
check_include_file (syslog.h HAVE_SYSLOG_H)
check_include_file (ucontext.h HAVE_UCONTEXT_H)
check_include_file (unistd.h HAVE_UNISTD_H)
check_include_file (unwind.h HAVE_UNWIND_H)
check_include_file (pwd.h HAVE_PWD_H)
check_include_file_cxx ("ext/hash_map" HAVE_EXT_HASH_MAP)
......@@ -118,12 +130,8 @@ check_cxx_compiler_flag (-Wunnamed-type-template-args
# snprintf as an inline function
check_symbol_exists (snprintf stdio.h HAVE_SNPRINTF)
check_library_exists (unwind get_static_proc_name "" HAVE_LIB_UNWIND)
check_library_exists (dbghelp UnDecorateSymbolName "" HAVE_DBGHELP)
find_library (UNWIND_LIBRARY NAMES unwind DOC "unwind library")
mark_as_advanced (UNWIND_LIBRARY)
check_c_source_compiles ("
#include <stdlib.h>
static void foo(void) __attribute__ ((unused));
......@@ -485,16 +493,57 @@ endif (WIN32)
add_compile_options ($<$<AND:$<BOOL:${HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS}>,$<NOT:$<CXX_COMPILER_ID:GNU>>>:-Wno-unnamed-type-template-args>)
set (_glog_CMake_BINDIR ${CMAKE_INSTALL_BINDIR})
set (_glog_CMake_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR})
set (_glog_CMake_LIBDIR ${CMAKE_INSTALL_LIBDIR})
set (_glog_CMake_INSTALLDIR ${_glog_CMake_LIBDIR}/cmake/glog)
set (_glog_CMake_DIR glog/cmake)
set (_glog_CMake_DATADIR ${CMAKE_INSTALL_DATAROOTDIR}/${_glog_CMake_DIR})
set (_glog_BINARY_CMake_DATADIR
${CMAKE_CURRENT_BINARY_DIR}/${_glog_CMake_DATADIR})
# Add additional CMake find modules here.
set (_glog_CMake_MODULES)
if (Unwind_FOUND)
# Copy the module only if libunwind is actually used.
list (APPEND _glog_CMake_MODULES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindUnwind.cmake)
endif (Unwind_FOUND)
# Generate file name for each module in the binary directory
foreach (_file ${_glog_CMake_MODULES})
get_filename_component (_module "${_file}" NAME)
list (APPEND _glog_BINARY_CMake_MODULES
${_glog_BINARY_CMake_DATADIR}/${_module})
endforeach (_file)
if (_glog_CMake_MODULES)
# Copy modules to binary directory during the build
add_custom_command (OUTPUT ${_glog_BINARY_CMake_MODULES}
COMMAND ${CMAKE_COMMAND} -E make_directory
${_glog_BINARY_CMake_DATADIR}
COMMAND ${CMAKE_COMMAND} -E copy ${_glog_CMake_MODULES}
${_glog_BINARY_CMake_DATADIR}
DEPENDS ${_glog_CMake_MODULES}
COMMENT "Copying find modules..."
)
endif (_glog_CMake_MODULES)
add_library (glog
${GLOG_SRCS}
${_glog_BINARY_CMake_MODULES}
)
add_library(glog::glog ALIAS glog)
set_target_properties (glog PROPERTIES POSITION_INDEPENDENT_CODE ON)
if (UNWIND_LIBRARY)
target_link_libraries (glog PUBLIC ${UNWIND_LIBRARY})
endif (UNWIND_LIBRARY)
if (Unwind_FOUND)
target_link_libraries (glog PUBLIC unwind::unwind)
set (Unwind_DEPENDENCY "find_dependency (Unwind ${Unwind_VERSION})")
endif (Unwind_FOUND)
if (HAVE_DBGHELP)
target_link_libraries (glog PUBLIC dbghelp)
......@@ -527,11 +576,6 @@ endif (WIN32)
set_target_properties (glog PROPERTIES PUBLIC_HEADER "${GLOG_PUBLIC_H}")
set (_glog_CMake_BINDIR ${CMAKE_INSTALL_BINDIR})
set (_glog_CMake_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR})
set (_glog_CMake_LIBDIR ${CMAKE_INSTALL_LIBDIR})
set (_glog_CMake_INSTALLDIR ${_glog_CMake_LIBDIR}/cmake/glog)
target_include_directories (glog BEFORE PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
......@@ -661,6 +705,57 @@ if (BUILD_TESTING)
if (TARGET symbolize_unittest)
add_test (NAME symbolize COMMAND symbolize_unittest)
endif (TARGET symbolize_unittest)
# Generate an initial cache
get_cache_variables (_CACHEVARS EXCLUDE CMAKE_MAKE_PROGRAM)
set (_INITIAL_CACHE
${CMAKE_CURRENT_BINARY_DIR}/test_package_config/glog_package_config_initial_cache.cmake)
# Package config test
add_test (NAME cmake_package_config_init COMMAND ${CMAKE_COMMAND}
-DTEST_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/test_package_config
-DINITIAL_CACHE=${_INITIAL_CACHE}
-DCACHEVARS=${_CACHEVARS}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestInitPackageConfig.cmake
)
add_test (NAME cmake_package_config_generate COMMAND ${CMAKE_COMMAND}
-DPATH=$ENV{PATH}
-DINITIAL_CACHE=${_INITIAL_CACHE}
-DTEST_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/test_package_config/working_config
-DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/src/package_config_unittest/working_config
-DPACKAGE_DIR=${CMAKE_CURRENT_BINARY_DIR}
-DGENERATOR=${CMAKE_GENERATOR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestPackageConfig.cmake
)
add_test (NAME cmake_package_config_build COMMAND
${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/test_package_config/working_config
)
add_test (NAME cmake_package_config_cleanup COMMAND ${CMAKE_COMMAND} -E
remove_directory
${CMAKE_CURRENT_BINARY_DIR}/test_package_config
)
# Fixtures setup
set_tests_properties (cmake_package_config_init PROPERTIES FIXTURES_SETUP
cmake_package_config)
set_tests_properties (cmake_package_config_generate PROPERTIES FIXTURES_SETUP
cmake_package_config_working)
# Fixtures cleanup
set_tests_properties (cmake_package_config_cleanup PROPERTIES FIXTURES_CLEANUP
cmake_package_config)
# Fixture requirements
set_tests_properties (cmake_package_config_generate PROPERTIES
FIXTURES_REQUIRED cmake_package_config)
set_tests_properties (cmake_package_config_build PROPERTIES
FIXTURES_REQUIRED "cmake_package_config;cmake_package_config_working")
endif (BUILD_TESTING)
install (TARGETS glog
......@@ -703,10 +798,47 @@ write_basic_package_version_file (glog-config-version.cmake VERSION
export (TARGETS glog NAMESPACE glog:: FILE glog-targets.cmake)
export (PACKAGE glog)
get_filename_component (_PREFIX "${CMAKE_INSTALL_PREFIX}" ABSOLUTE)
# Directory containing the find modules relative to the config install
# directory.
file (RELATIVE_PATH glog_REL_CMake_MODULES
${_PREFIX}/${_glog_CMake_INSTALLDIR}
${_PREFIX}/${_glog_CMake_DATADIR}/glog-modules.cmake)
get_filename_component (glog_REL_CMake_DATADIR ${glog_REL_CMake_MODULES}
DIRECTORY)
set (glog_FULL_CMake_DATADIR
${CMAKE_CURRENT_BINARY_DIR}/${_glog_CMake_DATADIR})
configure_file (glog-modules.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/glog-modules.cmake @ONLY)
install (CODE
"
set (glog_FULL_CMake_DATADIR \"\\\${CMAKE_CURRENT_LIST_DIR}/${glog_REL_CMake_DATADIR}\")
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/glog-modules.cmake.in
\"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/glog-modules.cmake\" @ONLY)
file (INSTALL
\"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/glog-modules.cmake\"
DESTINATION
\"\${CMAKE_INSTALL_PREFIX}/${_glog_CMake_INSTALLDIR}\")
"
COMPONENT Development
)
install (FILES
${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/glog-config-version.cmake
DESTINATION ${_glog_CMake_INSTALLDIR})
# Find modules in share/glog/cmake
install (DIRECTORY ${_glog_BINARY_CMake_DATADIR}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/glog
COMPONENT Development
FILES_MATCHING PATTERN "*.cmake"
)
install (EXPORT glog-targets NAMESPACE glog:: DESTINATION
${_glog_CMake_INSTALLDIR})
# - Try to find libunwind
# Once done this will define
#
# Unwind_FOUND - system has libunwind
# unwind::unwind - cmake target for libunwind
include (FindPackageHandleStandardArgs)
find_path (Unwind_INCLUDE_DIR NAMES unwind.h libunwind.h DOC "unwind include directory")
find_library (Unwind_LIBRARY NAMES unwind DOC "unwind library")
if (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
set (Unwind_ARCH "arm")
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64")
set (Unwind_ARCH "aarch64")
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR
CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64" OR
CMAKE_SYSTEM_PROCESSOR STREQUAL "corei7-64")
set (Unwind_ARCH "x86_64")
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
set (Unwind_ARCH "x86")
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^ppc64")
set (Unwind_ARCH "ppc64")
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^ppc")
set (Unwind_ARCH "ppc32")
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
set (Unwind_ARCH "mips")
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^hppa")
set (Unwind_ARCH "hppa")
elseif (CMAKE_SYSTEM_PROCESSOR MATCHES "^ia64")
set (Unwind_ARCH "ia64")
endif (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
find_library (Unwind_PLATFORM_LIBRARY NAMES "unwind-${Unwind_ARCH}"
DOC "unwind library platform")
mark_as_advanced (Unwind_INCLUDE_DIR Unwind_LIBRARY Unwind_PLATFORM_LIBRARY)
# Extract version information
if (Unwind_LIBRARY)
set (_Unwind_VERSION_HEADER ${Unwind_INCLUDE_DIR}/libunwind-common.h)
if (EXISTS ${_Unwind_VERSION_HEADER})
FILE (READ ${_Unwind_VERSION_HEADER} _Unwind_VERSION_CONTENTS)
string (REGEX REPLACE ".*#define UNW_VERSION_MAJOR[ \t]+([0-9]+).*" "\\1"
Unwind_VERSION_MAJOR "${_Unwind_VERSION_CONTENTS}")
string (REGEX REPLACE ".*#define UNW_VERSION_MINOR[ \t]+([0-9]+).*" "\\1"
Unwind_VERSION_MINOR "${_Unwind_VERSION_CONTENTS}")
string (REGEX REPLACE ".*#define UNW_VERSION_EXTRA[ \t]+([0-9]+).*" "\\1"
Unwind_VERSION_PATCH "${_Unwind_VERSION_CONTENTS}")
set (Unwind_VERSION
${Unwind_VERSION_MAJOR}.${Unwind_VERSION_MINOR}.${Unwind_VERSION_PATCH})
set (Unwind_VERSION_COMPONENTS 3)
endif (EXISTS ${_Unwind_VERSION_HEADER})
endif (Unwind_LIBRARY)
# handle the QUIETLY and REQUIRED arguments and set Unwind_FOUND to TRUE
# if all listed variables are TRUE
find_package_handle_standard_args (Unwind REQUIRED_VARS Unwind_INCLUDE_DIR
Unwind_LIBRARY Unwind_PLATFORM_LIBRARY VERSION_VAR Unwind_VERSION)
if (Unwind_FOUND)
add_library (unwind::unwind INTERFACE IMPORTED)
set_property (TARGET unwind::unwind PROPERTY
INTERFACE_INCLUDE_DIRECTORIES ${Unwind_INCLUDE_DIR}
)
set_property (TARGET unwind::unwind PROPERTY
INTERFACE_LINK_LIBRARIES ${Unwind_LIBRARY} ${Unwind_PLATFORM_LIBRARY}
)
set_property (TARGET unwind::unwind PROPERTY
IMPORTED_CONFIGURATIONS RELEASE
)
endif (Unwind_FOUND)
cmake_policy (PUSH)
cmake_policy (VERSION 3.3)
include (CMakeParseArguments)
function (get_cache_variables _CACHEVARS)
set (_SINGLE)
set (_MULTI EXCLUDE)
set (_OPTIONS)
cmake_parse_arguments (_ARGS "${_OPTIONS}" "${_SINGLE}" "${_MULTI}" ${ARGS} ${ARGN})
get_cmake_property (_VARIABLES VARIABLES)
set (CACHEVARS)
foreach (_VAR ${_VARIABLES})
if (DEFINED _ARGS_EXCLUDE)
if ("${_VAR}" IN_LIST _ARGS_EXCLUDE)
continue ()
endif ("${_VAR}" IN_LIST _ARGS_EXCLUDE)
endif (DEFINED _ARGS_EXCLUDE)
get_property (_CACHEVARTYPE CACHE ${_VAR} PROPERTY TYPE)
if ("${_CACHEVARTYPE}" STREQUAL INTERNAL OR
"${_CACHEVARTYPE}" STREQUAL STATIC OR
"${_CACHEVARTYPE}" STREQUAL UNINITIALIZED)
continue ()
endif ("${_CACHEVARTYPE}" STREQUAL INTERNAL OR
"${_CACHEVARTYPE}" STREQUAL STATIC OR
"${_CACHEVARTYPE}" STREQUAL UNINITIALIZED)
get_property (_CACHEVARVAL CACHE ${_VAR} PROPERTY VALUE)
if ("${_CACHEVARVAL}" STREQUAL "")
continue ()
endif ("${_CACHEVARVAL}" STREQUAL "")
get_property (_CACHEVARDOC CACHE ${_VAR} PROPERTY HELPSTRING)
# Escape " in values
string (REPLACE "\"" "\\\"" _CACHEVARVAL "${_CACHEVARVAL}")
# Escape " in help strings
string (REPLACE "\"" "\\\"" _CACHEVARDOC "${_CACHEVARDOC}")
# Escape ; in values
string (REPLACE ";" "\\\;" _CACHEVARVAL "${_CACHEVARVAL}")
# Escape backslash in values
string (REGEX REPLACE "\\\\([^\"])" "\\\\\\1" _CACHEVARVAL "${_CACHEVARVAL}")
if (NOT "${_CACHEVARTYPE}" STREQUAL BOOL)
set (_CACHEVARVAL "\"${_CACHEVARVAL}\"")
endif (NOT "${_CACHEVARTYPE}" STREQUAL BOOL)
if (NOT "${_CACHEVARTYPE}" STREQUAL "" AND NOT "${_CACHEVARVAL}" STREQUAL "")
set (CACHEVARS "${CACHEVARS}set (${_VAR} ${_CACHEVARVAL} CACHE ${_CACHEVARTYPE} \"${_CACHEVARDOC}\")\n")
endif (NOT "${_CACHEVARTYPE}" STREQUAL "" AND NOT "${_CACHEVARVAL}" STREQUAL "")
endforeach (_VAR)
set (${_CACHEVARS} ${CACHEVARS} PARENT_SCOPE)
endfunction (get_cache_variables)
cmake_policy (POP)
# Create the build directory
execute_process (
COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_BINARY_DIR}
RESULT_VARIABLE _DIRECTORY_CREATED_SUCCEEDED
)
if (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0)
message (FATAL_ERROR "Failed to create build directory")
endif (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0)
file (WRITE ${INITIAL_CACHE} "${CACHEVARS}")
# Create the build directory
execute_process (
COMMAND ${CMAKE_COMMAND} -E make_directory ${TEST_BINARY_DIR}
RESULT_VARIABLE _DIRECTORY_CREATED_SUCCEEDED
)
if (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0)
message (FATAL_ERROR "Failed to create build directory")
endif (NOT _DIRECTORY_CREATED_SUCCEEDED EQUAL 0)
# Capture the PATH environment variable content set during project
# generation stage. This is required because later during the build stage
# the PATH is modified again (e.g., for MinGW AppVeyor CI builds) by adding
# back the directory containing git.exe. Incidently, the Git installation
# directory also contains sh.exe which causes MinGW Makefile generation to
# fail.
set (ENV{PATH} ${PATH})
# Run CMake
execute_process (
COMMAND ${CMAKE_COMMAND} -C ${INITIAL_CACHE}
-G ${GENERATOR}
-DCMAKE_PREFIX_PATH=${PACKAGE_DIR}
-DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON
-DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON
${SOURCE_DIR}
WORKING_DIRECTORY ${TEST_BINARY_DIR}
RESULT_VARIABLE _GENERATE_SUCCEEDED
)
if (NOT _GENERATE_SUCCEEDED EQUAL 0)
message (FATAL_ERROR "Failed to generate project files using CMake")
endif (NOT _GENERATE_SUCCEEDED EQUAL 0)
......@@ -5,7 +5,9 @@ endif (CMAKE_VERSION VERSION_LESS @glog_CMake_VERSION@)
@PACKAGE_INIT@
include (CMakeFindDependencyMacro)
include (${CMAKE_CURRENT_LIST_DIR}/glog-modules.cmake)
@gflags_DEPENDENCY@
@Unwind_DEPENDENCY@
include ("${CMAKE_CURRENT_LIST_DIR}/glog-targets.cmake")
include (${CMAKE_CURRENT_LIST_DIR}/glog-targets.cmake)
cmake_policy (PUSH)
cmake_policy (SET CMP0057 NEW)
if (CMAKE_VERSION VERSION_LESS 3.3)
message (FATAL_ERROR "glog-modules.cmake requires the consumer "
"to use CMake 3.3 (or newer)")
endif (CMAKE_VERSION VERSION_LESS 3.3)
set (glog_MODULE_PATH "@glog_FULL_CMake_DATADIR@")
list (APPEND CMAKE_MODULE_PATH ${glog_MODULE_PATH})
if (NOT glog_MODULE_PATH IN_LIST CMAKE_MODULE_PATH)
message (FATAL_ERROR "Cannot add '${glog_MODULE_PATH}' to "
"CMAKE_MODULE_PATH. This will cause glog-config.cmake to fail at "
"locating required find modules. Make sure CMAKE_MODULE_PATH is not a cache variable.")
endif (NOT glog_MODULE_PATH IN_LIST CMAKE_MODULE_PATH)
cmake_policy (POP)
cmake_minimum_required (VERSION 3.1)
project (glog_package_config)
find_package (glog REQUIRED NO_MODULE)
add_executable (glog_package_config glog_package_config.cc)
target_link_libraries (glog_package_config PRIVATE glog::glog)
#include <glog/logging.h>
int main(int /*argc*/, char** argv)
{
google::InitGoogleLogging(argv[0]);
}
......@@ -34,7 +34,7 @@
#include "config.h"
#include "port.h"
#include "stacktrace.h"
#include <DbgHelp.h>
#include <dbghelp.h>
_START_GOOGLE_NAMESPACE_
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment