mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-12-22 16:30:57 +01:00
nx_tzdb: Create headers from downloaded system archive data
Use lat9nq/tzdb_to_nx release data to generate header files. nx_tzdb: Use an interface library nx_tzdb: Gate download if achive not exists nx_tzdb: Fix header generator brace closing nx_tzdb: Add base directory files nx_tzdb: Add SPDX info
This commit is contained in:
parent
a40e0fdf9e
commit
73036c83a3
6 changed files with 167 additions and 0 deletions
3
externals/CMakeLists.txt
vendored
3
externals/CMakeLists.txt
vendored
|
@ -139,6 +139,9 @@ if (YUZU_USE_EXTERNAL_VULKAN_HEADERS)
|
|||
add_subdirectory(Vulkan-Headers)
|
||||
endif()
|
||||
|
||||
# TZDB (Time Zone Database)
|
||||
add_subdirectory(nx_tzdb)
|
||||
|
||||
if (NOT TARGET LLVM::Demangle)
|
||||
add_library(demangle demangle/ItaniumDemangle.cpp)
|
||||
target_include_directories(demangle PUBLIC ./demangle)
|
||||
|
|
65
externals/nx_tzdb/CMakeLists.txt
vendored
Normal file
65
externals/nx_tzdb/CMakeLists.txt
vendored
Normal file
|
@ -0,0 +1,65 @@
|
|||
# SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
set(NX_TZDB_VERSION "220816")
|
||||
set(NX_TZDB_DOWNLOAD_URL "https://github.com/lat9nq/tzdb_to_nx/releases/download/${NX_TZDB_VERSION}/${NX_TZDB_VERSION}.zip")
|
||||
|
||||
set(NX_TZDB_ARCHIVE "${CMAKE_CURRENT_BINARY_DIR}/${NX_TZDB_VERSION}.zip")
|
||||
set(NX_TZDB_DIR "${CMAKE_CURRENT_BINARY_DIR}/nx_tzdb")
|
||||
|
||||
set(NX_TZDB_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/include")
|
||||
|
||||
if (NOT EXISTS ${NX_TZDB_ARCHIVE})
|
||||
file(DOWNLOAD ${NX_TZDB_DOWNLOAD_URL} ${NX_TZDB_ARCHIVE})
|
||||
file(ARCHIVE_EXTRACT
|
||||
INPUT
|
||||
${NX_TZDB_ARCHIVE}
|
||||
DESTINATION
|
||||
${NX_TZDB_DIR})
|
||||
endif()
|
||||
|
||||
add_library(nx_tzdb INTERFACE)
|
||||
target_include_directories(nx_tzdb
|
||||
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
INTERFACE ${NX_TZDB_INCLUDE_DIR})
|
||||
|
||||
function(CreateHeader ZONE_PATH HEADER_NAME)
|
||||
set(HEADER_PATH "${NX_TZDB_INCLUDE_DIR}/nx_tzdb/${HEADER_NAME}.h")
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
${NX_TZDB_INCLUDE_DIR}/nx_tzdb/${HEADER_NAME}.h
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/NxTzdbCreateHeader.cmake
|
||||
${ZONE_PATH}
|
||||
${HEADER_NAME}
|
||||
${NX_TZDB_INCLUDE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
DEPENDS
|
||||
tzdb_template.h.in
|
||||
NxTzdbCreateHeader.cmake)
|
||||
|
||||
target_sources(nx_tzdb PRIVATE ${HEADER_PATH})
|
||||
endfunction()
|
||||
|
||||
CreateHeader(${NX_TZDB_DIR} base)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo zoneinfo)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/Africa africa)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/America america)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/America/Argentina america_argentina)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/America/Indiana america_indiana)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/America/Kentucky america_kentucky)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/America/North_Dakota america_north_dakota)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/Antartica antartica)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/Arctic arctic)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/Asia asia)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/Atlantic atlantic)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/Australia australia)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/Brazil brazil)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/Canada canada)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/Chile chile)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/Etc etc)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/Europe europe)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/Indian indian)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/Mexico mexico)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/Pacific pacific)
|
||||
CreateHeader(${NX_TZDB_DIR}/zoneinfo/US us)
|
8
externals/nx_tzdb/ListFilesInDirectory.cmake
vendored
Normal file
8
externals/nx_tzdb/ListFilesInDirectory.cmake
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
# SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
# CMake does not have a way to list the files in a specific directory,
|
||||
# so we need this script to do that for us in a platform-agnostic fashion
|
||||
|
||||
file(GLOB FILE_LIST LIST_DIRECTORIES false RELATIVE ${CMAKE_SOURCE_DIR} "*")
|
||||
execute_process(COMMAND ${CMAKE_COMMAND} -E echo "${FILE_LIST};")
|
46
externals/nx_tzdb/NxTzdbCreateHeader.cmake
vendored
Normal file
46
externals/nx_tzdb/NxTzdbCreateHeader.cmake
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
# SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
set(ZONE_PATH ${CMAKE_ARGV3})
|
||||
set(HEADER_NAME ${CMAKE_ARGV4})
|
||||
set(NX_TZDB_INCLUDE_DIR ${CMAKE_ARGV5})
|
||||
set(NX_TZDB_SOURCE_DIR ${CMAKE_ARGV6})
|
||||
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_COMMAND} -P ${NX_TZDB_SOURCE_DIR}/ListFilesInDirectory.cmake
|
||||
WORKING_DIRECTORY ${ZONE_PATH}
|
||||
OUTPUT_VARIABLE FILE_LIST)
|
||||
|
||||
set(DIRECTORY_NAME ${HEADER_NAME})
|
||||
|
||||
set(FILE_DATA "")
|
||||
foreach(ZONE_FILE ${FILE_LIST})
|
||||
if ("${ZONE_FILE}" STREQUAL "\n")
|
||||
continue()
|
||||
endif()
|
||||
|
||||
string(APPEND FILE_DATA "{\"${ZONE_FILE}\",\n{")
|
||||
|
||||
file(READ ${ZONE_PATH}/${ZONE_FILE} ZONE_DATA HEX)
|
||||
string(LENGTH "${ZONE_DATA}" ZONE_DATA_LEN)
|
||||
foreach(I RANGE 0 ${ZONE_DATA_LEN} 2)
|
||||
math(EXPR BREAK_LINE "(${I} + 2) % 38")
|
||||
|
||||
string(SUBSTRING "${ZONE_DATA}" "${I}" "2" HEX_DATA)
|
||||
if ("${HEX_DATA}" STREQUAL "")
|
||||
break()
|
||||
endif()
|
||||
|
||||
string(APPEND FILE_DATA "0x${HEX_DATA},")
|
||||
if ("${BREAK_LINE}" STREQUAL "0")
|
||||
string(APPEND FILE_DATA "\n")
|
||||
else()
|
||||
string(APPEND FILE_DATA " ")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
string(APPEND FILE_DATA "}},\n")
|
||||
endforeach()
|
||||
|
||||
file(READ ${NX_TZDB_SOURCE_DIR}/tzdb_template.h.in NX_TZDB_TEMPLATE_H_IN)
|
||||
file(CONFIGURE OUTPUT ${NX_TZDB_INCLUDE_DIR}/nx_tzdb/${HEADER_NAME}.h CONTENT "${NX_TZDB_TEMPLATE_H_IN}")
|
27
externals/nx_tzdb/include/nx_tzdb.h
vendored
Normal file
27
externals/nx_tzdb/include/nx_tzdb.h
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "nx_tzdb/africa.h"
|
||||
#include "nx_tzdb/america.h"
|
||||
#include "nx_tzdb/america_argentina.h"
|
||||
#include "nx_tzdb/america_indiana.h"
|
||||
#include "nx_tzdb/america_kentucky.h"
|
||||
#include "nx_tzdb/america_north_dakota.h"
|
||||
#include "nx_tzdb/antartica.h"
|
||||
#include "nx_tzdb/arctic.h"
|
||||
#include "nx_tzdb/asia.h"
|
||||
#include "nx_tzdb/atlantic.h"
|
||||
#include "nx_tzdb/australia.h"
|
||||
#include "nx_tzdb/base.h"
|
||||
#include "nx_tzdb/brazil.h"
|
||||
#include "nx_tzdb/canada.h"
|
||||
#include "nx_tzdb/chile.h"
|
||||
#include "nx_tzdb/etc.h"
|
||||
#include "nx_tzdb/europe.h"
|
||||
#include "nx_tzdb/indian.h"
|
||||
#include "nx_tzdb/mexico.h"
|
||||
#include "nx_tzdb/pacific.h"
|
||||
#include "nx_tzdb/us.h"
|
||||
#include "nx_tzdb/zoneinfo.h"
|
18
externals/nx_tzdb/tzdb_template.h.in
vendored
Normal file
18
externals/nx_tzdb/tzdb_template.h.in
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
namespace NxTzdb {
|
||||
|
||||
// clang-format off
|
||||
const static std::map<const char*, const std::vector<uint8_t>> @DIRECTORY_NAME@ =
|
||||
{
|
||||
@FILE_DATA@};
|
||||
// clang-format on
|
||||
|
||||
} // namespace NxTzdb
|
Loading…
Reference in a new issue