2022-01-18 06:48:24 +00:00
set ( LIBRARY_DIR "${ClickHouse_SOURCE_DIR}/contrib/cctz" )
set ( SRCS
" $ { L I B R A R Y _ D I R } / s r c / c i v i l _ t i m e _ d e t a i l . c c "
" $ { L I B R A R Y _ D I R } / s r c / t i m e _ z o n e _ f i x e d . c c "
" $ { L I B R A R Y _ D I R } / s r c / t i m e _ z o n e _ f o r m a t . c c "
" $ { L I B R A R Y _ D I R } / s r c / t i m e _ z o n e _ i f . c c "
" $ { L I B R A R Y _ D I R } / s r c / t i m e _ z o n e _ i m p l . c c "
" $ { L I B R A R Y _ D I R } / s r c / t i m e _ z o n e _ i n f o . c c "
" $ { L I B R A R Y _ D I R } / s r c / t i m e _ z o n e _ l i b c . c c "
" $ { L I B R A R Y _ D I R } / s r c / t i m e _ z o n e _ l o o k u p . c c "
" $ { L I B R A R Y _ D I R } / s r c / t i m e _ z o n e _ p o s i x . c c "
" $ { L I B R A R Y _ D I R } / s r c / z o n e _ i n f o _ s o u r c e . c c "
)
2022-01-20 14:11:06 +00:00
add_library ( _cctz ${ SRCS } )
target_include_directories ( _cctz PUBLIC "${LIBRARY_DIR}/include" )
2022-01-18 06:48:24 +00:00
if ( OS_FREEBSD )
# yes, need linux, because bsd check inside linux in time_zone_libc.cc:24
2022-01-20 14:11:06 +00:00
target_compile_definitions ( _cctz PRIVATE __USE_BSD linux _XOPEN_SOURCE=600 )
2017-11-02 18:55:52 +00:00
endif ( )
2022-01-18 06:48:24 +00:00
# Related to time_zones table:
2023-07-23 03:25:14 +00:00
# TimeZones.generated.cpp is autogenerated each time during a build
set ( TIMEZONES_FILE "${CMAKE_CURRENT_BINARY_DIR}/TimeZones.generated.cpp" )
2022-01-18 06:48:24 +00:00
# remove existing copies so that its generated fresh on each build.
2023-07-23 03:25:14 +00:00
file ( REMOVE ${ TIMEZONES_FILE } )
2022-01-18 06:48:24 +00:00
# get the list of timezones from tzdata shipped with cctz
set ( TZDIR "${LIBRARY_DIR}/testdata/zoneinfo" )
file ( STRINGS "${LIBRARY_DIR}/testdata/version" TZDATA_VERSION )
set_property ( GLOBAL PROPERTY TZDATA_VERSION_PROP "${TZDATA_VERSION}" )
message ( STATUS "Packaging with tzdata version: ${TZDATA_VERSION}" )
# each file in that dir (except of tab and localtime) store the info about timezone
execute_process ( COMMAND
b a s h - c " c d $ { T Z D I R } & & f i n d * - t y p e f - a n d ! - n a m e ' * . t a b ' - a n d ! - n a m e ' l o c a l t i m e ' | L C _ A L L = C s o r t | p a s t e - s d ' ; ' - "
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
O U T P U T _ V A R I A B L E T I M E Z O N E S )
2023-07-23 03:25:14 +00:00
file ( APPEND ${ TIMEZONES_FILE } "// autogenerated by ClickHouse/contrib/cctz-cmake/CMakeLists.txt\n" )
file ( APPEND ${ TIMEZONES_FILE } "#include <incbin.h>\n" )
2022-01-18 06:48:24 +00:00
2023-07-23 03:25:14 +00:00
set ( COUNTER 1 )
2022-01-18 06:48:24 +00:00
foreach ( TIMEZONE ${ TIMEZONES } )
2023-07-23 22:03:40 +00:00
file ( APPEND ${ TIMEZONES_FILE } "INCBIN(resource_timezone${COUNTER}, \" ${ TZDIR } / ${ TIMEZONE } \");\n")
2023-07-23 03:25:14 +00:00
MATH ( EXPR COUNTER "${COUNTER}+1" )
2022-01-18 06:48:24 +00:00
endforeach ( TIMEZONE )
2023-07-23 03:25:14 +00:00
2023-07-23 04:09:15 +00:00
file ( APPEND ${ TIMEZONES_FILE } "const char * auto_time_zones[] {\n" )
foreach ( TIMEZONE ${ TIMEZONES } )
file ( APPEND ${ TIMEZONES_FILE } " \" ${ TIMEZONE } \",\n")
MATH ( EXPR COUNTER "${COUNTER}+1" )
endforeach ( TIMEZONE )
2023-07-23 19:00:28 +00:00
file ( APPEND ${ TIMEZONES_FILE } " nullptr\n};\n\n" )
2023-07-23 04:09:15 +00:00
file ( APPEND ${ TIMEZONES_FILE } "#include <string_view>\n\n" )
file ( APPEND ${ TIMEZONES_FILE } "std::string_view getTimeZone(const char * name)\n{\n" )
2023-07-23 03:25:14 +00:00
set ( COUNTER 1 )
foreach ( TIMEZONE ${ TIMEZONES } )
2023-07-23 04:09:15 +00:00
file ( APPEND ${ TIMEZONES_FILE } " if (std::string_view(\" ${ TIMEZONE } \") == name ) r e t u r n { r e i n t e r p r e t _ c a s t < c o n s t c h a r * > ( g r e s o u r c e _ t i m e z o n e $ { C O U N T E R } D a t a ) , g r e s o u r c e _ t i m e z o n e $ { C O U N T E R } S i z e } ; \ n " )
2023-07-23 03:25:14 +00:00
MATH ( EXPR COUNTER "${COUNTER}+1" )
endforeach ( TIMEZONE )
2023-07-23 04:09:15 +00:00
file ( APPEND ${ TIMEZONES_FILE } " return {};\n" )
file ( APPEND ${ TIMEZONES_FILE } "}\n" )
2023-07-23 03:25:14 +00:00
add_library ( tzdata ${ TIMEZONES_FILE } )
target_link_libraries ( tzdata ch_contrib::incbin )
target_link_libraries ( _cctz tzdata )
2022-01-18 06:48:24 +00:00
2022-01-20 14:11:06 +00:00
add_library ( ch_contrib::cctz ALIAS _cctz )