Skip to content

Commit

Permalink
Merge pull request #1 from isaachier/hunter-2.2
Browse files Browse the repository at this point in the history
Backport CMake changes to v2.2
  • Loading branch information
isaachier authored Mar 8, 2018
2 parents e19879d + 450af4b commit bc4a0a9
Show file tree
Hide file tree
Showing 7 changed files with 664 additions and 133 deletions.
187 changes: 109 additions & 78 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,62 +1,33 @@
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.1)

project(cctz)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

set(CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/cmake
${PROJECT_SOURCE_DIR}/cmake/modules
${CMAKE_MODULE_PATH})
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/toolchain.cmake"
CACHE FILEPATH
"Toolchain to use for building this package and dependencies")

include(HunterGate)
HunterGate(
URL "https://github.com/ruslo/hunter/archive/v0.20.14.tar.gz"
SHA1 "18cdbf5c47abdda437c73bf5437b7c3c65afe47c"
)

project(cctz VERSION 2.2)

include(CTest)
include(FeatureSummary)

option(BUILD_TOOLS "Whether or not to build tools" ON)
option(BUILD_EXAMPLES "Whether or not to build examples" ON)

if (BUILD_TESTING)
find_package(benchmark)
set_package_properties(benchmark PROPERTIES
TYPE REQUIRED
DESCRIPTION "a microbenchmark support library"
URL "https://github.com/google/benchmark"
)

find_package(GMock)
set_package_properties(GMock PROPERTIES
TYPE REQUIRED
DESCRIPTION "the Google C++ mocking framework"
URL "https://github.com/google/googletest"
)

find_package(GTest)
set_package_properties(GTest PROPERTIES
TYPE REQUIRED
DESCRIPTION "the Google C++ test framework"
URL "https://github.com/google/googletest"
)

find_package(Threads)
set_package_properties(Threads PROPERTIES
TYPE REQUIRED
DESCRIPTION "the system thread library"
)
hunter_add_package(benchmark)
find_package(benchmark CONFIG REQUIRED)
hunter_add_package(GTest)
find_package(GMock CONFIG REQUIRED)
find_package(GTest CONFIG REQUIRED)
endif()

# Starting from CMake >= 3.1, if a specific standard is required,
# it can be set from the command line with:
# cmake -DCMAKE_CXX_STANDARD=[11|14|17]
function(cctz_target_set_cxx_standard target)
set(cxx_standard 11)
if (CMAKE_VERSION VERSION_LESS "3.1")
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(${target} PRIVATE -std=c++${cxx_standard})
endif()
elseif (CMAKE_VERSION VERSION_LESS "3.8")
set_property(TARGET ${target} PROPERTY CXX_STANDARD ${cxx_standard})
else()
target_compile_features(${target} PUBLIC cxx_std_${cxx_standard})
endif()
endfunction()

add_library(cctz
src/civil_time_detail.cc
src/time_zone_fixed.cc
Expand All @@ -74,49 +45,36 @@ add_library(cctz
src/time_zone_posix.cc
src/time_zone_posix.h
src/tzfile.h
src/zone_info_source.cc
)
cctz_target_set_cxx_standard(cctz)
add_library(cctz::cctz ALIAS cctz)
src/zone_info_source.cc)

target_include_directories(cctz PUBLIC include)
target_include_directories(cctz PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)

add_executable(time_tool src/time_tool.cc)
cctz_target_set_cxx_standard(time_tool)
target_link_libraries(time_tool cctz::cctz)
if (BUILD_TOOLS)
add_executable(time_tool src/time_tool.cc)
target_link_libraries(time_tool cctz)
endif()

if (BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

if (BUILD_TESTING)
add_executable(civil_time_test src/civil_time_test.cc)
cctz_target_set_cxx_standard(civil_time_test)
target_include_directories(civil_time_test PRIVATE ${GTEST_INCLUDE_DIRS})
target_link_libraries(civil_time_test
cctz::cctz
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
target_link_libraries(civil_time_test PUBLIC
cctz
GTest::main)
add_test(civil_time_test civil_time_test)

add_executable(time_zone_lookup_test src/time_zone_lookup_test.cc)
cctz_target_set_cxx_standard(time_zone_lookup_test)
target_include_directories(time_zone_lookup_test PRIVATE ${GTEST_INCLUDE_DIRS})
target_link_libraries(time_zone_lookup_test
cctz::cctz
${GTEST_BOTH_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
target_link_libraries(time_zone_lookup_test PUBLIC
cctz
GTest::main)
add_test(time_zone_lookup_test time_zone_lookup_test)

add_executable(time_zone_format_test src/time_zone_format_test.cc)
cctz_target_set_cxx_standard(time_zone_format_test)
target_link_libraries(time_zone_format_test
cctz::cctz
${CMAKE_THREAD_LIBS_INIT}
GMock::Main
)
target_link_libraries(time_zone_format_test PUBLIC
cctz GMock::main)
add_test(time_zone_format_test time_zone_format_test)

# tests runs on testdata
Expand All @@ -130,8 +88,81 @@ if (BUILD_TESTING)
)

add_executable(benchmarks src/benchmarks.cc)
cctz_target_set_cxx_standard(benchmarks)
target_link_libraries(benchmarks cctz::cctz benchmark::benchmark)
target_link_libraries(benchmarks cctz benchmark::benchmark)
endif()

feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)

# Installation (https://github.com/forexample/package-example)

# Layout. This works for all platforms:
# * <prefix>/lib/cmake/<PROJECT-NAME>
# * <prefix>/lib/
# * <prefix>/include/
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
set(include_install_dir "include")

set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")

# Configuration
set(version_config "${generated_dir}/${PROJECT_NAME}ConfigVersion.cmake")
set(project_config "${generated_dir}/${PROJECT_NAME}Config.cmake")
set(TARGETS_EXPORT_NAME "${PROJECT_NAME}Targets")
set(namespace "${PROJECT_NAME}::")

# Include module with fuction 'write_basic_package_version_file'
include(CMakePackageConfigHelpers)

# Configure '<PROJECT-NAME>ConfigVersion.cmake'
# Use:
# * PROJECT_VERSION
write_basic_package_version_file(
"${version_config}" COMPATIBILITY SameMajorVersion
)

# Configure '<PROJECT-NAME>Config.cmake'
# Use variables:
# * TARGETS_EXPORT_NAME
# * PROJECT_NAME
configure_package_config_file(
"cmake/Config.cmake.in"
"${project_config}"
INSTALL_DESTINATION "${config_install_dir}"
)

# Targets:
# * <prefix>/lib/libcctz.a
# * header location after install: <prefix>/include/cctz/time_zone.h
# * headers can be included by C++ code `#include <cctz/time_zone.h>`
install(
TARGETS cctz
EXPORT "${TARGETS_EXPORT_NAME}"
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "${include_install_dir}"
)

# Headers:
# * include/cctz/time_zone.h -> <prefix>/include/cctz/time_zone.h
install(
DIRECTORY "include/cctz"
DESTINATION "${include_install_dir}"
FILES_MATCHING PATTERN "*.h"
)

# Config
# * <prefix>/lib/cmake/cctz/cctzConfig.cmake
# * <prefix>/lib/cmake/cctz/cctzConfigVersion.cmake
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
)

# Config
# * <prefix>/lib/cmake/cctz/cctzTargets.cmake
install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
DESTINATION "${config_install_dir}"
)
4 changes: 4 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")
Loading

0 comments on commit bc4a0a9

Please sign in to comment.