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

[date] Add official CMake targets support #8151

Merged
merged 1 commit into from
Sep 17, 2019
Merged
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
13 changes: 13 additions & 0 deletions ports/date/0001-fix-uwp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git i/include/date/date.h w/include/date/date.h
index fce6200..6a77ad4 100644
--- i/include/date/date.h
+++ w/include/date/date.h
@@ -82,7 +82,7 @@
#ifdef _MSC_VER
# pragma warning(push)
// warning C4127: conditional expression is constant
-# pragma warning(disable : 4127)
+# pragma warning(disable : 4127 4996)
#endif

namespace date
44 changes: 0 additions & 44 deletions ports/date/CMakeLists.txt

This file was deleted.

4 changes: 2 additions & 2 deletions ports/date/CONTROL
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Source: date
Version: 2019-05-18-1
Version: 2019-09-09
Homepage: https://github.com/HowardHinnant/date
Description: A date and time library based on the C++11/14/17 <chrono> header
Description: A date and time library based on the C++17 <chrono> header

Feature: remote-api
Description: support automatic download of tz data
Expand Down
36 changes: 19 additions & 17 deletions ports/date/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,39 @@ endif()
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO HowardHinnant/date
REF ed0368fc75427ef05cefdf19a39b60d7bed2f039
SHA512 5f6a0d7e094fd1ab7b6a1ea9a96e467138220e9207e2eda68f71b68d6c56759e7470fabdfa920d92876e9c9b466e56ea8102333f407a46bb4cba43a2dfeb5e3a
REF 44344000f0fa32e66787d6d2c9ff5ddfd3605df7
SHA512 1ec75a4b6310f735261c996c63df8176f0523d8f59a23edd49fd8efbdcbf1e78051ba2f36df0920f6f5e6bbc8f81ea4639f73e05bb1cb7f97a8e500bde667782
HEAD_REF master
PATCHES "${CMAKE_CURRENT_LIST_DIR}/0001-fix-uwp.patch"
)

file(COPY ${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt DESTINATION ${SOURCE_PATH})

set(HAS_REMOTE_API 0)
set(DATE_USE_SYSTEM_TZ_DB 1)
if("remote-api" IN_LIST FEATURES)
set(HAS_REMOTE_API 1)
set(DATE_USE_SYSTEM_TZ_DB 0)
endif()

vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS -DHAS_REMOTE_API=${HAS_REMOTE_API}
OPTIONS_DEBUG -DDISABLE_INSTALL_HEADERS=ON
OPTIONS
-DUSE_SYSTEM_TZ_DB=${DATE_USE_SYSTEM_TZ_DB}
-DENABLE_DATE_TESTING=OFF
)

vcpkg_install_cmake()

vcpkg_fixup_cmake_targets(CONFIG_PATH share/unofficial-date TARGET_PATH share/unofficial-date)
if(NOT VCPKG_CMAKE_SYSTEM_NAME OR VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
vcpkg_fixup_cmake_targets(CONFIG_PATH CMake TARGET_PATH share/date)
else()
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake/date TARGET_PATH share/date)
endif()

vcpkg_copy_pdbs()

set(HEADER "${CURRENT_PACKAGES_DIR}/include/date/tz.h")
file(READ "${HEADER}" _contents)
string(REPLACE "#define TZ_H" "#define TZ_H\n#undef HAS_REMOTE_API\n#define HAS_REMOTE_API ${HAS_REMOTE_API}" _contents "${_contents}")
if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
string(REPLACE "ifdef DATE_BUILD_DLL" "if 1" _contents "${_contents}")
endif()
file(WRITE "${HEADER}" "${_contents}")

file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include)
file(INSTALL ${SOURCE_PATH}/LICENSE.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/date RENAME copyright)
file(INSTALL ${CMAKE_CURRENT_LIST_DIR}/usage DESTINATION ${CURRENT_PACKAGES_DIR}/share/date)

# Remove the wrapper when backwards compatibility with the unofficial::date::date and unofficial::date::tz
# targets is no longer required.
file(INSTALL ${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/share/date)
4 changes: 4 additions & 0 deletions ports/date/usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The package date provides CMake targets:

find_package(date CONFIG REQUIRED)
target_link_libraries(main PRIVATE date::date date::tz)
11 changes: 11 additions & 0 deletions ports/date/vcpkg-cmake-wrapper.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
_find_package(${ARGS})

if(NOT TARGET unofficial::date::date AND TARGET date::date)
add_library(unofficial::date::date INTERFACE IMPORTED)
target_link_libraries(unofficial::date::date INTERFACE date::date)
endif()

if(NOT TARGET unofficial::date::tz AND TARGET date::tz)
add_library(unofficial::date::tz INTERFACE IMPORTED)
target_link_libraries(unofficial::date::tz INTERFACE date::tz)
endif()