2018-03-19 17:52:38 +00:00
|
|
|
cmake_minimum_required( VERSION 3.1.0 )
|
2017-11-24 21:34:36 -05:00
|
|
|
|
2019-09-09 14:01:07 +02:00
|
|
|
project( date VERSION 2.4.1 )
|
2017-11-24 21:34:36 -05:00
|
|
|
|
2018-03-13 18:22:26 +01:00
|
|
|
include( GNUInstallDirs )
|
|
|
|
|
2017-11-24 23:07:39 -05:00
|
|
|
find_package( Threads REQUIRED )
|
2017-11-24 21:34:36 -05:00
|
|
|
|
2018-03-19 17:52:38 +00:00
|
|
|
# Override by setting on CMake command line.
|
|
|
|
set( CMAKE_CXX_STANDARD 17 CACHE STRING "The C++ standard whose features are requested.")
|
|
|
|
|
2017-11-24 23:07:39 -05:00
|
|
|
option( USE_SYSTEM_TZ_DB "Use the operating system's timezone database" OFF )
|
|
|
|
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 )
|
2018-01-28 18:40:46 -05:00
|
|
|
option( ENABLE_DATE_TESTING "Enable unit tests" ON )
|
2018-06-11 09:14:17 +02:00
|
|
|
option( DISABLE_STRING_VIEW "Disable string view" OFF )
|
2017-12-02 20:24:42 +01:00
|
|
|
|
|
|
|
function( print_option OPT )
|
2017-12-26 21:00:29 +01: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})
|
2017-12-02 20:24:42 +01:00
|
|
|
message( "# date: ${OPT} ${${OPT}}" )
|
|
|
|
endif( )
|
|
|
|
endfunction( )
|
|
|
|
|
|
|
|
print_option( USE_SYSTEM_TZ_DB )
|
|
|
|
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
|
|
|
|
|
|
|
set( HEADER_FOLDER "include" )
|
|
|
|
set( SOURCE_FOLDER "src" )
|
|
|
|
set( TEST_FOLDER "test" )
|
|
|
|
|
|
|
|
# This is needed so IDE's live MSVC show header files
|
|
|
|
set( HEADER_FILES
|
|
|
|
${HEADER_FOLDER}/date/chrono_io.h
|
|
|
|
${HEADER_FOLDER}/date/date.h
|
|
|
|
${HEADER_FOLDER}/date/ios.h
|
|
|
|
${HEADER_FOLDER}/date/islamic.h
|
|
|
|
${HEADER_FOLDER}/date/iso_week.h
|
|
|
|
${HEADER_FOLDER}/date/julian.h
|
|
|
|
${HEADER_FOLDER}/date/tz.h
|
|
|
|
${HEADER_FOLDER}/date/tz_private.h
|
|
|
|
)
|
|
|
|
|
2019-09-09 14:01:07 +02:00
|
|
|
add_library( tz ${HEADER_FILES} ${SOURCE_FOLDER}/tz.cpp )
|
2017-12-25 17:14:50 +02:00
|
|
|
|
2018-01-09 20:09:11 -05:00
|
|
|
if( USE_SYSTEM_TZ_DB )
|
2019-09-09 14:01:07 +02:00
|
|
|
target_compile_definitions( tz PRIVATE -DUSE_AUTOLOAD=0 )
|
|
|
|
target_compile_definitions( tz PRIVATE -DHAS_REMOTE_API=0 )
|
2018-01-09 20:09:11 -05:00
|
|
|
# cannot set USE_OS_TZDB to 1 on Windows
|
|
|
|
if( NOT WIN32 )
|
2019-09-09 14:01:07 +02:00
|
|
|
target_compile_definitions( tz PUBLIC -DUSE_OS_TZDB=1 )
|
2018-01-09 20:09:11 -05:00
|
|
|
endif( )
|
|
|
|
else( )
|
2019-09-09 14:01:07 +02:00
|
|
|
target_compile_definitions( tz PRIVATE -DUSE_AUTOLOAD=1 )
|
|
|
|
target_compile_definitions( tz PRIVATE -DHAS_REMOTE_API=1 )
|
|
|
|
target_compile_definitions( tz PUBLIC -DUSE_OS_TZDB=0 )
|
2018-01-09 20:09:11 -05:00
|
|
|
find_package( CURL REQUIRED )
|
|
|
|
include_directories( SYSTEM ${CURL_INCLUDE_DIRS} )
|
|
|
|
set( OPTIONAL_LIBRARIES ${CURL_LIBRARIES} )
|
|
|
|
endif( )
|
|
|
|
|
|
|
|
if( USE_TZ_DB_IN_DOT )
|
2019-09-09 14:01:07 +02:00
|
|
|
target_compile_definitions( tz PRIVATE -DINSTALL=. )
|
2018-01-09 20:09:11 -05:00
|
|
|
endif( )
|
|
|
|
|
2018-06-11 09:14:17 +02:00
|
|
|
if( DISABLE_STRING_VIEW )
|
2019-09-09 14:01:07 +02:00
|
|
|
target_compile_definitions( tz PRIVATE -DHAS_STRING_VIEW=0 )
|
2018-06-11 09:14:17 +02:00
|
|
|
endif( )
|
|
|
|
|
|
|
|
if( BUILD_SHARED_LIBS )
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fPIC")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fPIC")
|
2019-09-09 14:56:01 +02:00
|
|
|
if( WIN32 )
|
|
|
|
target_compile_definitions( tz PRIVATE -DDATE_BUILD_DLL=1 PUBLIC -DDATE_USE_DLL=1 )
|
|
|
|
endif( )
|
2018-06-11 09:14:17 +02:00
|
|
|
endif( )
|
|
|
|
|
2019-09-09 14:01:07 +02:00
|
|
|
target_link_libraries( tz ${CMAKE_THREAD_LIBS_INIT} ${OPTIONAL_LIBRARIES} )
|
2017-11-24 21:34:36 -05:00
|
|
|
|
2017-11-29 15:27:24 +01:00
|
|
|
# add include folders to the library and targets that consume it
|
2019-09-09 14:01:07 +02:00
|
|
|
target_include_directories(tz PUBLIC
|
2019-09-06 15:57:46 +02:00
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${HEADER_FOLDER}>
|
|
|
|
$<INSTALL_INTERFACE:include>
|
2017-11-29 15:27:24 +01:00
|
|
|
)
|
2019-09-06 15:57:46 +02:00
|
|
|
set(version_config "${CMAKE_CURRENT_BINARY_DIR}/dateConfigVersion.cmake")
|
2019-09-09 14:01:07 +02:00
|
|
|
set_target_properties(tz PROPERTIES VERSION "${PROJECT_VERSION}" SOVERSION "${PROJECT_VERSION}")
|
2017-11-29 15:27:24 +01:00
|
|
|
|
2019-09-06 15:57:46 +02:00
|
|
|
include(CMakePackageConfigHelpers)
|
2019-09-09 14:01:07 +02:00
|
|
|
write_basic_package_version_file("${version_config}" VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion)
|
2019-09-06 15:57:46 +02:00
|
|
|
|
2019-09-09 14:01:07 +02:00
|
|
|
# An interface library (not a compiled library), to enable automatic include_directory (for when just date.h,
|
|
|
|
# but not "tz.h and its lib" are needed)
|
|
|
|
add_library(date INTERFACE)
|
2017-12-01 21:15:32 +01:00
|
|
|
|
|
|
|
# add include folders to the INTERFACE and targets that consume it
|
2019-09-09 14:01:07 +02:00
|
|
|
target_include_directories(date INTERFACE
|
2019-09-06 15:57:46 +02:00
|
|
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
2018-01-10 17:03:14 -05:00
|
|
|
$<INSTALL_INTERFACE:include>
|
2017-12-01 21:15:32 +01:00
|
|
|
)
|
|
|
|
|
2018-01-10 17:06:42 -05:00
|
|
|
if(WIN32 AND NOT CYGWIN)
|
|
|
|
set(DEF_INSTALL_CMAKE_DIR CMake)
|
|
|
|
else()
|
2018-03-13 18:22:26 +01:00
|
|
|
set(DEF_INSTALL_CMAKE_DIR ${CMAKE_INSTALL_LIBDIR}/cmake/date)
|
2018-01-10 17:06:42 -05:00
|
|
|
endif()
|
2017-12-01 21:15:32 +01:00
|
|
|
|
2019-09-09 14:01:07 +02:00
|
|
|
install( TARGETS tz EXPORT dateConfig
|
2018-03-13 18:22:26 +01:00
|
|
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
|
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) # This is for Windows
|
2019-09-06 15:57:46 +02:00
|
|
|
|
2019-09-09 14:01:07 +02:00
|
|
|
export(TARGETS date tz NAMESPACE date:: FILE dateConfig.cmake)
|
2019-09-06 15:57:46 +02:00
|
|
|
|
2019-09-09 14:01:07 +02:00
|
|
|
install(TARGETS date EXPORT dateConfig)
|
2019-09-06 15:57:46 +02:00
|
|
|
install(EXPORT dateConfig NAMESPACE date:: DESTINATION ${DEF_INSTALL_CMAKE_DIR})
|
|
|
|
install(DIRECTORY ${HEADER_FOLDER}/ DESTINATION include/)
|
2017-11-24 23:07:39 -05:00
|
|
|
|
2018-01-28 18:40:46 -05:00
|
|
|
if ( ENABLE_DATE_TESTING )
|
|
|
|
|
|
|
|
enable_testing( )
|
|
|
|
|
|
|
|
add_custom_target( testit COMMAND ${CMAKE_CTEST_COMMAND} )
|
|
|
|
|
2019-09-09 14:01:07 +02:00
|
|
|
add_dependencies( testit tz )
|
2018-01-28 18:40:46 -05:00
|
|
|
function( add_pass_tests TEST_GLOB TEST_PREFIX )
|
|
|
|
file( GLOB_RECURSE FILENAMES ${TEST_GLOB} )
|
|
|
|
include_directories( "${HEADER_FOLDER}/date" )
|
|
|
|
|
|
|
|
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} )
|
2019-09-09 14:01:07 +02:00
|
|
|
target_link_libraries( ${BIN_NAME} tz )
|
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 )
|
|
|
|
|
|
|
|
set( TEST_TYPE "_fail" )
|
|
|
|
|
|
|
|
set( PREFIX "${TEST_PREFIX}_fail_${TEST_NAME}" )
|
|
|
|
set( BIN_NAME ${PREFIX}_bin )
|
|
|
|
set( TST_NAME ${PREFIX}_test )
|
|
|
|
|
|
|
|
#target_compile_definitions( ${BIN_NAME} PRIVATE ${TST_NAME} )
|
|
|
|
set( TEST_BIN_NAME ${CMAKE_BINARY_DIR}/${BIN_NAME} )
|
|
|
|
add_custom_target( ${BIN_NAME}
|
|
|
|
COMMAND ${PROJECT_SOURCE_DIR}/compile_fail.sh ${TEST_BIN_NAME} ${CMAKE_CXX_COMPILER} -std=c++14 -L${CMAKE_BINARY_DIR}/ -ltz -I${PROJECT_SOURCE_DIR}/${HEADER_FOLDER}/date -o ${BIN_NAME} ${TEST_FILE}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
|
|
|
COMMENT ${TST_NAME}
|
|
|
|
)
|
|
|
|
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( )
|
|
|
|
|
|
|
|
file( GLOB children RELATIVE "${PROJECT_SOURCE_DIR}/${TEST_FOLDER}" "${PROJECT_SOURCE_DIR}/${TEST_FOLDER}/*" )
|
|
|
|
foreach( child ${children} )
|
|
|
|
if( IS_DIRECTORY "${PROJECT_SOURCE_DIR}/${TEST_FOLDER}/${child}" )
|
|
|
|
set( CUR_FOLDER "${PROJECT_SOURCE_DIR}/${TEST_FOLDER}/${child}" )
|
|
|
|
add_pass_tests( "${CUR_FOLDER}/*.cpp" ${child} )
|
|
|
|
if( NOT WIN32 )
|
|
|
|
add_fail_tests( "${CUR_FOLDER}/*.fail.cpp" ${child} )
|
|
|
|
endif( )
|
|
|
|
endif( )
|
|
|
|
endforeach( )
|
|
|
|
endif( )
|