From fc4cf092f9674f2670fb9177edcdee870399b829 Mon Sep 17 00:00:00 2001 From: Michael Ellery Date: Sun, 29 Dec 2019 11:51:04 -0800 Subject: [PATCH] Fix cmake install for 3.14 or earlier (3.7 min) (#522) * Fix cmake install for 3.14 or earlier (3.7 min) Fixes: #504, #505 * Add find_dependency to config file FIXES: #514 --- CMakeLists.txt | 23 ++++++++++++++++------- cmake/dateConfig.cmake | 11 +++++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 cmake/dateConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 885e424..8e243ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,9 +15,7 @@ #]===================================================================] -cmake_minimum_required( VERSION 3.1.0 ) - -cmake_policy( VERSION 3.14 ) +cmake_minimum_required( VERSION 3.7 ) project( date VERSION 2.4.1 ) @@ -71,8 +69,10 @@ target_sources( date INTERFACE $ $ ) -# public headers will get installed: -set_target_properties( date PROPERTIES PUBLIC_HEADER include/date/date.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 ) +endif () target_compile_definitions( date INTERFACE #To workaround libstdc++ issue https://github.com/HowardHinnant/date/issues/388 ONLY_C_LOCALE=$,1,0> @@ -138,7 +138,12 @@ write_basic_package_version_file( "${version_config}" install( TARGETS date EXPORT dateConfig PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/date ) -export( TARGETS date NAMESPACE date:: FILE dateConfig.cmake ) +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 () if( BUILD_TZ_LIB ) install( TARGETS tz @@ -147,7 +152,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 tz NAMESPACE date:: APPEND FILE dateConfig.cmake ) + export( TARGETS tz NAMESPACE date:: APPEND FILE dateTargets.cmake ) endif( ) if( WIN32 AND NOT CYGWIN) @@ -156,8 +161,12 @@ else( ) set( CONFIG_LOC "${CMAKE_INSTALL_LIBDIR}/cmake/date" ) endif( ) install( EXPORT dateConfig + FILE dateTargets.cmake NAMESPACE date:: DESTINATION ${CONFIG_LOC} ) +install ( + FILES cmake/dateConfig.cmake "${version_config}" + DESTINATION ${CONFIG_LOC}) #[===================================================================[ testing diff --git a/cmake/dateConfig.cmake b/cmake/dateConfig.cmake new file mode 100644 index 0000000..20f86e8 --- /dev/null +++ b/cmake/dateConfig.cmake @@ -0,0 +1,11 @@ +include( CMakeFindDependencyMacro ) +include( "${CMAKE_CURRENT_LIST_DIR}/dateTargets.cmake" ) +if( NOT MSVC AND TARGET date::tz ) + find_dependency( Threads REQUIRED) + get_target_property( _tzill date::tz INTERFACE_LINK_LIBRARIES ) + if( _tzill AND "${_tzill}" MATCHES "libcurl" ) + find_dependency( CURL ) + endif( ) +endif( ) + +