Skip to content

Commit

Permalink
cmake: use glog specific project variables (#1004)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiud authored Dec 21, 2023
1 parent dfb7703 commit e26e342
Showing 1 changed file with 55 additions and 55 deletions.
110 changes: 55 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ project (glog

set (CPACK_PACKAGE_NAME glog)
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Google logging library")
set (CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set (CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set (CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set (CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
set (CPACK_PACKAGE_VERSION_MAJOR ${glog_VERSION_MAJOR})
set (CPACK_PACKAGE_VERSION_MINOR ${glog_VERSION_MINOR})
set (CPACK_PACKAGE_VERSION_PATCH ${glog_VERSION_PATCH})
set (CPACK_PACKAGE_VERSION ${glog_VERSION})

list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
list (APPEND CMAKE_MODULE_PATH ${glog_SOURCE_DIR}/cmake)

include (CheckCXXCompilerFlag)
include (CheckCXXSourceCompiles)
Expand Down Expand Up @@ -385,12 +385,12 @@ endif (WITH_THREADS AND Threads_FOUND)
# fopen/open on Cygwin can not handle unix-type paths like /home/....
# therefore we translate TEST_SRC_DIR to windows-path.
if (CYGWIN)
execute_process (COMMAND cygpath.exe -m ${CMAKE_CURRENT_SOURCE_DIR}
execute_process (COMMAND cygpath.exe -m ${glog_SOURCE_DIR}
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE TEST_SRC_DIR)
set (TEST_SRC_DIR \"${TEST_SRC_DIR}\")
else (CYGWIN)
set (TEST_SRC_DIR \"${CMAKE_CURRENT_SOURCE_DIR}\")
set (TEST_SRC_DIR \"${glog_SOURCE_DIR}\")
endif (CYGWIN)

configure_file (src/config.h.cmake.in config.h)
Expand All @@ -409,14 +409,14 @@ 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})
${glog_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)
list (APPEND _glog_CMake_MODULES ${glog_SOURCE_DIR}/cmake/FindUnwind.cmake)
endif (Unwind_FOUND)

# Generate file name for each module in the binary directory
Expand All @@ -440,11 +440,11 @@ if (_glog_CMake_MODULES)
endif (_glog_CMake_MODULES)

set (GLOG_PUBLIC_H
${CMAKE_CURRENT_BINARY_DIR}/glog/export.h
${CMAKE_CURRENT_BINARY_DIR}/glog/logging.h
${CMAKE_CURRENT_BINARY_DIR}/glog/raw_logging.h
${CMAKE_CURRENT_BINARY_DIR}/glog/stl_logging.h
${CMAKE_CURRENT_BINARY_DIR}/glog/vlog_is_on.h
${glog_BINARY_DIR}/glog/export.h
${glog_BINARY_DIR}/glog/logging.h
${glog_BINARY_DIR}/glog/raw_logging.h
${glog_BINARY_DIR}/glog/stl_logging.h
${glog_BINARY_DIR}/glog/vlog_is_on.h
src/glog/log_severity.h
src/glog/platform.h
)
Expand Down Expand Up @@ -536,7 +536,7 @@ if (ANDROID)
set (glog_libraries_options_for_static_linking "${glog_libraries_options_for_static_linking} -llog")
endif (ANDROID)

set_target_properties (glog PROPERTIES VERSION ${PROJECT_VERSION})
set_target_properties (glog PROPERTIES VERSION ${glog_VERSION})
set_target_properties (glog PROPERTIES SOVERSION 1)

if (CYGWIN OR WIN32)
Expand All @@ -546,20 +546,20 @@ endif (CYGWIN OR WIN32)
set_target_properties (glog PROPERTIES PUBLIC_HEADER "${GLOG_PUBLIC_H}")

target_include_directories (glog BEFORE PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>"
"$<BUILD_INTERFACE:${glog_BINARY_DIR}>"
"$<BUILD_INTERFACE:${glog_SOURCE_DIR}/src>"
"$<INSTALL_INTERFACE:${_glog_CMake_INCLUDE_DIR}>"
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
PRIVATE ${glog_BINARY_DIR}
PRIVATE ${glog_SOURCE_DIR}/src)

if (CYGWIN OR WIN32)
target_include_directories (glog_internal PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/windows>"
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/windows)
"$<BUILD_INTERFACE:${glog_SOURCE_DIR}/src/windows>"
PRIVATE ${glog_SOURCE_DIR}/src/windows)

target_include_directories (glog PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/windows>"
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/windows)
"$<BUILD_INTERFACE:${glog_SOURCE_DIR}/src/windows>"
PRIVATE ${glog_SOURCE_DIR}/src/windows)
endif (CYGWIN OR WIN32)

set_target_properties (glog PROPERTIES DEFINE_SYMBOL GOOGLE_GLOG_IS_A_DLL)
Expand All @@ -572,20 +572,20 @@ target_compile_definitions (glog_internal PUBLIC

generate_export_header (glog
EXPORT_MACRO_NAME GLOG_EXPORT
EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/glog/export.h)
EXPORT_FILE_NAME ${glog_BINARY_DIR}/glog/export.h)

string (STRIP "${glog_libraries_options_for_static_linking}" glog_libraries_options_for_static_linking)

if (WITH_PKGCONFIG)
set (VERSION ${PROJECT_VERSION})
set (VERSION ${glog_VERSION})
set (prefix ${CMAKE_INSTALL_PREFIX})
set (exec_prefix ${CMAKE_INSTALL_FULL_BINDIR})
set (libdir ${CMAKE_INSTALL_FULL_LIBDIR})
set (includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})

configure_file (
"${PROJECT_SOURCE_DIR}/libglog.pc.in"
"${PROJECT_BINARY_DIR}/libglog.pc"
"${glog_SOURCE_DIR}/libglog.pc.in"
"${glog_BINARY_DIR}/libglog.pc"
@ONLY
)

Expand Down Expand Up @@ -734,37 +734,37 @@ if (BUILD_TESTING)
get_cache_variables (_CACHEVARS)

set (_INITIAL_CACHE
${CMAKE_CURRENT_BINARY_DIR}/test_package_config/glog_package_config_initial_cache.cmake)
${glog_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
-DTEST_BINARY_DIR=${glog_BINARY_DIR}/test_package_config
-DINITIAL_CACHE=${_INITIAL_CACHE}
-DCACHEVARS=${_CACHEVARS}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestInitPackageConfig.cmake
-P ${glog_SOURCE_DIR}/cmake/TestInitPackageConfig.cmake
)

add_test (NAME cmake_package_config_generate COMMAND ${CMAKE_COMMAND}
-DGENERATOR=${CMAKE_GENERATOR}
-DGENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
-DGENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET}
-DINITIAL_CACHE=${_INITIAL_CACHE}
-DPACKAGE_DIR=${CMAKE_CURRENT_BINARY_DIR}
-DPACKAGE_DIR=${glog_BINARY_DIR}
-DPATH=$ENV{PATH}
-DSOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}/src/package_config_unittest/working_config
-DTEST_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/test_package_config/working_config
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TestPackageConfig.cmake
-DSOURCE_DIR=${glog_SOURCE_DIR}/src/package_config_unittest/working_config
-DTEST_BINARY_DIR=${glog_BINARY_DIR}/test_package_config/working_config
-P ${glog_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
${CMAKE_COMMAND} --build ${glog_BINARY_DIR}/test_package_config/working_config
--config $<CONFIG>
)

add_test (NAME cmake_package_config_cleanup COMMAND ${CMAKE_COMMAND} -E
remove_directory
${CMAKE_CURRENT_BINARY_DIR}/test_package_config
${glog_BINARY_DIR}/test_package_config
)

# Fixtures setup
Expand Down Expand Up @@ -798,7 +798,7 @@ if (BUILD_TESTING)

target_link_libraries (cleanup_with_relative_prefix_unittest PRIVATE glog_test)

set (CLEANUP_LOG_DIR ${CMAKE_CURRENT_BINARY_DIR}/cleanup_tests)
set (CLEANUP_LOG_DIR ${glog_BINARY_DIR}/cleanup_tests)

add_test (NAME cleanup_init COMMAND
${CMAKE_COMMAND} -E make_directory ${CLEANUP_LOG_DIR})
Expand All @@ -809,21 +809,21 @@ if (BUILD_TESTING)
-DLOGCLEANUP=$<TARGET_FILE:cleanup_immediately_unittest>
# NOTE The trailing slash is important
-DTEST_DIR=${CLEANUP_LOG_DIR}/
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/RunCleanerTest1.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
-P ${glog_SOURCE_DIR}/cmake/RunCleanerTest1.cmake
WORKING_DIRECTORY ${glog_BINARY_DIR})
add_test (NAME cleanup_with_absolute_prefix COMMAND
${CMAKE_COMMAND}
-DLOGCLEANUP=$<TARGET_FILE:cleanup_with_absolute_prefix_unittest>
-DTEST_DIR=${CMAKE_CURRENT_BINARY_DIR}/
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/RunCleanerTest2.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
-DTEST_DIR=${glog_BINARY_DIR}/
-P ${glog_SOURCE_DIR}/cmake/RunCleanerTest2.cmake
WORKING_DIRECTORY ${glog_BINARY_DIR})
add_test (NAME cleanup_with_relative_prefix COMMAND
${CMAKE_COMMAND}
-DLOGCLEANUP=$<TARGET_FILE:cleanup_with_relative_prefix_unittest>
-DTEST_DIR=${CMAKE_CURRENT_BINARY_DIR}/
-DTEST_DIR=${glog_BINARY_DIR}/
-DTEST_SUBDIR=test_subdir/
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/RunCleanerTest3.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
-P ${glog_SOURCE_DIR}/cmake/RunCleanerTest3.cmake
WORKING_DIRECTORY ${glog_BINARY_DIR})

# Fixtures setup
set_tests_properties (cleanup_init PROPERTIES FIXTURES_SETUP logcleanuptest)
Expand All @@ -844,7 +844,7 @@ install (TARGETS glog

if (WITH_PKGCONFIG)
install (
FILES "${PROJECT_BINARY_DIR}/libglog.pc"
FILES "${glog_BINARY_DIR}/libglog.pc"
DESTINATION "${_glog_CMake_LIBDIR}/pkgconfig"
)
endif (WITH_PKGCONFIG)
Expand All @@ -865,12 +865,12 @@ if (gflags_FOUND)
endif (gflags_FOUND)

configure_package_config_file (glog-config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake
${glog_BINARY_DIR}/glog-config.cmake
INSTALL_DESTINATION ${_glog_CMake_INSTALLDIR}
NO_CHECK_REQUIRED_COMPONENTS_MACRO)

write_basic_package_version_file (
${CMAKE_CURRENT_BINARY_DIR}/glog-config-version.cmake
${glog_BINARY_DIR}/glog-config-version.cmake
COMPATIBILITY SameMajorVersion)

export (TARGETS glog NAMESPACE glog:: FILE glog-targets.cmake)
Expand All @@ -888,10 +888,10 @@ get_filename_component (glog_REL_CMake_DATADIR ${glog_REL_CMake_MODULES}
DIRECTORY)

set (glog_FULL_CMake_DATADIR
${CMAKE_CURRENT_BINARY_DIR}/${_glog_CMake_DATADIR})
${glog_BINARY_DIR}/${_glog_CMake_DATADIR})

configure_file (glog-modules.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/glog-modules.cmake @ONLY)
${glog_BINARY_DIR}/glog-modules.cmake @ONLY)

install (CODE
"
Expand All @@ -902,19 +902,19 @@ if (NOT IS_ABSOLUTE ${_glog_CMake_INSTALLDIR})
set (glog_DATADIR_DESTINATION \"\${CMAKE_INSTALL_PREFIX}/\${glog_DATADIR_DESTINATION}\")
endif (NOT IS_ABSOLUTE ${_glog_CMake_INSTALLDIR})
configure_file (\"${CMAKE_CURRENT_SOURCE_DIR}/glog-modules.cmake.in\"
\"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/glog-modules.cmake\" @ONLY)
configure_file (\"${glog_SOURCE_DIR}/glog-modules.cmake.in\"
\"${glog_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/glog-modules.cmake\" @ONLY)
file (INSTALL
\"${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/glog-modules.cmake\"
\"${glog_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/glog-modules.cmake\"
DESTINATION
\"\${glog_DATADIR_DESTINATION}\")
"
COMPONENT Development
)

install (FILES
${CMAKE_CURRENT_BINARY_DIR}/glog-config.cmake
${CMAKE_CURRENT_BINARY_DIR}/glog-config-version.cmake
${glog_BINARY_DIR}/glog-config.cmake
${glog_BINARY_DIR}/glog-config-version.cmake
DESTINATION ${_glog_CMake_INSTALLDIR})

# Find modules in share/glog/cmake
Expand Down

0 comments on commit e26e342

Please sign in to comment.