Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiud committed Oct 6, 2023
1 parent 857df01 commit 7f7ddf9
Showing 1 changed file with 71 additions and 66 deletions.
137 changes: 71 additions & 66 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,7 @@ project (glog
LANGUAGES CXX
)

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})

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

include (CheckCXXCompilerFlag)
include (CheckCXXSourceCompiles)
Expand All @@ -27,7 +20,6 @@ include (CheckTypeSize)
include (CMakeDependentOption)
include (CMakePackageConfigHelpers)
include (CMakePushCheckState)
include (CPack)
include (CTest)
include (DetermineGflagsNamespace)
include (GenerateExportHeader)
Expand Down Expand Up @@ -238,7 +230,7 @@ if (HAVE_UCONTEXT_H AND NOT PC_FROM_UCONTEXT)
foreach (_PC_FIELD ${_PC_FIELDS})
foreach (_PC_HEADER ${_PC_HEADERS})
set (_TMP
${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/uctfield.cpp)
${glog_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/uctfield.cpp)
file (WRITE ${_TMP} "
#define _GNU_SOURCE 1
#include <${_PC_HEADER}>
Expand All @@ -248,7 +240,7 @@ int main(void)
return u.${_PC_FIELD} == 0;
}
")
try_compile (HAVE_PC_FROM_UCONTEXT ${CMAKE_CURRENT_BINARY_DIR} ${_TMP}
try_compile (HAVE_PC_FROM_UCONTEXT ${glog_BINARY_DIR} ${_TMP}
COMPILE_DEFINITIONS _GNU_SOURCE=1)

if (HAVE_PC_FROM_UCONTEXT)
Expand Down Expand Up @@ -395,12 +387,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 @@ -419,14 +411,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 @@ -450,11 +442,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 @@ -546,20 +538,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,7 +564,7 @@ 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)

Expand All @@ -584,8 +576,8 @@ if (WITH_PKGCONFIG)
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 @@ -747,37 +739,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 @@ -811,7 +803,7 @@ if (BUILD_TESTING)

target_link_libraries (cleanup_with_relative_prefix_unittest PRIVATE ${_GLOG_TEST_LIBS})

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 @@ -822,21 +814,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 @@ -850,15 +842,17 @@ endif (BUILD_TESTING)

install (TARGETS glog
EXPORT glog-targets
RUNTIME DESTINATION ${_glog_CMake_BINDIR}
PUBLIC_HEADER DESTINATION ${_glog_CMake_INCLUDE_DIR}/glog
LIBRARY DESTINATION ${_glog_CMake_LIBDIR}
ARCHIVE DESTINATION ${_glog_CMake_LIBDIR})
RUNTIME DESTINATION ${_glog_CMake_BINDIR} COMPONENT Runtime
PUBLIC_HEADER DESTINATION ${_glog_CMake_INCLUDE_DIR}/glog COMPONENT Development
LIBRARY DESTINATION ${_glog_CMake_LIBDIR} COMPONENT Runtime
ARCHIVE DESTINATION ${_glog_CMake_LIBDIR} COMPONENT Development
)

if (WITH_PKGCONFIG)
install (
FILES "${PROJECT_BINARY_DIR}/libglog.pc"
FILES "${glog_BINARY_DIR}/libglog.pc"
DESTINATION "${_glog_CMake_LIBDIR}/pkgconfig"
COMPONENT Development
)
endif (WITH_PKGCONFIG)

Expand All @@ -878,12 +872,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 @@ -901,10 +895,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 @@ -915,20 +909,22 @@ 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
DESTINATION ${_glog_CMake_INSTALLDIR})
${glog_BINARY_DIR}/glog-config.cmake
${glog_BINARY_DIR}/glog-config-version.cmake
DESTINATION ${_glog_CMake_INSTALLDIR}
COMPONENT Development
)

# Find modules in share/glog/cmake
install (DIRECTORY ${_glog_BINARY_CMake_DATADIR}
Expand All @@ -937,5 +933,14 @@ install (DIRECTORY ${_glog_BINARY_CMake_DATADIR}
FILES_MATCHING PATTERN "*.cmake"
)

install (EXPORT glog-targets NAMESPACE glog:: DESTINATION
${_glog_CMake_INSTALLDIR})
install (EXPORT glog-targets NAMESPACE glog::
DESTINATION ${_glog_CMake_INSTALLDIR}
COMPONENT Development
)

set (CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
set (CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)
set (CPACK_PACKAGE_CONTACT "Google Log maintainers")
set (CPACK_DEBIAN_PACKAGE_NAME google-glog)

include (CPack)

0 comments on commit 7f7ddf9

Please sign in to comment.