Meta: Move remove_unicode_data_if_version_changed to utils.cmake

This function will be used by the time zone database parser. Move it to
the common utilities file, and rename it remove_path_if_version_changed
to be more generic.
This commit is contained in:
Timothy Flynn 2021-12-22 16:12:59 -05:00 committed by Linus Groh
parent a70e029236
commit d5f14b5ff9
Notes: sideshowbarker 2024-07-17 21:27:03 +09:00
2 changed files with 21 additions and 19 deletions

View file

@ -1,3 +1,5 @@
include(${CMAKE_CURRENT_LIST_DIR}/utils.cmake)
set(UCD_VERSION 14.0.0)
set(CLDR_VERSION 40.0.0)
@ -67,23 +69,6 @@ set(CLDR_NUMBERS_PATH "${CLDR_PATH}/${CLDR_NUMBERS_SOURCE}")
set(CLDR_UNITS_SOURCE cldr-units-modern)
set(CLDR_UNITS_PATH "${CLDR_PATH}/${CLDR_UNITS_SOURCE}")
function(remove_unicode_data_if_version_changed version version_file cache_path)
set(version_differs YES)
if (EXISTS "${version_file}")
file(STRINGS "${version_file}" active_version)
if (version STREQUAL active_version)
set(version_differs NO)
endif()
endif()
if (version_differs)
message(STATUS "Removing outdated ${cache_path} for version ${version}")
file(REMOVE_RECURSE "${cache_path}")
file(WRITE "${version_file}" "${version}")
endif()
endfunction()
function(download_ucd_file url path)
if (NOT EXISTS "${path}")
get_filename_component(file "${path}" NAME)
@ -120,8 +105,8 @@ function(invoke_generator name generator header implementation)
endfunction()
if (ENABLE_UNICODE_DATABASE_DOWNLOAD)
remove_unicode_data_if_version_changed("${UCD_VERSION}" "${UCD_VERSION_FILE}" "${UCD_PATH}")
remove_unicode_data_if_version_changed("${CLDR_VERSION}" "${CLDR_VERSION_FILE}" "${CLDR_PATH}")
remove_path_if_version_changed("${UCD_VERSION}" "${UCD_VERSION_FILE}" "${UCD_PATH}")
remove_path_if_version_changed("${CLDR_VERSION}" "${CLDR_VERSION_FILE}" "${CLDR_PATH}")
download_ucd_file("${UNICODE_DATA_URL}" "${UNICODE_DATA_PATH}")
download_ucd_file("${SPECIAL_CASING_URL}" "${SPECIAL_CASING_PATH}")

View file

@ -158,3 +158,20 @@ function(link_with_unicode_data target)
target_link_libraries("${target}" LibUnicodeData)
endif()
endfunction()
function(remove_path_if_version_changed version version_file cache_path)
set(version_differs YES)
if (EXISTS "${version_file}")
file(STRINGS "${version_file}" active_version)
if (version STREQUAL active_version)
set(version_differs NO)
endif()
endif()
if (version_differs)
message(STATUS "Removing outdated ${cache_path} for version ${version}")
file(REMOVE_RECURSE "${cache_path}")
file(WRITE "${version_file}" "${version}")
endif()
endfunction()