cmake_policy (SET CMP0042 NEW)
endif (POLICY CMP0042)
+if (POLICY CMP0063)
+ cmake_policy (SET CMP0063 NEW)
+endif (POLICY CMP0063)
+
project (google-glog)
enable_testing ()
set (CPACK_PACKAGE_VERSION ${GLOG_VERSION})
option (WITH_GFLAGS "Use gflags" ON)
+option (WITH_THREADS "Enable multithreading support" ON)
list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
endif (gflags_FOUND)
endif (WITH_GFLAGS)
-find_package (Threads)
+if (WITH_THREADS)
+ find_package (Threads)
+endif (WITH_THREADS)
check_include_file (dlfcn.h HAVE_DLFCN_H)
check_include_file (execinfo.h HAVE_EXECINFO_H)
check_function_exists (sigaction HAVE_SIGACTION)
check_function_exists (sigaltstack HAVE_SIGALSTACK)
-check_cxx_compiler_flag (-Wno-deprecated HAVE_NO_DEPRECATED)
-check_cxx_compiler_flag (-Wno-unnamed-type-template-args
+# NOTE gcc does not fail if you pass a non-existent -Wno-* option as an
+# argument. However, it will happily fail if you pass the corresponding -W*
+# option. So, we check whether options that disable warnings exist by testing
+# the availability of the corresponding option that enables the warning. This
+# eliminates the need to check for compiler for several (mainly Clang) options.
+
+check_cxx_compiler_flag (-Wdeprecated HAVE_NO_DEPRECATED)
+check_cxx_compiler_flag (-Wunnamed-type-template-args
HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS)
# NOTE: Cannot use check_function_exists here since >=vc-14.0 can define
check_library_exists (unwind get_static_proc_name "" HAVE_LIB_UNWIND)
+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));
set (SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
-if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
- set (HAVE_PTHREAD 1)
-endif (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
+if (WITH_THREADS AND Threads_FOUND)
+ if (CMAKE_USE_PTHREADS_INIT)
+ set (HAVE_PTHREAD 1)
+ endif (CMAKE_USE_PTHREADS_INIT)
+else (WITH_THREADS AND Threads_FOUND)
+ set (NO_THREADS 1)
+endif (WITH_THREADS AND Threads_FOUND)
set (TEST_SRC_DIR \"${CMAKE_CURRENT_SOURCE_DIR}\")
)
endif (WIN32)
+add_compile_options ($<$<BOOL:${HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS}>:-Wno-unnamed-type-template-args>)
+
add_library (glog
${GLOG_SRCS}
)
+set_target_properties (glog PROPERTIES POSITION_INDEPENDENT_CODE ON)
+
+if (UNWIND_LIBRARY)
+ target_link_libraries (glog PUBLIC ${UNWIND_LIBRARY})
+endif (UNWIND_LIBRARY)
+
+if (HAVE_PTHREAD)
+ target_link_libraries (glog PUBLIC ${CMAKE_THREAD_LIBS_INIT})
+endif (HAVE_PTHREAD)
+
if (WIN32 AND HAVE_SNPRINTF)
set_property (SOURCE src/windows/port.cc APPEND PROPERTY COMPILE_DEFINITIONS
HAVE_SNPRINTF)
endif (WIN32 AND HAVE_SNPRINTF)
-if (HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS)
- target_compile_options (glog PUBLIC -Wno-unnamed-type-template-args)
-endif (HAVE_NO_UNNAMED_TYPE_TEMPLATE_ARGS)
-
if (gflags_FOUND)
- target_include_directories (glog PUBLIC ${gflags_INCLUDE_DIR})
+ target_include_directories (glog PUBLIC $<BUILD_INTERFACE:${gflags_INCLUDE_DIR}>)
target_link_libraries (glog PUBLIC ${gflags_LIBRARIES})
if (NOT BUILD_SHARED_LIBS)
target_include_directories (glog BEFORE PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
+ "$<INSTALL_INTERFACE:include>"
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
"GOOGLE_GLOG_DLL_DECL_FOR_UNITTESTS=${_IMPORT}")
endif (NOT BUILD_SHARED_LIBS)
-if (HAVE_PTHREAD)
- target_link_libraries (glog PUBLIC ${CMAKE_THREAD_LIBS_INIT})
-else (HAVE_PTHREAD)
- target_compile_definitions (glog PUBLIC NO_THREADS)
-endif (HAVE_PTHREAD)
-
if (HAVE_EXECINFO_H)
set (HAVE_STACKTRACE 1)
endif (HAVE_EXECINFO_H)
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
-# Build tree config
-
-set (glog_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
-set (glog_PACKAGE_DEPS)
-
if (gflags_FOUND)
- set (glog_PACKAGE_DEPS
-"
-include (CMakeFindDependencyMacro)
-
-find_dependency (gflags ${gflags_VERSION})
-")
+ set (gflags_DEPENDENCY "find_dependency (gflags ${gflags_VERSION})")
endif (gflags_FOUND)
configure_package_config_file (glog-config.cmake.in
- ${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake INSTALL_DESTINATION
- lib/cmake/glog PATH_VARS glog_INCLUDE_DIR
+ ${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake
+ INSTALL_DESTINATION lib/cmake/glog
NO_CHECK_REQUIRED_COMPONENTS_MACRO)
-# The version file is the same both for build tree and install mode config
write_basic_package_version_file (glog-config-version.cmake VERSION
${GLOG_VERSION} COMPATIBILITY SameMajorVersion)
-# Install config
-
-set (glog_INCLUDE_DIR include)
-
-configure_package_config_file (glog-config.cmake.in
- ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/glog-config.cmake
- INSTALL_DESTINATION lib/cmake/glog PATH_VARS glog_INCLUDE_DIR
- NO_CHECK_REQUIRED_COMPONENTS_MACRO)
-
-export (TARGETS glog FILE glog-targets.cmake)
+export (TARGETS glog NAMESPACE glog:: FILE glog-targets.cmake)
export (PACKAGE glog)
install (FILES
- ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/glog-config.cmake
+ ${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/glog-config-version.cmake
DESTINATION lib/cmake/glog)
-install (EXPORT glog-targets DESTINATION lib/cmake/glog)
+install (EXPORT glog-targets NAMESPACE glog:: DESTINATION lib/cmake/glog)