From b5dc9ac015afd88f87126b8d5a5c6e50c6f51ba5 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 17 Jan 2024 15:47:37 -0500 Subject: [PATCH 1/6] cmake: Check program existence with CMake standards --- externals/tz/CMakeLists.txt | 2 +- src/tzdb/CMakeLists.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/externals/tz/CMakeLists.txt b/externals/tz/CMakeLists.txt index c1288e7..3fa28e4 100644 --- a/externals/tz/CMakeLists.txt +++ b/externals/tz/CMakeLists.txt @@ -5,7 +5,7 @@ set(TZ_ZONEINFO_DIR "${TZ_DIR}/usr/share/zoneinfo" CACHE PATH "Time zone info da set(TZIF_LIST_FILE "${CMAKE_CURRENT_BINARY_DIR}/tzif_list.txt" CACHE PATH "List of zone info files") find_program(GNU_MAKE make) -if ("${GNU_MAKE}" STREQUAL "GNU_MAKE-NOTFOUND") +if (NOT GNU_MAKE) message(FATAL_ERROR "GNU make not found") endif() diff --git a/src/tzdb/CMakeLists.txt b/src/tzdb/CMakeLists.txt index 119002b..baf3a88 100644 --- a/src/tzdb/CMakeLists.txt +++ b/src/tzdb/CMakeLists.txt @@ -1,10 +1,10 @@ find_program(GIT_PROGRAM git) -if ("${GIT_PROGRAM}" STREQUAL "GIT_PROGRAM-NOTFOUND") +if (NOT GIT_PROGRAM) message(FATAL_ERROR "git program not found") endif() find_program(GNU_DATE date) -if ("${GNU_DATE}" STREQUAL "GNU_DATE-NOTFOUND") +if (NOT GNU_DATE) message(FATAL_ERROR "date program not found") endif() From 14733f4575befc3e9fa782d1548933f56b0ca703 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:12:17 -0500 Subject: [PATCH 2/6] cmake: Use git clone instead of file copy Preserves (enough) git repository data for configuration to work without error. --- externals/tz/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/externals/tz/CMakeLists.txt b/externals/tz/CMakeLists.txt index 3fa28e4..48bc9c0 100644 --- a/externals/tz/CMakeLists.txt +++ b/externals/tz/CMakeLists.txt @@ -12,7 +12,11 @@ endif() if (NOT EXISTS "${TZ_DIR}" OR NOT EXISTS "${TZIF_LIST_FILE}") # tz's makefile can only build in-tree, so copy the whole source tree to a # separate directory before building. - file(COPY ${TZ_SOURCE_DIR}/ DESTINATION ${TZ_TMP_SOURCE_DIR}) + execute_process( + COMMAND + ${GIT_PROGRAM} clone --depth 1 "file://${TZ_SOURCE_DIR}" "${TZ_TMP_SOURCE_DIR}" + COMMAND_ERROR_IS_FATAL ANY + ) if (APPLE) set(TZ_MAKEFLAGS "LDLIBS=${Intl_LIBRARY}") From 76de8f411590519de6b17115453149ef040b6969 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:16:04 -0500 Subject: [PATCH 3/6] cmake: Add option to specify custom zoneinfo Enables developers to use a different zoneinfo source than the included submodule. --- CMakeLists.txt | 2 + externals/tz/CMakeLists.txt | 73 +++++++++++++++++++++---------------- 2 files changed, 44 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9986f6d..e15cb29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.10) project(tzdb2nx VERSION 1.0) +option(TZDB2NX_ZONEINFO_DIR "Specify a custom zoneinfo directory containing time zone data you wish to use" "") + set(CMAKE_CXX_STANDARD 20) if (APPLE) diff --git a/externals/tz/CMakeLists.txt b/externals/tz/CMakeLists.txt index 48bc9c0..c3ceeda 100644 --- a/externals/tz/CMakeLists.txt +++ b/externals/tz/CMakeLists.txt @@ -1,48 +1,59 @@ set(TZ_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tz" CACHE PATH "Time zone source directory") set(TZ_DIR "${CMAKE_CURRENT_BINARY_DIR}/tz") set(TZ_TMP_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/tmpsrc") -set(TZ_ZONEINFO_DIR "${TZ_DIR}/usr/share/zoneinfo" CACHE PATH "Time zone info data directory") set(TZIF_LIST_FILE "${CMAKE_CURRENT_BINARY_DIR}/tzif_list.txt" CACHE PATH "List of zone info files") +if (TZDB2NX_ZONEINFO_DIR) + set(TZ_ZONEINFO_DIR "${TZDB2NX_ZONEINFO_DIR}" CACHE PATH "Time zone info data directory") +else() + set(TZ_ZONEINFO_DIR "${TZ_DIR}/usr/share/zoneinfo" CACHE PATH "Time zone info data directory") +endif() find_program(GNU_MAKE make) if (NOT GNU_MAKE) message(FATAL_ERROR "GNU make not found") endif() +find_program(GIT_PROGRAM git) +if (NOT GIT_PROGRAM) + message(FATAL_ERROR "git program not found") +endif() + if (NOT EXISTS "${TZ_DIR}" OR NOT EXISTS "${TZIF_LIST_FILE}") - # tz's makefile can only build in-tree, so copy the whole source tree to a - # separate directory before building. - execute_process( - COMMAND - ${GIT_PROGRAM} clone --depth 1 "file://${TZ_SOURCE_DIR}" "${TZ_TMP_SOURCE_DIR}" - COMMAND_ERROR_IS_FATAL ANY - ) + if (NOT TZDB2NX_ZONEINFO_DIR) + # tz's makefile can only build in-tree, so copy the whole source tree to a + # separate directory before building. + execute_process( + COMMAND + ${GIT_PROGRAM} clone --depth 1 "file://${TZ_SOURCE_DIR}" "${TZ_TMP_SOURCE_DIR}" + COMMAND_ERROR_IS_FATAL ANY + ) - if (APPLE) - set(TZ_MAKEFLAGS "LDLIBS=${Intl_LIBRARY}") - else() - set(TZ_MAKEFLAGS) + if (APPLE) + set(TZ_MAKEFLAGS "LDLIBS=${Intl_LIBRARY}") + else() + set(TZ_MAKEFLAGS) + endif() + + execute_process( + COMMAND + ${GNU_MAKE} DESTDIR=${TZ_DIR} ${TZ_MAKEFLAGS} install + WORKING_DIRECTORY + ${TZ_TMP_SOURCE_DIR} + COMMAND_ERROR_IS_FATAL ANY + ) + + unset(TZ_MAKEFLAGS) + + # Step taken by Arch Linux packaging, but Nintendo apparently skips it + # execute_process( + # COMMAND + # "${TZDB_LOCATION}/zic" -b fat -d ${TZDB_ZONEINFO} africa antarctica asia australasia europe northamerica southamerica etcetera backward factory + # WORKING_DIRECTORY + # "${TZDB_LOCATION}" + # COMMAND_ERROR_IS_FATAL ANY + # ) endif() - execute_process( - COMMAND - ${GNU_MAKE} DESTDIR=${TZ_DIR} ${TZ_MAKEFLAGS} install - WORKING_DIRECTORY - ${TZ_TMP_SOURCE_DIR} - COMMAND_ERROR_IS_FATAL ANY - ) - - unset(TZ_MAKEFLAGS) - - # Step taken by Arch Linux packaging, but Nintendo apparently skips it - # execute_process( - # COMMAND - # "${TZDB_LOCATION}/zic" -b fat -d ${TZDB_ZONEINFO} africa antarctica asia australasia europe northamerica southamerica etcetera backward factory - # WORKING_DIRECTORY - # "${TZDB_LOCATION}" - # COMMAND_ERROR_IS_FATAL ANY - # ) - execute_process( COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/CMakeModules/list_directory.cmake false ON From d35fcb25584c91f4a26c411204bd8651df560307 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Thu, 18 Jan 2024 20:33:04 -0500 Subject: [PATCH 4/6] cmake: Add user specifiable version variable Previously it was still using the submodule's version. --- CMakeLists.txt | 5 +++++ src/tzdb/CMakeLists.txt | 44 ++++++++++++++++++++++------------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e15cb29..a02a73f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,11 @@ cmake_minimum_required(VERSION 3.10) project(tzdb2nx VERSION 1.0) option(TZDB2NX_ZONEINFO_DIR "Specify a custom zoneinfo directory containing time zone data you wish to use" "") +option(TZDB2NX_VERSION "Specify a custom zoneinfo version with the directory" "") + +if ((TZDB2NX_ZONEINFO_DIR AND NOT TZDB2NX_VERSION) OR (TZDB2NX_VERSION AND NOT TZDB2NX_ZONEINFO_DIR)) + message(FATAL_ERROR "Either TZDB2NX_ZONEINFO_DIR or TZDB2NX_VERSION but not both were defined.") +endif() set(CMAKE_CXX_STANDARD 20) diff --git a/src/tzdb/CMakeLists.txt b/src/tzdb/CMakeLists.txt index baf3a88..0301616 100644 --- a/src/tzdb/CMakeLists.txt +++ b/src/tzdb/CMakeLists.txt @@ -13,29 +13,33 @@ set(NX_ZONEINFO_DIR "${NX_TZDB_DIR}/zoneinfo") set(TZDB_VERSION_FILE ${TZ_SOURCE_DIR}/NEWS) -execute_process( - COMMAND - ${GIT_PROGRAM} log --pretty=%at -n1 NEWS - OUTPUT_VARIABLE - TZ_COMMIT_TIME - WORKING_DIRECTORY - ${TZ_SOURCE_DIR} - COMMAND_ERROR_IS_FATAL ANY) +if (NOT "${TZDB2NX_VERSION}" STREQUAL "") + set(TZDB_VERSION "${TZDB2NX_VERSION}\n") +else() + execute_process( + COMMAND + ${GIT_PROGRAM} log --pretty=%at -n1 NEWS + OUTPUT_VARIABLE + TZ_COMMIT_TIME + WORKING_DIRECTORY + ${TZ_SOURCE_DIR} + COMMAND_ERROR_IS_FATAL ANY) -string(REPLACE "\n" "" TZ_COMMIT_TIME "${TZ_COMMIT_TIME}") + string(REPLACE "\n" "" TZ_COMMIT_TIME "${TZ_COMMIT_TIME}") -if (APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|NetBSD|OpenBSD") - set(VERSION_COMMAND ${GNU_DATE} -r ${TZ_COMMIT_TIME} +%y%m%d) -else () - set(VERSION_COMMAND ${GNU_DATE} +%y%m%d --date=@${TZ_COMMIT_TIME}) -endif () + if (APPLE OR CMAKE_SYSTEM_NAME MATCHES "DragonFly|FreeBSD|NetBSD|OpenBSD") + set(VERSION_COMMAND ${GNU_DATE} -r ${TZ_COMMIT_TIME} +%y%m%d) + else () + set(VERSION_COMMAND ${GNU_DATE} +%y%m%d --date=@${TZ_COMMIT_TIME}) + endif () -execute_process( - COMMAND - ${VERSION_COMMAND} - OUTPUT_VARIABLE - TZDB_VERSION - COMMAND_ERROR_IS_FATAL ANY) + execute_process( + COMMAND + ${VERSION_COMMAND} + OUTPUT_VARIABLE + TZDB_VERSION + COMMAND_ERROR_IS_FATAL ANY) +endif() set(NX_VERSION_FILE ${NX_TZDB_DIR}/version.txt) file(WRITE ${NX_VERSION_FILE} "${TZDB_VERSION}") From e77461733bd6556896019c12c5036dd24b551c98 Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Thu, 18 Jan 2024 20:38:26 -0500 Subject: [PATCH 5/6] cmake: Add comment to directory check In review, this if statement was questioned as being a directory existence check in fact it is checking the value of the variable itself. --- externals/tz/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/tz/CMakeLists.txt b/externals/tz/CMakeLists.txt index c3ceeda..948fe69 100644 --- a/externals/tz/CMakeLists.txt +++ b/externals/tz/CMakeLists.txt @@ -19,7 +19,7 @@ if (NOT GIT_PROGRAM) endif() if (NOT EXISTS "${TZ_DIR}" OR NOT EXISTS "${TZIF_LIST_FILE}") - if (NOT TZDB2NX_ZONEINFO_DIR) + if (NOT TZDB2NX_ZONEINFO_DIR) # If a custom zoneinfo directory was specified # tz's makefile can only build in-tree, so copy the whole source tree to a # separate directory before building. execute_process( From 9231fff8c954333626efaeda0a5f811e3e4da7bb Mon Sep 17 00:00:00 2001 From: lat9nq <22451773+lat9nq@users.noreply.github.com> Date: Fri, 19 Jan 2024 21:19:40 -0500 Subject: [PATCH 6/6] cmake: Allow specifying TZDB2NX_VERSION without other requirements I was worried the version and custom zoneinfo dir were tied together, but it's fine. We can override the version whenever we want. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a02a73f..ad64710 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,8 +5,8 @@ project(tzdb2nx VERSION 1.0) option(TZDB2NX_ZONEINFO_DIR "Specify a custom zoneinfo directory containing time zone data you wish to use" "") option(TZDB2NX_VERSION "Specify a custom zoneinfo version with the directory" "") -if ((TZDB2NX_ZONEINFO_DIR AND NOT TZDB2NX_VERSION) OR (TZDB2NX_VERSION AND NOT TZDB2NX_ZONEINFO_DIR)) - message(FATAL_ERROR "Either TZDB2NX_ZONEINFO_DIR or TZDB2NX_VERSION but not both were defined.") +if (TZDB2NX_ZONEINFO_DIR AND NOT TZDB2NX_VERSION) + message(FATAL_ERROR "TZDB2NX_ZONEINFO_DIR was specified but TZDB2NX_VERSION was left undefined.") endif() set(CMAKE_CXX_STANDARD 20)