Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create iso_week header only library in cmake-file #503

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 61 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,20 @@ target_include_directories( date INTERFACE
# 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:
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include/date/solar_hijri.h>
$<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>
)

add_library(extra INTERFACE)
add_library(date::extra ALIAS extra)
target_sources(extra INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>$<INSTALL_INTERFACE:include>/date/solar_hijri.h
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>$<INSTALL_INTERFACE:include>/date/islamic.h
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>$<INSTALL_INTERFACE:include>/date/julian.h
)

if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
# public headers will get installed:
set_target_properties( date PROPERTIES PUBLIC_HEADER include/date/date.h )
set_target_properties( date PROPERTIES PUBLIC_HEADER include/date/date.h)
set_target_properties( extra PROPERTIES PUBLIC_HEADER "include/date/islamic.h;include/date/solar_hijri.h;include/date/julian.h")
endif ()

# These used to be set with generator expressions,
Expand All @@ -97,6 +102,24 @@ if ( DISABLE_STRING_VIEW )
target_compile_definitions( date INTERFACE HAS_STRING_VIEW=0 -DHAS_DEDUCTION_GUIDES=0 )
endif()

#[===================================================================[
iso_week (header only) library
#]===================================================================]
add_library( iso_week INTERFACE )
add_library( date::iso_week ALIAS iso_week )
target_include_directories( iso_week INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include> )
target_sources( iso_week INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>$<INSTALL_INTERFACE:include>/date/iso_week.h
)
# public headers will get installed:
set_target_properties( iso_week PROPERTIES PUBLIC_HEADER include/date/iso_week.h )
target_compile_definitions( iso_week INTERFACE
#To workaround libstdc++ issue https://github.com/HowardHinnant/date/issues/388
ONLY_C_LOCALE=$<IF:$<BOOL:${COMPILE_WITH_C_LOCALE}>,1,0>
$<$<BOOL:${DISABLE_STRING_VIEW}>:HAS_STRING_VIEW=0> )

#[===================================================================[
tz (compiled) library
#]===================================================================]
Expand All @@ -108,6 +131,7 @@ if( BUILD_TZ_LIB )
PRIVATE
include/date/tz_private.h
src/tz.cpp )

if ( IOS )
target_sources( date-tz
PUBLIC
Expand Down Expand Up @@ -147,10 +171,10 @@ if( BUILD_TZ_LIB )
PUBLIC_HEADER "${TZ_HEADERS}"
VERSION "${PROJECT_VERSION}"
SOVERSION "${ABI_VERSION}" )
if( NOT MSVC )
find_package( Threads )
target_link_libraries( date-tz PUBLIC Threads::Threads )
endif( )

find_package( Threads )
target_link_libraries( date-tz PUBLIC Threads::Threads )

if( NOT USE_SYSTEM_TZ_DB AND NOT MANUAL_TZ_DB )
find_package( CURL REQUIRED )
target_include_directories( date-tz SYSTEM PRIVATE ${CURL_INCLUDE_DIRS} )
Expand All @@ -169,13 +193,30 @@ write_basic_package_version_file( "${version_config}"
COMPATIBILITY SameMajorVersion )

install( TARGETS date
EXPORT dateConfig
EXPORT dateTargets
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/date )
export( TARGETS date NAMESPACE date:: FILE dateTargets.cmake )

install( TARGETS extra
EXPORT dateTargets
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/date)
export(TARGETS extra NAMESPACE date:: APPEND FILE dateTargets.cmake)

install( TARGETS iso_week
EXPORT dateTargets
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/date )
export( TARGETS iso_week NAMESPACE date:: APPEND FILE dateTargets.cmake )


if (CMAKE_VERSION VERSION_LESS 3.15)
install(
FILES include/date/date.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/date )

install(
FILES include/date/islamic.h include/date/solar_hijri.h include/date/julian.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/date )

endif ()

if( BUILD_TZ_LIB )
Expand All @@ -185,6 +226,7 @@ if( BUILD_TZ_LIB )
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) # This is for Windows

export( TARGETS date-tz NAMESPACE date:: APPEND FILE dateTargets.cmake )
endif( )

Expand All @@ -193,13 +235,17 @@ if( WIN32 AND NOT CYGWIN)
else( )
set( CONFIG_LOC "${CMAKE_INSTALL_LIBDIR}/cmake/date" )
endif( )
install( EXPORT dateConfig

install( EXPORT dateTargets
FILE dateTargets.cmake
NAMESPACE date::
DESTINATION ${CONFIG_LOC} )
install (
FILES cmake/dateConfig.cmake "${version_config}"
DESTINATION ${CONFIG_LOC})

configure_file(cmake/dateConfig.cmake.in dateConfig.cmake @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/dateConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/dateConfigVersion.cmake"
DESTINATION ${CONFIG_LOC}
)

#[===================================================================[
testing
Expand Down
13 changes: 13 additions & 0 deletions cmake/dateConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
include(CMakeFindDependencyMacro)

set(USE_SYSTEM_TZ_DB @USE_SYSTEM_TZ_DB@)
set(BUILD_TZ_LIB @BUILD_TZ_LIB@)

find_dependency( Threads REQUIRED )

if( NOT USE_SYSTEM_TZ_DB )
find_dependency( CURL REQUIRED )
endif( )

include("${CMAKE_CURRENT_LIST_DIR}/dateTargets.cmake")

4 changes: 2 additions & 2 deletions include/date/iso_week.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ inline
unsigned char
weekday::to_iso_encoding(unsigned char z) NOEXCEPT
{
return z != 0 ? z : (unsigned char)7;
return z != 0 ? z : static_cast<unsigned char>(7);
}

CONSTCD11
Expand Down Expand Up @@ -451,7 +451,7 @@ weekday::weekday(unsigned wd) NOEXCEPT
CONSTCD11
inline
weekday::weekday(date::weekday wd) NOEXCEPT
: wd_(wd.iso_encoding())
: wd_(static_cast<decltype(wd_)>(wd.iso_encoding()))
{}

CONSTCD11
Expand Down