diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..5322a25 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "externals/tz/tz"] + path = externals/tz/tz + url = https://github.com/eggert/tz.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c47574..87c8950 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,11 +2,7 @@ cmake_minimum_required(VERSION 3.10) project(tzdb2nx VERSION 1.0) -set(TZDB_VERSION "$ENV{TZDB_VERSION}") -if ("${TZDB_VERSION}" STREQUAL "") - set(TZDB_VERSION "2022c") -endif() - set(CMAKE_CXX_STANDARD 20) +add_subdirectory(externals) add_subdirectory(src) diff --git a/externals/CMakeLists.txt b/externals/CMakeLists.txt new file mode 100644 index 0000000..33a9c7c --- /dev/null +++ b/externals/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(tz) diff --git a/externals/tz/CMakeLists.txt b/externals/tz/CMakeLists.txt new file mode 100644 index 0000000..eacd3be --- /dev/null +++ b/externals/tz/CMakeLists.txt @@ -0,0 +1,34 @@ +set(TZ_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tz") +set(TZ_DIR "${CMAKE_CURRENT_BINARY_DIR}/tz") +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") + +find_program(GNU_MAKE make) +if ("${GNU_MAKE}" STREQUAL "GNU_MAKE-NOTFOUND") + message(FATAL_ERROR "GNU make not found") +endif() + +if (NOT EXISTS "${TZ_DIR}" OR NOT EXISTS "${TZIF_LIST_FILE}") + execute_process( + COMMAND + ${GNU_MAKE} DESTDIR=${TZ_DIR} install + WORKING_DIRECTORY + ${TZ_SOURCE_DIR} + COMMAND_ERROR_IS_FATAL ANY + ) + + # 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 + /bin/bash "${CMAKE_CURRENT_SOURCE_DIR}/find_tzif.sh" "${TZ_ZONEINFO_DIR}" "${TZIF_LIST_FILE}" + COMMAND_ERROR_IS_FATAL ANY + ) +endif() diff --git a/src/tzdb/find_tzif.sh b/externals/tz/find_tzif.sh similarity index 100% rename from src/tzdb/find_tzif.sh rename to externals/tz/find_tzif.sh diff --git a/externals/tz/tz b/externals/tz/tz new file mode 160000 index 0000000..ce4d776 --- /dev/null +++ b/externals/tz/tz @@ -0,0 +1 @@ +Subproject commit ce4d77644d2793027bb27f095dec7b530edcd947 diff --git a/src/tzdb/CMakeLists.txt b/src/tzdb/CMakeLists.txt index 3bd7688..b91ed63 100644 --- a/src/tzdb/CMakeLists.txt +++ b/src/tzdb/CMakeLists.txt @@ -1,21 +1,10 @@ -find_program(GNU_MAKE make) -if ("${GNU_MAKE}" STREQUAL "GNU_MAKE-NOTFOUND") - message(ERROR "make program not found") -endif() +set(NX_TZDB_DIR "${CMAKE_CURRENT_BINARY_DIR}/nx" CACHE PATH "Path to Switch-style time zone data") +set(NX_ZONEINFO_DIR "${NX_TZDB_DIR}/zoneinfo") -set(TZDB_ARCHIVE "tzdb-${TZDB_VERSION}.tar.lz") -set(TZDB_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/tzdb-${TZDB_VERSION}") -if (NOT (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${TZDB_ARCHIVE}" AND EXISTS "${TZDB_LOCATION}")) - file(DOWNLOAD "https://data.iana.org/time-zones/releases/${TZDB_ARCHIVE}" "${CMAKE_CURRENT_BINARY_DIR}/${TZDB_ARCHIVE}") - file(ARCHIVE_EXTRACT INPUT "${CMAKE_CURRENT_BINARY_DIR}/${TZDB_ARCHIVE}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") -endif() - -set(TZDB_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/build") -set(TZDB_ZONEINFO "${TZDB_BUILD_DIR}/usr/share/zoneinfo") -set(TZIF_LIST_FILE "${CMAKE_CURRENT_BINARY_DIR}/tzif_list.txt") - -set(NX_BUILD_DIR "${PROJECT_BINARY_DIR}/nx") -set(NX_ZONEINFO_DIR "${NX_BUILD_DIR}/zoneinfo") +set(TZDB_VERSION_FILE ${TZDB_LOCATION}/version) +file(TIMESTAMP ${TZDB_VERSION_FILE} TZDB_VERSION "%y%m%d" UTC) +set(NX_VERSION_FILE ${NX_TZDB_DIR}/version.txt) +file(WRITE ${NX_VERSION_FILE} "${TZDB_VERSION}") add_custom_target(x80e ALL @@ -23,37 +12,7 @@ add_custom_target(x80e tzdb2nx ${NX_VERSION_FILE}) -if (NOT EXISTS "${TZDB_BUILD_DIR}" OR NOT EXISTS ${TZIF_LIST_FILE}) - execute_process( - COMMAND - "${GNU_MAKE}" DESTDIR=${TZDB_BUILD_DIR} install - WORKING_DIRECTORY - "${TZDB_LOCATION}" - COMMAND_ERROR_IS_FATAL ANY - ) - - # 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 - /bin/bash "${CMAKE_CURRENT_SOURCE_DIR}/find_tzif.sh" "${TZDB_ZONEINFO}" "${TZIF_LIST_FILE}" - COMMAND_ERROR_IS_FATAL ANY - ) -endif() - -set(TZDB_VERSION_FILE ${TZDB_LOCATION}/version) -file(TIMESTAMP ${TZDB_VERSION_FILE} TZDB_VERSION "%y%m%d" UTC) -set(NX_VERSION_FILE ${NX_BUILD_DIR}/version.txt) -file(WRITE ${NX_VERSION_FILE} "${TZDB_VERSION}") - -set(BINARY_LIST_TXT ${NX_BUILD_DIR}/binaryList.txt) +set(BINARY_LIST_TXT ${NX_TZDB_DIR}/binaryList.txt) add_custom_target(binary_list bash ${CMAKE_CURRENT_SOURCE_DIR}/generate_binary_list_txt.sh ${BINARY_LIST_TXT} BYPRODUCTS @@ -64,7 +23,7 @@ add_dependencies(x80e binary_list) file(STRINGS "${TZIF_LIST_FILE}" TZ_FILES) foreach(FILE ${TZ_FILES}) - file(RELATIVE_PATH TARG "${TZDB_ZONEINFO}" "${FILE}") + file(RELATIVE_PATH TARG "${TZ_ZONEINFO_DIR}" "${FILE}") get_filename_component(TARG_PATH "${NX_ZONEINFO_DIR}/${TARG}" DIRECTORY) string(REGEX REPLACE "\/" "_" TARG_SANITIZED "${TARG}") add_custom_target(${TARG_SANITIZED} @@ -73,10 +32,9 @@ foreach(FILE ${TZ_FILES}) COMMAND mkdir -p ${TARG_PATH} COMMAND - "${PROJECT_BINARY_DIR}/src/tzdb2nx/tzdb2nx" ${FILE} ${NX_ZONEINFO_DIR}/${TARG} + ${TZDB2NX_PATH} ${FILE} ${NX_ZONEINFO_DIR}/${TARG} DEPENDS - tzdb2nx - ) + tzdb2nx) add_dependencies(x80e ${TARG_SANITIZED}) add_dependencies(binary_list ${TARG_SANITIZED}) diff --git a/src/tzdb2nx/CMakeLists.txt b/src/tzdb2nx/CMakeLists.txt index 9d2b034..ae5d614 100644 --- a/src/tzdb2nx/CMakeLists.txt +++ b/src/tzdb2nx/CMakeLists.txt @@ -2,3 +2,6 @@ add_executable(tzdb2nx main.cpp tzif.cpp tzif.h) + +set(TZDB2NX_PATH "${CMAKE_CURRENT_BINARY_DIR}/tzdb2nx" CACHE PATH "Path to tzdb2nx path") +set_target_properties(tzdb2nx PROPERTIES CMAKE_RUNTIME_OUTPUT_DIRECTORY ${TZDB2NX_PATH})