From 72fb0d204dd50aeb14eeb2e8b562ca7c8bb53a3a Mon Sep 17 00:00:00 2001 From: Connor Jakubik Date: Wed, 11 Nov 2020 12:46:32 -0600 Subject: [PATCH 1/2] Resolve #618 (Specify TZDB location via CMake) I went ahead and renamed `INSTALL` to `TZDB_INSTALL_PATH` to reduce possibility of name conflicts. --- CMakeLists.txt | 10 ++++++++++ src/tz.cpp | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 012512ae..0faeb803 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,9 @@ option( ENABLE_DATE_TESTING "Enable unit tests" OFF ) option( DISABLE_STRING_VIEW "Disable string view" OFF ) option( COMPILE_WITH_C_LOCALE "define ONLY_C_LOCALE=1" OFF ) option( BUILD_TZ_LIB "build/install of TZ library" OFF ) +option( USE_CUSTOM_TZDB_INSTALL_PATH "Use a custom path for finding the tzdata folder" OFF ) +# The location of the database is CUSTOM_TZDB_INSTALL_PATH/tzdata (CUSTOM_TZDB_INSTALL_PATH\tzdata on Windows) +set(CUSTOM_TZDB_INSTALL_PATH ".") if( ENABLE_DATE_TESTING AND NOT BUILD_TZ_LIB ) message(WARNING "Testing requested, bug BUILD_TZ_LIB not ON - forcing the latter") @@ -55,6 +58,10 @@ print_option( USE_TZ_DB_IN_DOT ) print_option( BUILD_SHARED_LIBS ) print_option( ENABLE_DATE_TESTING ) print_option( DISABLE_STRING_VIEW ) +print_option( USE_CUSTOM_TZDB_INSTALL_PATH ) +if(USE_CUSTOM_TZDB_INSTALL_PATH) + message("# date: CUSTOM_TZDB_INSTALL_PATH ${CUSTOM_TZDB_INSTALL_PATH}") +endif() #[===================================================================[ date (header only) library @@ -96,6 +103,9 @@ endif() if ( DISABLE_STRING_VIEW ) target_compile_definitions( date INTERFACE HAS_STRING_VIEW=0 -DHAS_DEDUCTION_GUIDES=0 ) endif() +if ( USE_CUSTOM_TZDB_INSTALL_PATH ) + target_compile_definitions( date INTERFACE TZDB_INSTALL_PATH=${CUSTOM_TZDB_INSTALL_PATH} ) +endif() #[===================================================================[ tz (compiled) library diff --git a/src/tz.cpp b/src/tz.cpp index 7cbdbcb9..c8bea132 100644 --- a/src/tz.cpp +++ b/src/tz.cpp @@ -123,7 +123,7 @@ # include # if WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP # define WINRT -# define INSTALL . +# define TZDB_INSTALL_PATH . # endif # endif @@ -141,7 +141,7 @@ # endif // HAS_REMOTE_API #else // !_WIN32 # include -# if !USE_OS_TZDB && !defined(INSTALL) +# if !USE_OS_TZDB && !defined(TZDB_INSTALL_PATH) # include # endif # include @@ -222,7 +222,7 @@ get_known_folder(const GUID& folderid) return folder; } -# ifndef INSTALL +# ifndef TZDB_INSTALL_PATH // Usually something like "c:\Users\username\Downloads". static @@ -232,12 +232,12 @@ get_download_folder() return get_known_folder(FOLDERID_Downloads); } -# endif // !INSTALL +# endif // !TZDB_INSTALL_PATH # endif // WINRT # else // !_WIN32 -# if !defined(INSTALL) +# if !defined(TZDB_INSTALL_PATH) static std::string @@ -263,7 +263,7 @@ get_download_folder() return expand_path("~/Downloads"); } -# endif // !defined(INSTALL) +# endif // !defined(TZDB_INSTALL_PATH) # endif // !_WIN32 @@ -284,20 +284,20 @@ std::string& access_install() { static std::string install -#ifndef INSTALL +#ifndef TZDB_INSTALL_PATH = get_download_folder() + folder_delimiter + "tzdata"; -#else // !INSTALL +#else // !TZDB_INSTALL_PATH # define STRINGIZEIMP(x) #x # define STRINGIZE(x) STRINGIZEIMP(x) - = STRINGIZE(INSTALL) + std::string(1, folder_delimiter) + "tzdata"; + = STRINGIZE(TZDB_INSTALL_PATH) + std::string(1, folder_delimiter) + "tzdata"; #undef STRINGIZEIMP #undef STRINGIZE -#endif // !INSTALL +#endif // !TZDB_INSTALL_PATH return install; } From 9b6e713114989a44c36b766b111666b68fbb3675 Mon Sep 17 00:00:00 2001 From: Connor Jakubik Date: Wed, 11 Nov 2020 17:01:28 -0600 Subject: [PATCH 2/2] Revert change to INSTALL macro --- CMakeLists.txt | 3 ++- src/tz.cpp | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0faeb803..8d932903 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,7 @@ option( ENABLE_DATE_TESTING "Enable unit tests" OFF ) option( DISABLE_STRING_VIEW "Disable string view" OFF ) option( COMPILE_WITH_C_LOCALE "define ONLY_C_LOCALE=1" OFF ) option( BUILD_TZ_LIB "build/install of TZ library" OFF ) +# Only works when MANUAL_TZ_DB = ON option( USE_CUSTOM_TZDB_INSTALL_PATH "Use a custom path for finding the tzdata folder" OFF ) # The location of the database is CUSTOM_TZDB_INSTALL_PATH/tzdata (CUSTOM_TZDB_INSTALL_PATH\tzdata on Windows) set(CUSTOM_TZDB_INSTALL_PATH ".") @@ -104,7 +105,7 @@ if ( DISABLE_STRING_VIEW ) target_compile_definitions( date INTERFACE HAS_STRING_VIEW=0 -DHAS_DEDUCTION_GUIDES=0 ) endif() if ( USE_CUSTOM_TZDB_INSTALL_PATH ) - target_compile_definitions( date INTERFACE TZDB_INSTALL_PATH=${CUSTOM_TZDB_INSTALL_PATH} ) + target_compile_definitions( date INTERFACE INSTALL=${CUSTOM_TZDB_INSTALL_PATH} ) endif() #[===================================================================[ diff --git a/src/tz.cpp b/src/tz.cpp index c8bea132..7cbdbcb9 100644 --- a/src/tz.cpp +++ b/src/tz.cpp @@ -123,7 +123,7 @@ # include # if WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP # define WINRT -# define TZDB_INSTALL_PATH . +# define INSTALL . # endif # endif @@ -141,7 +141,7 @@ # endif // HAS_REMOTE_API #else // !_WIN32 # include -# if !USE_OS_TZDB && !defined(TZDB_INSTALL_PATH) +# if !USE_OS_TZDB && !defined(INSTALL) # include # endif # include @@ -222,7 +222,7 @@ get_known_folder(const GUID& folderid) return folder; } -# ifndef TZDB_INSTALL_PATH +# ifndef INSTALL // Usually something like "c:\Users\username\Downloads". static @@ -232,12 +232,12 @@ get_download_folder() return get_known_folder(FOLDERID_Downloads); } -# endif // !TZDB_INSTALL_PATH +# endif // !INSTALL # endif // WINRT # else // !_WIN32 -# if !defined(TZDB_INSTALL_PATH) +# if !defined(INSTALL) static std::string @@ -263,7 +263,7 @@ get_download_folder() return expand_path("~/Downloads"); } -# endif // !defined(TZDB_INSTALL_PATH) +# endif // !defined(INSTALL) # endif // !_WIN32 @@ -284,20 +284,20 @@ std::string& access_install() { static std::string install -#ifndef TZDB_INSTALL_PATH +#ifndef INSTALL = get_download_folder() + folder_delimiter + "tzdata"; -#else // !TZDB_INSTALL_PATH +#else // !INSTALL # define STRINGIZEIMP(x) #x # define STRINGIZE(x) STRINGIZEIMP(x) - = STRINGIZE(TZDB_INSTALL_PATH) + std::string(1, folder_delimiter) + "tzdata"; + = STRINGIZE(INSTALL) + std::string(1, folder_delimiter) + "tzdata"; #undef STRINGIZEIMP #undef STRINGIZE -#endif // !TZDB_INSTALL_PATH +#endif // !INSTALL return install; }