2019-10-11 17:24:25 -07:00
|
|
|
#[===================================================================[
|
|
|
|
date library by Howard Hinnant
|
|
|
|
|
|
|
|
CMake projects that wish to use this library should consider
|
|
|
|
something like the following :
|
|
|
|
|
|
|
|
include( FetchContent )
|
|
|
|
FetchContent_Declare( date_src
|
|
|
|
GIT_REPOSITORY https://github.com/HowardHinnant/date.git
|
2021-09-01 15:57:59 +02:00
|
|
|
GIT_TAG v3.0.1 # adjust tag/branch/commit as needed
|
2019-10-11 17:24:25 -07:00
|
|
|
)
|
|
|
|
FetchContent_MakeAvailable(date_src)
|
|
|
|
...
|
|
|
|
target_link_libraries (my_target PRIVATE date::date)
|
|
|
|
|
|
|
|
#]===================================================================]
|
|
|
|
|
2019-12-29 11:51:04 -08:00
|
|
|
cmake_minimum_required( VERSION 3.7 )
|
2019-09-23 19:08:07 -07:00
|
|
|
|
2021-09-01 15:57:59 +02:00
|
|
|
project( date VERSION 3.0.1 )
|
2020-08-25 13:57:00 -07:00
|
|
|
set(ABI_VERSION 3) # used as SOVERSION, increment when ABI changes
|
2017-11-24 21:34:36 -05:00
|
|
|
|
2018-03-13 18:22:26 +01:00
|
|
|
include( GNUInstallDirs )
|
|
|
|
|
2019-10-11 17:24:25 -07:00
|
|
|
get_directory_property( has_parent PARENT_DIRECTORY )
|
2017-11-24 21:34:36 -05:00
|
|
|
|
2018-03-19 17:52:38 +00:00
|
|
|
# Override by setting on CMake command line.
|
2019-10-11 17:24:25 -07:00
|
|
|
set( CMAKE_CXX_STANDARD 17 CACHE STRING "The C++ standard whose features are requested." )
|
2018-03-19 17:52:38 +00:00
|
|
|
|
2017-11-24 23:07:39 -05:00
|
|
|
option( USE_SYSTEM_TZ_DB "Use the operating system's timezone database" OFF )
|
2020-01-15 19:08:15 -08:00
|
|
|
option( MANUAL_TZ_DB "User will set TZ DB manually by invoking set_install in their code" OFF )
|
2017-11-24 23:07:39 -05:00
|
|
|
option( USE_TZ_DB_IN_DOT "Save the timezone database in the current folder" OFF )
|
2018-03-19 18:04:34 +00:00
|
|
|
option( BUILD_SHARED_LIBS "Build a shared version of library" OFF )
|
2019-10-11 17:24:25 -07:00
|
|
|
option( ENABLE_DATE_TESTING "Enable unit tests" OFF )
|
2018-06-11 09:14:17 +02:00
|
|
|
option( DISABLE_STRING_VIEW "Disable string view" OFF )
|
2019-10-11 17:24:25 -07:00
|
|
|
option( COMPILE_WITH_C_LOCALE "define ONLY_C_LOCALE=1" OFF )
|
|
|
|
option( BUILD_TZ_LIB "build/install of TZ library" OFF )
|
2019-09-08 15:42:46 +02:00
|
|
|
|
2019-10-11 17:24:25 -07:00
|
|
|
if( ENABLE_DATE_TESTING AND NOT BUILD_TZ_LIB )
|
|
|
|
message(WARNING "Testing requested, bug BUILD_TZ_LIB not ON - forcing the latter")
|
|
|
|
set (BUILD_TZ_LIB ON CACHE BOOL "required for testing" FORCE)
|
|
|
|
endif( )
|
2017-12-02 20:24:42 +01:00
|
|
|
|
|
|
|
function( print_option OPT )
|
2019-10-11 17:24:25 -07:00
|
|
|
if ( NOT DEFINED PRINT_OPTION_CURR_${OPT} OR ( NOT PRINT_OPTION_CURR_${OPT} STREQUAL ${OPT} ) )
|
|
|
|
set( PRINT_OPTION_CURR_${OPT} ${${OPT}} CACHE BOOL "" )
|
|
|
|
mark_as_advanced(PRINT_OPTION_CURR_${OPT})
|
|
|
|
message( "# date: ${OPT} ${${OPT}}" )
|
|
|
|
endif( )
|
2017-12-02 20:24:42 +01:00
|
|
|
endfunction( )
|
|
|
|
|
|
|
|
print_option( USE_SYSTEM_TZ_DB )
|
2020-01-15 19:08:15 -08:00
|
|
|
print_option( MANUAL_TZ_DB )
|
2017-12-02 20:24:42 +01:00
|
|
|
print_option( USE_TZ_DB_IN_DOT )
|
2018-03-19 18:04:34 +00:00
|
|
|
print_option( BUILD_SHARED_LIBS )
|
2018-01-28 18:40:46 -05:00
|
|
|
print_option( ENABLE_DATE_TESTING )
|
2018-06-11 09:14:17 +02:00
|
|
|
print_option( DISABLE_STRING_VIEW )
|
2017-11-24 21:34:36 -05:00
|
|
|
|
2019-10-11 17:24:25 -07:00
|
|
|
#[===================================================================[
|
|
|
|
date (header only) library
|
|
|
|
#]===================================================================]
|
|
|
|
add_library( date INTERFACE )
|
|
|
|
add_library( date::date ALIAS date )
|
|
|
|
target_include_directories( date INTERFACE
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
|
|
$<INSTALL_INTERFACE:include> )
|
|
|
|
# adding header sources just helps IDEs
|
|
|
|
target_sources( date INTERFACE
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>$<INSTALL_INTERFACE:include>/date/date.h
|
|
|
|
# the rest of these are not currently part of the public interface of the library:
|
2020-01-27 13:30:24 +03:30
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/date/solar_hijri.h>
|
2019-10-11 17:24:25 -07:00
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/date/islamic.h>
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/date/iso_week.h>
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/date/julian.h>
|
2017-11-24 21:34:36 -05:00
|
|
|
)
|
2019-12-29 11:51:04 -08:00
|
|
|
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
|
|
|
|
# public headers will get installed:
|
|
|
|
set_target_properties( date PROPERTIES PUBLIC_HEADER include/date/date.h )
|
|
|
|
endif ()
|
2020-07-23 01:03:42 +02:00
|
|
|
|
|
|
|
# These used to be set with generator expressions,
|
|
|
|
#
|
|
|
|
# ONLY_C_LOCALE=$<IF:$<BOOL:${COMPILE_WITH_C_LOCALE}>,1,0>
|
|
|
|
#
|
|
|
|
# which expand in the output target file to, e.g.
|
|
|
|
#
|
|
|
|
# ONLY_C_LOCALE=$<IF:$<BOOL:FALSE>,1,0>
|
|
|
|
#
|
|
|
|
# This string is then (somtimes?) not correctly interpreted.
|
|
|
|
if ( COMPILE_WITH_C_LOCALE )
|
|
|
|
# To workaround libstdc++ issue https://github.com/HowardHinnant/date/issues/388
|
|
|
|
target_compile_definitions( date INTERFACE ONLY_C_LOCALE=1 )
|
|
|
|
else()
|
|
|
|
target_compile_definitions( date INTERFACE ONLY_C_LOCALE=0 )
|
|
|
|
endif()
|
|
|
|
if ( DISABLE_STRING_VIEW )
|
2020-10-09 02:22:15 +03:00
|
|
|
target_compile_definitions( date INTERFACE HAS_STRING_VIEW=0 -DHAS_DEDUCTION_GUIDES=0 )
|
2020-07-23 01:03:42 +02:00
|
|
|
endif()
|
2019-10-11 17:24:25 -07:00
|
|
|
|
|
|
|
#[===================================================================[
|
|
|
|
tz (compiled) library
|
|
|
|
#]===================================================================]
|
|
|
|
if( BUILD_TZ_LIB )
|
2020-05-19 18:34:50 -07:00
|
|
|
add_library( date-tz )
|
|
|
|
target_sources( date-tz
|
2019-10-11 17:24:25 -07:00
|
|
|
PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>$<INSTALL_INTERFACE:include>/date/tz.h
|
|
|
|
PRIVATE
|
|
|
|
include/date/tz_private.h
|
|
|
|
src/tz.cpp )
|
2020-07-23 01:03:42 +02:00
|
|
|
if ( IOS )
|
|
|
|
target_sources( date-tz
|
|
|
|
PUBLIC
|
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>$<INSTALL_INTERFACE:include>/date/ios.h
|
|
|
|
PRIVATE
|
|
|
|
src/ios.mm )
|
|
|
|
endif()
|
2020-08-25 13:57:00 -07:00
|
|
|
add_library( date::date-tz ALIAS date-tz )
|
2020-05-19 18:34:50 -07:00
|
|
|
target_link_libraries( date-tz PUBLIC date )
|
|
|
|
target_include_directories( date-tz PUBLIC
|
2019-10-11 17:24:25 -07:00
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
|
|
|
$<INSTALL_INTERFACE:include> )
|
2020-07-23 01:03:42 +02:00
|
|
|
|
|
|
|
if ( USE_SYSTEM_TZ_DB OR MANUAL_TZ_DB )
|
|
|
|
target_compile_definitions( date-tz PRIVATE AUTO_DOWNLOAD=0 HAS_REMOTE_API=0 )
|
|
|
|
else()
|
|
|
|
target_compile_definitions( date-tz PRIVATE AUTO_DOWNLOAD=1 HAS_REMOTE_API=1 )
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if ( USE_SYSTEM_TZ_DB AND NOT WIN32 AND NOT MANUAL_TZ_DB )
|
|
|
|
target_compile_definitions( date-tz PRIVATE INSTALL=. PUBLIC USE_OS_TZDB=1 )
|
|
|
|
else()
|
|
|
|
target_compile_definitions( date-tz PUBLIC USE_OS_TZDB=0 )
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if ( WIN32 AND BUILD_SHARED_LIBS )
|
|
|
|
target_compile_definitions( date-tz PUBLIC DATE_BUILD_DLL=1 )
|
|
|
|
endif()
|
|
|
|
|
2019-10-11 17:24:25 -07:00
|
|
|
set(TZ_HEADERS include/date/tz.h)
|
2020-07-23 01:03:42 +02:00
|
|
|
|
2019-10-11 17:24:25 -07:00
|
|
|
if( IOS )
|
|
|
|
list(APPEND TZ_HEADERS include/date/ios.h)
|
|
|
|
endif( )
|
2020-05-19 18:34:50 -07:00
|
|
|
set_target_properties( date-tz PROPERTIES
|
2019-10-11 17:24:25 -07:00
|
|
|
POSITION_INDEPENDENT_CODE ON
|
|
|
|
PUBLIC_HEADER "${TZ_HEADERS}"
|
|
|
|
VERSION "${PROJECT_VERSION}"
|
2020-08-25 13:57:00 -07:00
|
|
|
SOVERSION "${ABI_VERSION}" )
|
2019-10-11 17:24:25 -07:00
|
|
|
if( NOT MSVC )
|
|
|
|
find_package( Threads )
|
2020-05-19 18:34:50 -07:00
|
|
|
target_link_libraries( date-tz PUBLIC Threads::Threads )
|
2019-10-11 17:24:25 -07:00
|
|
|
endif( )
|
2020-01-15 19:08:15 -08:00
|
|
|
if( NOT USE_SYSTEM_TZ_DB AND NOT MANUAL_TZ_DB )
|
2019-10-11 17:24:25 -07:00
|
|
|
find_package( CURL REQUIRED )
|
2020-05-19 18:34:50 -07:00
|
|
|
target_include_directories( date-tz SYSTEM PRIVATE ${CURL_INCLUDE_DIRS} )
|
|
|
|
target_link_libraries( date-tz PRIVATE ${CURL_LIBRARIES} )
|
2019-10-11 17:24:25 -07:00
|
|
|
endif( )
|
2018-01-09 20:09:11 -05:00
|
|
|
endif( )
|
|
|
|
|
2019-10-11 17:24:25 -07:00
|
|
|
#[===================================================================[
|
|
|
|
installation
|
|
|
|
#]===================================================================]
|
|
|
|
set( version_config "${CMAKE_CURRENT_BINARY_DIR}/dateConfigVersion.cmake" )
|
|
|
|
|
|
|
|
include( CMakePackageConfigHelpers )
|
|
|
|
write_basic_package_version_file( "${version_config}"
|
|
|
|
VERSION ${PROJECT_VERSION}
|
|
|
|
COMPATIBILITY SameMajorVersion )
|
|
|
|
|
|
|
|
install( TARGETS date
|
|
|
|
EXPORT dateConfig
|
|
|
|
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/date )
|
2019-12-29 11:51:04 -08:00
|
|
|
export( TARGETS date NAMESPACE date:: FILE dateTargets.cmake )
|
|
|
|
if (CMAKE_VERSION VERSION_LESS 3.15)
|
|
|
|
install(
|
|
|
|
FILES include/date/date.h
|
|
|
|
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/date )
|
|
|
|
endif ()
|
2019-10-11 17:24:25 -07:00
|
|
|
|
|
|
|
if( BUILD_TZ_LIB )
|
2020-05-19 18:34:50 -07:00
|
|
|
install( TARGETS date-tz
|
2019-10-11 17:24:25 -07:00
|
|
|
EXPORT dateConfig
|
|
|
|
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/date
|
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) # This is for Windows
|
2020-05-19 18:34:50 -07:00
|
|
|
export( TARGETS date-tz NAMESPACE date:: APPEND FILE dateTargets.cmake )
|
2018-06-11 09:14:17 +02:00
|
|
|
endif( )
|
|
|
|
|
2019-10-11 17:24:25 -07:00
|
|
|
if( WIN32 AND NOT CYGWIN)
|
|
|
|
set( CONFIG_LOC CMake )
|
|
|
|
else( )
|
|
|
|
set( CONFIG_LOC "${CMAKE_INSTALL_LIBDIR}/cmake/date" )
|
2018-06-11 09:14:17 +02:00
|
|
|
endif( )
|
2019-10-11 17:24:25 -07:00
|
|
|
install( EXPORT dateConfig
|
2019-12-29 11:51:04 -08:00
|
|
|
FILE dateTargets.cmake
|
2019-10-11 17:24:25 -07:00
|
|
|
NAMESPACE date::
|
|
|
|
DESTINATION ${CONFIG_LOC} )
|
2019-12-29 11:51:04 -08:00
|
|
|
install (
|
|
|
|
FILES cmake/dateConfig.cmake "${version_config}"
|
|
|
|
DESTINATION ${CONFIG_LOC})
|
2019-10-11 17:24:25 -07:00
|
|
|
|
|
|
|
#[===================================================================[
|
|
|
|
testing
|
|
|
|
#]===================================================================]
|
|
|
|
if( ENABLE_DATE_TESTING )
|
2018-01-28 18:40:46 -05:00
|
|
|
enable_testing( )
|
|
|
|
|
|
|
|
add_custom_target( testit COMMAND ${CMAKE_CTEST_COMMAND} )
|
2020-05-19 18:34:50 -07:00
|
|
|
add_dependencies( testit date-tz )
|
2019-10-11 17:24:25 -07:00
|
|
|
|
2018-01-28 18:40:46 -05:00
|
|
|
function( add_pass_tests TEST_GLOB TEST_PREFIX )
|
|
|
|
file( GLOB_RECURSE FILENAMES ${TEST_GLOB} )
|
|
|
|
|
|
|
|
foreach( TEST_FILE ${FILENAMES} )
|
|
|
|
get_filename_component( TEST_NAME ${TEST_FILE} NAME_WE )
|
|
|
|
get_filename_component( TEST_EXT ${TEST_FILE} EXT )
|
|
|
|
if( NOT ${TEST_EXT} STREQUAL ".fail.cpp" )
|
|
|
|
set( PREFIX "${TEST_PREFIX}_pass_${TEST_NAME}" )
|
|
|
|
set( BIN_NAME ${PREFIX}_bin )
|
|
|
|
set( TST_NAME ${PREFIX}_test )
|
|
|
|
add_executable( ${BIN_NAME} EXCLUDE_FROM_ALL ${TEST_FILE} )
|
|
|
|
add_test( ${TST_NAME} ${BIN_NAME} )
|
2020-05-19 18:34:50 -07:00
|
|
|
target_link_libraries( ${BIN_NAME} date-tz )
|
2019-10-11 17:24:25 -07:00
|
|
|
# HACK: because the test files don't use FQ includes:
|
|
|
|
target_include_directories( ${BIN_NAME} PRIVATE include/date )
|
2018-01-28 18:40:46 -05:00
|
|
|
add_dependencies( testit ${BIN_NAME} )
|
|
|
|
endif( )
|
|
|
|
endforeach( )
|
|
|
|
endfunction( )
|
|
|
|
|
|
|
|
function( add_fail_tests TEST_GLOB TEST_PREFIX )
|
|
|
|
file( GLOB_RECURSE FILENAMES ${TEST_GLOB} )
|
|
|
|
|
|
|
|
foreach( TEST_FILE ${FILENAMES} )
|
|
|
|
get_filename_component( TEST_NAME ${TEST_FILE} NAME_WE )
|
|
|
|
get_filename_component( TEST_EXT ${TEST_FILE} EXT )
|
|
|
|
|
2019-10-11 17:24:25 -07:00
|
|
|
set( TEST_TYPE "_fail" )
|
2018-01-28 18:40:46 -05:00
|
|
|
|
|
|
|
set( PREFIX "${TEST_PREFIX}_fail_${TEST_NAME}" )
|
|
|
|
set( BIN_NAME ${PREFIX}_bin )
|
|
|
|
set( TST_NAME ${PREFIX}_test )
|
|
|
|
|
|
|
|
set( TEST_BIN_NAME ${CMAKE_BINARY_DIR}/${BIN_NAME} )
|
|
|
|
add_custom_target( ${BIN_NAME}
|
2019-10-11 17:24:25 -07:00
|
|
|
COMMAND
|
|
|
|
${PROJECT_SOURCE_DIR}/compile_fail.sh
|
|
|
|
${TEST_BIN_NAME}
|
|
|
|
${CMAKE_CXX_COMPILER}
|
|
|
|
-std=c++14
|
|
|
|
-L${CMAKE_BINARY_DIR}/
|
2020-08-25 13:57:00 -07:00
|
|
|
-ldate-tz
|
2019-10-11 17:24:25 -07:00
|
|
|
-I${PROJECT_SOURCE_DIR}/include
|
|
|
|
-I${PROJECT_SOURCE_DIR}/include/date
|
|
|
|
-o ${BIN_NAME}
|
|
|
|
${TEST_FILE}
|
2018-01-28 18:40:46 -05:00
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
2019-10-11 17:24:25 -07:00
|
|
|
COMMENT ${TST_NAME} )
|
2018-01-28 18:40:46 -05:00
|
|
|
add_test( ${TST_NAME} "${PROJECT_SOURCE_DIR}/test_fail.sh" ${CMAKE_BINARY_DIR}/${BIN_NAME} WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/" )
|
|
|
|
#set_tests_properties( ${TST_NAME} PROPERTIES WILL_FAIL TRUE)
|
|
|
|
add_dependencies( testit ${BIN_NAME} )
|
|
|
|
endforeach( )
|
|
|
|
endfunction( )
|
|
|
|
|
2019-10-11 17:24:25 -07:00
|
|
|
file( GLOB children RELATIVE "${PROJECT_SOURCE_DIR}/test" "${PROJECT_SOURCE_DIR}/test/*" )
|
2018-01-28 18:40:46 -05:00
|
|
|
foreach( child ${children} )
|
2019-10-11 17:24:25 -07:00
|
|
|
if( IS_DIRECTORY "${PROJECT_SOURCE_DIR}/test/${child}" )
|
|
|
|
set( CUR_FOLDER "${PROJECT_SOURCE_DIR}/test/${child}" )
|
2018-01-28 18:40:46 -05:00
|
|
|
add_pass_tests( "${CUR_FOLDER}/*.cpp" ${child} )
|
|
|
|
if( NOT WIN32 )
|
|
|
|
add_fail_tests( "${CUR_FOLDER}/*.fail.cpp" ${child} )
|
|
|
|
endif( )
|
|
|
|
endif( )
|
|
|
|
endforeach( )
|
|
|
|
endif( )
|