2017-11-26 23:09:46 -05:00
|
|
|
cmake_minimum_required( VERSION 3.0.2 )
|
2017-11-24 21:34:36 -05:00
|
|
|
|
|
|
|
project( date_prj )
|
|
|
|
|
2017-11-24 23:07:39 -05:00
|
|
|
find_package( Threads REQUIRED )
|
2017-11-24 21:34:36 -05:00
|
|
|
|
2017-11-26 23:09:46 -05:00
|
|
|
enable_testing( )
|
2017-11-24 21:34:36 -05:00
|
|
|
|
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 )
|
2017-11-24 23:24:19 -05:00
|
|
|
option( BUILD_STATIC "Build a static version of library" ON )
|
2017-11-24 21:34:36 -05:00
|
|
|
|
|
|
|
if( USE_SYSTEM_TZ_DB )
|
|
|
|
add_definitions( -DUSE_AUTOLOAD=0 )
|
|
|
|
add_definitions( -DHAS_REMOTE_API=0 )
|
2017-11-24 23:58:18 -05:00
|
|
|
# cannot set USE_OS_TZDB to 1 on Windows
|
2017-11-24 23:54:38 -05:00
|
|
|
if( NOT WIN32 )
|
|
|
|
add_definitions( -DUSE_OS_TZDB=1 )
|
|
|
|
endif( )
|
2017-11-24 21:34:36 -05:00
|
|
|
else( )
|
2017-11-24 23:07:39 -05:00
|
|
|
add_definitions( -DUSE_AUTOLOAD=1 )
|
|
|
|
add_definitions( -DHAS_REMOTE_API=1 )
|
|
|
|
add_definitions( -DUSE_OS_TZDB=0 )
|
2017-11-24 21:34:36 -05:00
|
|
|
find_package( CURL REQUIRED )
|
2017-11-26 15:44:22 -05:00
|
|
|
include_directories( SYSTEM )
|
2017-11-24 21:34:36 -05:00
|
|
|
include_directories( SYSTEM ${CURL_INCLUDE_DIRS} )
|
2017-11-26 15:44:22 -05:00
|
|
|
set( OPTIONAL_LIBRARIES ${CURL_LIBRARIES} )
|
2017-11-24 21:34:36 -05:00
|
|
|
endif( )
|
|
|
|
|
2017-11-24 23:07:39 -05:00
|
|
|
if( USE_TZ_DB_IN_DOT )
|
|
|
|
add_definitions( -DINSTALL=. )
|
|
|
|
endif( )
|
|
|
|
|
2017-11-24 21:34:36 -05:00
|
|
|
set( HEADER_FOLDER "include" )
|
|
|
|
set( SOURCE_FOLDER "src" )
|
|
|
|
set( TEST_FOLDER "test" )
|
|
|
|
|
|
|
|
include_directories( ${HEADER_FOLDER} )
|
|
|
|
|
|
|
|
# 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
|
|
|
|
)
|
|
|
|
|
2017-11-24 23:24:19 -05:00
|
|
|
if( BUILD_STATIC )
|
|
|
|
add_library( tz STATIC ${HEADER_FILES} ${SOURCE_FOLDER}/tz.cpp )
|
|
|
|
else( )
|
|
|
|
add_library( tz SHARED ${HEADER_FILES} ${SOURCE_FOLDER}/tz.cpp )
|
|
|
|
endif( )
|
2017-11-24 21:34:36 -05:00
|
|
|
set_property(TARGET tz PROPERTY CXX_STANDARD 14)
|
|
|
|
target_link_libraries( tz ${CMAKE_THREAD_LIBS_INIT} ${OPTIONAL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} )
|
|
|
|
|
|
|
|
install( TARGETS tz DESTINATION lib )
|
|
|
|
install( DIRECTORY ${HEADER_FOLDER}/ DESTINATION include/ )
|
2017-11-24 23:07:39 -05:00
|
|
|
|
2017-11-26 23:09:46 -05:00
|
|
|
add_custom_target( testit COMMAND ${CMAKE_CTEST_COMMAND} )
|
|
|
|
|
|
|
|
add_dependencies( testit tz )
|
|
|
|
function( add_pass_tests TEST_GLOB TEST_PREFIX )
|
2017-11-27 00:00:14 -05:00
|
|
|
file( GLOB_RECURSE FILENAMES ${TEST_GLOB} )
|
2017-11-26 23:09:46 -05:00
|
|
|
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 )
|
|
|
|
|
|
|
|
set( PREFIX "${TEST_PREFIX}_${TEST_NAME}_pass" )
|
|
|
|
set( BIN_NAME ${PREFIX}_bin )
|
|
|
|
set( TST_NAME ${PREFIX}_test )
|
|
|
|
add_executable( ${BIN_NAME} EXCLUDE_FROM_ALL ${TEST_FILE} )
|
|
|
|
set_property(TARGET ${BIN_NAME} PROPERTY CXX_STANDARD 14)
|
|
|
|
add_test( ${TST_NAME} ${BIN_NAME} )
|
|
|
|
target_link_libraries( ${BIN_NAME} tz )
|
|
|
|
add_dependencies( testit ${BIN_NAME} )
|
|
|
|
endforeach( )
|
|
|
|
endfunction( )
|
|
|
|
|
|
|
|
function( add_fail_tests TEST_GLOB TEST_PREFIX )
|
2017-11-27 00:00:14 -05:00
|
|
|
file( GLOB_RECURSE FILENAMES ${TEST_GLOB} )
|
2017-11-26 23:09:46 -05:00
|
|
|
|
|
|
|
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}_${TEST_NAME}_fail" )
|
|
|
|
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( )
|
|
|
|
|
2017-11-27 00:00:14 -05:00
|
|
|
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}/*.pass.cpp" ${child} )
|
|
|
|
if( NOT WIN32 )
|
|
|
|
add_fail_tests( "${CUR_FOLDER}/*.fail.cpp" ${child} )
|
|
|
|
endif( )
|
|
|
|
endif( )
|
|
|
|
endforeach( )
|
2017-11-26 23:09:46 -05:00
|
|
|
|