Implement patch keys

Signed-off-by: crueter <crueter@eden-emu.dev>
This commit is contained in:
crueter 2026-06-26 02:15:22 -04:00
parent fd5e4ca409
commit 193efc4b82
No known key found for this signature in database
GPG key ID: 425ACD2D4830EBC6
3 changed files with 194 additions and 127 deletions

View file

@ -75,43 +75,45 @@ set(CPM_FILE
set(CPM_PACKAGES "" CACHE INTERNAL "") set(CPM_PACKAGES "" CACHE INTERNAL "")
if(NOT CPM_DONT_UPDATE_MODULE_PATH AND NOT DEFINED CMAKE_FIND_PACKAGE_REDIRECTS_DIR)
set(CPM_MODULE_PATH
"${CMAKE_BINARY_DIR}/CPM_modules"
CACHE INTERNAL ""
)
# remove old modules
file(REMOVE_RECURSE ${CPM_MODULE_PATH})
file(MAKE_DIRECTORY ${CPM_MODULE_PATH})
# locally added CPM modules should override global packages
set(CMAKE_MODULE_PATH "${CPM_MODULE_PATH};${CMAKE_MODULE_PATH}")
endif()
include(FetchContent) include(FetchContent)
# Create a custom FindXXX.cmake module for a CPM package This prevents `find_package(NAME)` from # compute a hash of all patch file contents
# finding the system library # if there are no patches, returns none
function(cpm_compute_patch_key patches patch_key_out)
if(NOT patches)
set("${patch_key_out}" "none" PARENT_SCOPE)
return()
endif()
set(combined "")
foreach(PATCH ${patches})
file(READ "${PATCH}" contents)
string(APPEND combined "${contents}")
endforeach()
string(SHA512 key "${combined}")
set("${patch_key_out}" "${key}" PARENT_SCOPE)
endfunction()
# Create a custom FindXXX.cmake module for a CPM package.
# This prevents `find_package(NAME)` from finding the system library
function(cpm_create_module_file Name) function(cpm_create_module_file Name)
if(NOT CPM_DONT_UPDATE_MODULE_PATH) if(NOT CPM_DONT_UPDATE_MODULE_PATH)
if(DEFINED CMAKE_FIND_PACKAGE_REDIRECTS_DIR) # Redirect find_package calls to the CPM package.
# Redirect find_package calls to the CPM package. This is what FetchContent does when you set # This is what FetchContent does when you set
# OVERRIDE_FIND_PACKAGE. The CMAKE_FIND_PACKAGE_REDIRECTS_DIR works for find_package in CONFIG # OVERRIDE_FIND_PACKAGE. The CMAKE_FIND_PACKAGE_REDIRECTS_DIR works for
# mode, unlike the Find${Name}.cmake fallback. CMAKE_FIND_PACKAGE_REDIRECTS_DIR is not defined # find_package in CONFIG mode, unlike the Find${Name}.cmake fallback.
# in script mode, or in CMake < 3.24. # CMAKE_FIND_PACKAGE_REDIRECTS_DIR is not defined in script mode
# https://cmake.org/cmake/help/latest/module/FetchContent.html#fetchcontent-find-package-integration-examples # https://cmake.org/cmake/help/latest/module/FetchContent.html#fetchcontent-find-package-integration-examples
string(TOLOWER ${Name} NameLower) string(TOLOWER ${Name} NameLower)
file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${NameLower}-config.cmake file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${NameLower}-config.cmake
"include(\"\${CMAKE_CURRENT_LIST_DIR}/${NameLower}-extra.cmake\" OPTIONAL)\n" "include(\"\${CMAKE_CURRENT_LIST_DIR}/${NameLower}-extra.cmake\" OPTIONAL)\n"
"include(\"\${CMAKE_CURRENT_LIST_DIR}/${Name}Extra.cmake\" OPTIONAL)\n" "include(\"\${CMAKE_CURRENT_LIST_DIR}/${Name}Extra.cmake\" OPTIONAL)\n")
)
file(WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${NameLower}-config-version.cmake file(WRITE
"set(PACKAGE_VERSION_COMPATIBLE TRUE)\n" "set(PACKAGE_VERSION_EXACT TRUE)\n" ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${NameLower}-config-version.cmake
) "set(PACKAGE_VERSION_COMPATIBLE TRUE)\n"
else() "set(PACKAGE_VERSION_EXACT TRUE)\n")
file(WRITE ${CPM_MODULE_PATH}/Find${Name}.cmake
"include(\"${CPM_FILE}\")\n${ARGN}\nset(${Name}_FOUND TRUE)"
)
endif()
endif() endif()
endfunction() endfunction()
@ -120,23 +122,15 @@ function(cpm_check_if_package_already_added CPM_ARGS_NAME CPM_ARGS_VERSION)
if("${CPM_ARGS_NAME}" IN_LIST CPM_PACKAGES) if("${CPM_ARGS_NAME}" IN_LIST CPM_PACKAGES)
CPMGetPackageVersion(${CPM_ARGS_NAME} CPM_PACKAGE_VERSION) CPMGetPackageVersion(${CPM_ARGS_NAME} CPM_PACKAGE_VERSION)
if("${CPM_PACKAGE_VERSION}" VERSION_LESS "${CPM_ARGS_VERSION}") if("${CPM_PACKAGE_VERSION}" VERSION_LESS "${CPM_ARGS_VERSION}")
message( message(WARNING
WARNING "${CPM_INDENT} Requires a newer version of ${CPM_ARGS_NAME} (${CPM_ARGS_VERSION}) than currently included (${CPM_PACKAGE_VERSION}).")
"${CPM_INDENT} Requires a newer version of ${CPM_ARGS_NAME} (${CPM_ARGS_VERSION}) than currently included (${CPM_PACKAGE_VERSION})."
)
endif() endif()
cpm_get_fetch_properties(${CPM_ARGS_NAME}) cpm_get_fetch_properties(${CPM_ARGS_NAME})
set(${CPM_ARGS_NAME}_ADDED NO) set(${CPM_ARGS_NAME}_ADDED NO)
set(CPM_PACKAGE_ALREADY_ADDED set(CPM_PACKAGE_ALREADY_ADDED YES PARENT_SCOPE)
YES
PARENT_SCOPE
)
cpm_export_variables(${CPM_ARGS_NAME}) cpm_export_variables(${CPM_ARGS_NAME})
else() else()
set(CPM_PACKAGE_ALREADY_ADDED set(CPM_PACKAGE_ALREADY_ADDED NO PARENT_SCOPE)
NO
PARENT_SCOPE
)
endif() endif()
endfunction() endfunction()
@ -151,28 +145,33 @@ function(cpm_add_patches)
# Find the patch program. # Find the patch program.
find_program(PATCH_EXECUTABLE patch) find_program(PATCH_EXECUTABLE patch)
if(CMAKE_HOST_WIN32 AND NOT PATCH_EXECUTABLE) if(CMAKE_HOST_WIN32 AND NOT PATCH_EXECUTABLE)
# The Windows git executable is distributed with patch.exe. Find the path to the executable, if # The Windows git executable is distributed with patch.exe.
# it exists, then search `../usr/bin` and `../../usr/bin` for patch.exe. # Find the path to the executable, if it exists, then search
# `../usr/bin` and `../../usr/bin` for patch.exe.
find_package(Git QUIET) find_package(Git QUIET)
if(GIT_EXECUTABLE) if(GIT_EXECUTABLE)
get_filename_component(extra_search_path ${GIT_EXECUTABLE} DIRECTORY) get_filename_component(extra_search_path
get_filename_component(extra_search_path_1up ${extra_search_path} DIRECTORY) ${GIT_EXECUTABLE} DIRECTORY)
get_filename_component(extra_search_path_2up ${extra_search_path_1up} DIRECTORY) get_filename_component(extra_search_path_1up
find_program( ${extra_search_path} DIRECTORY)
PATCH_EXECUTABLE patch HINTS "${extra_search_path_1up}/usr/bin" get_filename_component(extra_search_path_2up
"${extra_search_path_2up}/usr/bin" ${extra_search_path_1up} DIRECTORY)
) find_program(PATCH_EXECUTABLE patch HINTS
"${extra_search_path_1up}/usr/bin"
"${extra_search_path_2up}/usr/bin")
endif() endif()
endif() endif()
if(NOT PATCH_EXECUTABLE) if(NOT PATCH_EXECUTABLE)
message(FATAL_ERROR "Couldn't find `patch` executable to use with PATCHES keyword.") message(FATAL_ERROR
"Couldn't find `patch` executable to use with PATCHES keyword.")
endif() endif()
# Ensure each file exists (or error out) and add it to the list. # Ensure each file exists (or error out) and add it to the list.
set(patch_args "") set(patch_args "")
set(first_item True) set(first_item True)
foreach(PATCH_FILE ${ARGN}) foreach(PATCH_FILE ${ARGN})
# Make sure the patch file exists, if we can't find it, try again in the current directory. # Make sure the patch file exists, if we can't find it,
# try again in the current directory.
if(NOT EXISTS "${PATCH_FILE}") if(NOT EXISTS "${PATCH_FILE}")
if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/${PATCH_FILE}") if(NOT EXISTS "${CMAKE_CURRENT_LIST_DIR}/${PATCH_FILE}")
message(FATAL_ERROR "Couldn't find patch file: '${PATCH_FILE}'") message(FATAL_ERROR "Couldn't find patch file: '${PATCH_FILE}'")
@ -183,22 +182,20 @@ function(cpm_add_patches)
# Convert to absolute path for use with patch file command. # Convert to absolute path for use with patch file command.
get_filename_component(PATCH_FILE "${PATCH_FILE}" ABSOLUTE) get_filename_component(PATCH_FILE "${PATCH_FILE}" ABSOLUTE)
# The first patch entry must be preceded by "PATCH_COMMAND" while the following items are # The first patch entry must be preceded by "PATCH_COMMAND"
# preceded by "&&". # while the following items are preceded by "COMMAND".
if(first_item) if(first_item)
set(first_item False) set(first_item False)
list(APPEND patch_args "PATCH_COMMAND") list(APPEND patch_args "PATCH_COMMAND")
else() else()
list(APPEND patch_args "COMMAND") list(APPEND patch_args "COMMAND")
endif() endif()
# Add the patch command to the list # Add the patch command to the list
list(APPEND patch_args "${PATCH_EXECUTABLE}" "-p1" "-i" "${PATCH_FILE}") list(APPEND patch_args "${PATCH_EXECUTABLE}" "-p1" "-i" "${PATCH_FILE}")
endforeach() endforeach()
set(PATCH_COMMAND set(PATCH_COMMAND ${patch_args} PARENT_SCOPE)
${patch_args}
PARENT_SCOPE
)
endfunction() endfunction()
function(CPMAddPackage) function(CPMAddPackage)
@ -216,7 +213,11 @@ function(CPMAddPackage)
set(multiValueArgs URL OPTIONS PATCHES) set(multiValueArgs URL OPTIONS PATCHES)
cmake_parse_arguments(CPM_ARGS "" "${oneValueArgs}" "${multiValueArgs}" "${ARGN}") cmake_parse_arguments(CPM_ARGS
""
"${oneValueArgs}"
"${multiValueArgs}"
"${ARGN}")
if(CPM_ARGS_DOWNLOAD_ONLY) if(CPM_ARGS_DOWNLOAD_ONLY)
set(DOWNLOAD_ONLY ${CPM_ARGS_DOWNLOAD_ONLY}) set(DOWNLOAD_ONLY ${CPM_ARGS_DOWNLOAD_ONLY})
@ -255,8 +256,8 @@ function(CPMAddPackage)
OPTIONS "${CPM_ARGS_OPTIONS}" OPTIONS "${CPM_ARGS_OPTIONS}"
SOURCE_SUBDIR "${CPM_ARGS_SOURCE_SUBDIR}" SOURCE_SUBDIR "${CPM_ARGS_SOURCE_SUBDIR}"
DOWNLOAD_ONLY "${DOWNLOAD_ONLY}" DOWNLOAD_ONLY "${DOWNLOAD_ONLY}"
FORCE True FORCE True)
)
cpm_export_variables(${CPM_ARGS_NAME}) cpm_export_variables(${CPM_ARGS_NAME})
return() return()
endif() endif()
@ -284,11 +285,12 @@ function(CPMAddPackage)
set(fetch_source_dir ${CPM_ARGS_SOURCE_DIR}) set(fetch_source_dir ${CPM_ARGS_SOURCE_DIR})
if(NOT IS_ABSOLUTE ${CPM_ARGS_SOURCE_DIR}) if(NOT IS_ABSOLUTE ${CPM_ARGS_SOURCE_DIR})
get_filename_component( get_filename_component(
fetch_source_dir ${CPM_ARGS_SOURCE_DIR} REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR} fetch_source_dir ${CPM_ARGS_SOURCE_DIR}
) REALPATH BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif() endif()
if(NOT EXISTS ${fetch_source_dir}) if(NOT EXISTS ${fetch_source_dir})
file(REMOVE_RECURSE "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild") file(REMOVE_RECURSE
"${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild")
endif() endif()
else() else()
set(download_directory set(download_directory
@ -297,6 +299,77 @@ function(CPMAddPackage)
set(fetch_source_dir ${download_directory}) set(fetch_source_dir ${download_directory})
endif() endif()
# compute expected patch key
cpm_compute_patch_key("${CPM_ARGS_PATCHES}" expected_patch_key)
set(patch_key_file "${download_directory}/.cpm_patch_key")
# source is already fetched and verified
if(NOT DEFINED CPM_ARGS_SOURCE_DIR AND EXISTS ${download_directory})
# read current patch key from stamp
if(EXISTS "${patch_key_file}")
file(READ "${patch_key_file}" current_patch_key)
else()
set(current_patch_key "")
endif()
# if the patch key file is missing, either patches have changed or download
# failed; in either case refetch
if(NOT current_patch_key STREQUAL expected_patch_key)
message(DEBUG "${CPM_INDENT} Package ${CPM_ARGS_NAME} missing "
"or mismatched patch key, refetching")
file(REMOVE_RECURSE "${download_directory}")
file(REMOVE_RECURSE
"${CMAKE_BINARY_DIR}/CMakeFiles/fc-stamp/${lower_case_name}")
else()
file(LOCK ${download_directory}/../cmake.lock RELEASE)
cpm_store_fetch_properties(
${CPM_ARGS_NAME} "${download_directory}"
"${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build")
cpm_get_fetch_properties("${CPM_ARGS_NAME}")
if(CPM_ARGS_OPTIONS AND NOT DOWNLOAD_ONLY)
foreach(OPTION ${CPM_ARGS_OPTIONS})
cpm_parse_option("${OPTION}")
set(${OPTION_KEY} "${OPTION_VALUE}")
endforeach()
endif()
if(NOT "${DOWNLOAD_ONLY}")
cpm_create_module_file(${CPM_ARGS_NAME})
endif()
if(NOT DOWNLOAD_ONLY)
set(source_subdir ${download_directory})
if(DEFINED CPM_ARGS_SOURCE_SUBDIR)
set(source_subdir ${source_subdir}/${CPM_ARGS_SOURCE_SUBDIR})
endif()
if(EXISTS ${source_subdir}/CMakeLists.txt)
set(addSubdirectoryExtraArgs "")
if(${CPM_ARGS_EXCLUDE_FROM_ALL})
list(APPEND addSubdirectoryExtraArgs EXCLUDE_FROM_ALL)
endif()
if(CPM_ARGS_SYSTEM)
list(APPEND addSubdirectoryExtraArgs SYSTEM)
endif()
add_subdirectory(
${source_subdir}
${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build
${addSubdirectoryExtraArgs})
endif()
endif()
set(${CPM_ARGS_NAME}_ADDED YES)
cpm_export_variables(${CPM_ARGS_NAME})
return()
endif()
endif()
set(fetchContentDeclareExtraArgs "") set(fetchContentDeclareExtraArgs "")
if(${CPM_ARGS_EXCLUDE_FROM_ALL}) if(${CPM_ARGS_EXCLUDE_FROM_ALL})
list(APPEND fetchContentDeclareExtraArgs EXCLUDE_FROM_ALL) list(APPEND fetchContentDeclareExtraArgs EXCLUDE_FROM_ALL)
@ -307,7 +380,8 @@ function(CPMAddPackage)
endif() endif()
if(DEFINED CPM_ARGS_SOURCE_SUBDIR) if(DEFINED CPM_ARGS_SOURCE_SUBDIR)
list(APPEND fetchContentDeclareExtraArgs SOURCE_SUBDIR ${CPM_ARGS_SOURCE_SUBDIR}) list(APPEND fetchContentDeclareExtraArgs
SOURCE_SUBDIR ${CPM_ARGS_SOURCE_SUBDIR})
endif() endif()
if(CPM_ARGS_OPTIONS AND NOT DOWNLOAD_ONLY) if(CPM_ARGS_OPTIONS AND NOT DOWNLOAD_ONLY)
@ -327,18 +401,13 @@ function(CPMAddPackage)
endif() endif()
if(NOT DEFINED CPM_ARGS_SOURCE_DIR) if(NOT DEFINED CPM_ARGS_SOURCE_DIR)
if(EXISTS ${download_directory}) file(REMOVE_RECURSE
set(PACKAGE_INFO "${PACKAGE_INFO} at ${download_directory}") ${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild)
else()
file(REMOVE_RECURSE ${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild)
set(PACKAGE_INFO "${PACKAGE_INFO} to ${download_directory}")
endif()
file(LOCK ${download_directory}/../cmake.lock) file(LOCK ${download_directory}/../cmake.lock)
endif() endif()
if(NOT "${DOWNLOAD_ONLY}") if(NOT "${DOWNLOAD_ONLY}")
cpm_create_module_file(${CPM_ARGS_NAME} "CPMAddPackage(\"${ARGN}\")") cpm_create_module_file(${CPM_ARGS_NAME})
endif() endif()
FetchContent_Declare(${CPM_ARGS_NAME} FetchContent_Declare(${CPM_ARGS_NAME}
@ -346,8 +415,7 @@ function(CPMAddPackage)
${fetchContentURLArgs} ${fetchContentURLArgs}
${fetchContentPatchArgs} ${fetchContentPatchArgs}
SOURCE_DIR ${fetch_source_dir} SOURCE_DIR ${fetch_source_dir}
DOWNLOAD_NO_PROGRESS TRUE DOWNLOAD_NO_PROGRESS TRUE)
)
if(DOWNLOAD_ONLY) if(DOWNLOAD_ONLY)
FetchContent_Populate(${CPM_ARGS_NAME} FetchContent_Populate(${CPM_ARGS_NAME}
@ -355,20 +423,26 @@ function(CPMAddPackage)
SOURCE_DIR "${fetch_source_dir}" SOURCE_DIR "${fetch_source_dir}"
BINARY_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build" BINARY_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build"
SUBBUILD_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild" SUBBUILD_DIR "${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-subbuild"
DOWNLOAD_NO_PROGRESS TRUE DOWNLOAD_NO_PROGRESS TRUE)
)
else() else()
FetchContent_MakeAvailable(${CPM_ARGS_NAME}) FetchContent_MakeAvailable(${CPM_ARGS_NAME})
endif() endif()
# Write patch key.
if(NOT DEFINED CPM_ARGS_SOURCE_DIR AND EXISTS ${download_directory})
file(WRITE "${patch_key_file}" "${expected_patch_key}")
endif()
if(NOT DEFINED CPM_ARGS_SOURCE_DIR) if(NOT DEFINED CPM_ARGS_SOURCE_DIR)
file(LOCK ${download_directory}/../cmake.lock RELEASE) file(LOCK ${download_directory}/../cmake.lock RELEASE)
endif() endif()
FetchContent_GetProperties(${CPM_ARGS_NAME}) FetchContent_GetProperties(${CPM_ARGS_NAME})
cpm_store_fetch_properties( cpm_store_fetch_properties(
${CPM_ARGS_NAME} ${${lower_case_name}_SOURCE_DIR} ${${lower_case_name}_BINARY_DIR} ${CPM_ARGS_NAME}
) ${${lower_case_name}_SOURCE_DIR}
${${lower_case_name}_BINARY_DIR})
cpm_get_fetch_properties("${CPM_ARGS_NAME}") cpm_get_fetch_properties("${CPM_ARGS_NAME}")
set(${CPM_ARGS_NAME}_ADDED YES) set(${CPM_ARGS_NAME}_ADDED YES)
@ -378,22 +452,10 @@ endfunction()
# export variables available to the caller to the # export variables available to the caller to the
# parent scope expects ${CPM_ARGS_NAME} to be set # parent scope expects ${CPM_ARGS_NAME} to be set
macro(cpm_export_variables name) macro(cpm_export_variables name)
set(${name}_SOURCE_DIR set(${name}_SOURCE_DIR "${${name}_SOURCE_DIR}" PARENT_SCOPE)
"${${name}_SOURCE_DIR}" set(${name}_BINARY_DIR "${${name}_BINARY_DIR}" PARENT_SCOPE)
PARENT_SCOPE set(${name}_ADDED "${${name}_ADDED}" PARENT_SCOPE)
) set(CPM_LAST_PACKAGE_NAME "${name}" PARENT_SCOPE)
set(${name}_BINARY_DIR
"${${name}_BINARY_DIR}"
PARENT_SCOPE
)
set(${name}_ADDED
"${${name}_ADDED}"
PARENT_SCOPE
)
set(CPM_LAST_PACKAGE_NAME
"${name}"
PARENT_SCOPE
)
endmacro() endmacro()
# registers a package that has been added to CPM # registers a package that has been added to CPM

View file

@ -63,8 +63,9 @@ else()
endif() endif()
# Utility stuff # Utility stuff
function(cpm_utils_message level name message) function(cpm_utils_message level)
message(${level} "[CPMUtil] ${name}: ${message}") string(REPLACE ";" " " message "${ARGN}")
message(${level} "[CPMUtil] ${message}")
endfunction() endfunction()
# propagate a variable to parent scope # propagate a variable to parent scope
@ -189,7 +190,7 @@ macro(parse_object object)
get_json_element("${object}" git_host git_host "github.com") get_json_element("${object}" git_host git_host "github.com")
if (NOT version) if (NOT version)
cpm_utils_message(FATAL_ERROR "${JSON_NAME}" "version is required") cpm_utils_message(FATAL_ERROR "${JSON_NAME}: version is required")
endif() endif()
if(ci) if(ci)
@ -241,8 +242,9 @@ macro(parse_object object)
set(full_patch set(full_patch
"${CPMUTIL_PATCH_DIR}/${JSON_NAME}/${_patch}") "${CPMUTIL_PATCH_DIR}/${JSON_NAME}/${_patch}")
if(NOT EXISTS ${full_patch}) if(NOT EXISTS ${full_patch})
cpm_utils_message(FATAL_ERROR ${JSON_NAME} cpm_utils_message(FATAL_ERROR
"specifies patch ${full_patch} which does not exist") "${JSON_NAME} specifies patch"
"${full_patch} which does not exist")
endif() endif()
list(APPEND patches "${full_patch}") list(APPEND patches "${full_patch}")
@ -294,20 +296,18 @@ function(AddJsonPackage)
endif() endif()
if(NOT DEFINED CPMFILE_CONTENT) if(NOT DEFINED CPMFILE_CONTENT)
cpm_utils_message(FATAL_ERROR ${name} cpm_utils_message(FATAL_ERROR "${name}: No cpmfile present")
"No cpmfile present")
return()
endif() endif()
if(NOT DEFINED JSON_NAME) if(NOT DEFINED JSON_NAME)
cpm_utils_message(FATAL_ERROR "json package" "No name specified") cpm_utils_message(FATAL_ERROR "AddJsonPackage: No name specified")
endif() endif()
string(JSON object ERROR_VARIABLE string(JSON object ERROR_VARIABLE
err GET "${CPMFILE_CONTENT}" "${JSON_NAME}") err GET "${CPMFILE_CONTENT}" "${JSON_NAME}")
if(err) if(err)
cpm_utils_message(FATAL_ERROR ${JSON_NAME} "Not found in cpmfile") cpm_utils_message(FATAL_ERROR "${JSON_NAME} not found in cpmfile")
endif() endif()
parse_object(${object}) parse_object(${object})
@ -402,11 +402,11 @@ function(AddPackage)
"${ARGN}") "${ARGN}")
if(NOT DEFINED PKG_ARGS_NAME) if(NOT DEFINED PKG_ARGS_NAME)
cpm_utils_message(FATAL_ERROR "AddPackage" "NAME is required") cpm_utils_message(FATAL_ERROR "AddPackage: NAME is required")
endif() endif()
if(NOT DEFINED PKG_ARGS_VERSION) if(NOT DEFINED PKG_ARGS_VERSION)
cpm_utils_message(FATAL_ERROR "${PKG_ARGS_NAME}" "VERSION is required") cpm_utils_message(FATAL_ERROR "${PKG_ARGS_NAME}: VERSION is required")
endif() endif()
set(${PKG_ARGS_NAME}_CUSTOM_DIR "" CACHE STRING set(${PKG_ARGS_NAME}_CUSTOM_DIR "" CACHE STRING
@ -448,11 +448,11 @@ function(AddPackage)
endif() endif()
endif() endif()
else() else()
cpm_utils_message(FATAL_ERROR ${PKG_ARGS_NAME} cpm_utils_message(FATAL_ERROR
"No URL or repository defined") "${PKG_ARGS_NAME}: No URL or repository defined")
endif() endif()
cpm_utils_message(DEBUG ${PKG_ARGS_NAME} "Download URL is ${pkg_url}") cpm_utils_message(DEBUG "${PKG_ARGS_NAME} download URL is ${pkg_url}")
# TODO: maybe singular version/ref that detects sha/tag? # TODO: maybe singular version/ref that detects sha/tag?
if(DEFINED PKG_ARGS_SHA) if(DEFINED PKG_ARGS_SHA)
@ -464,8 +464,7 @@ function(AddPackage)
if(DEFINED PKG_ARGS_HASH) if(DEFINED PKG_ARGS_HASH)
set(pkg_hash "SHA512=${PKG_ARGS_HASH}") set(pkg_hash "SHA512=${PKG_ARGS_HASH}")
else() else()
cpm_utils_message(FATAL_ERROR ${PKG_ARGS_NAME} cpm_utils_message(FATAL_ERROR "${PKG_ARGS_NAME}: No hash defined")
"No hash defined")
endif() endif()
#[[ #[[
@ -547,18 +546,22 @@ function(AddPackage)
if (PKG_ARGS_PATCHES) if (PKG_ARGS_PATCHES)
list(APPEND EXTRA_ARGS PATCHES "${PKG_ARGS_PATCHES}") list(APPEND EXTRA_ARGS PATCHES "${PKG_ARGS_PATCHES}")
endif() endif()
if (PKG_ARGS_OPTIONS) if (PKG_ARGS_OPTIONS)
list(APPEND EXTRA_ARGS OPTIONS "${PKG_ARGS_OPTIONS}") list(APPEND EXTRA_ARGS OPTIONS "${PKG_ARGS_OPTIONS}")
endif() endif()
if (PKG_ARGS_SOURCE_SUBDIR) if (PKG_ARGS_SOURCE_SUBDIR)
list(APPEND EXTRA_ARGS SOURCE_SUBDIR "${PKG_ARGS_SOURCE_SUBDIR}") list(APPEND EXTRA_ARGS SOURCE_SUBDIR "${PKG_ARGS_SOURCE_SUBDIR}")
endif() endif()
if (PKG_ARGS_DOWNLOAD_ONLY OR PKG_ARGS_MODULE_PATH) if (PKG_ARGS_DOWNLOAD_ONLY OR PKG_ARGS_MODULE_PATH)
list(APPEND EXTRA_ARGS DOWNLOAD_ONLY ON) list(APPEND EXTRA_ARGS DOWNLOAD_ONLY ON)
endif() endif()
message(STATUS cpm_utils_message(STATUS
"[CPMUtil] Using bundled package ${PKG_ARGS_NAME}@${PKG_ARGS_VERSION} (${pkg_key})") "Using bundled package"
"${PKG_ARGS_NAME}@${PKG_ARGS_VERSION} (${pkg_key})")
CPMAddPackage( CPMAddPackage(
NAME ${PKG_ARGS_NAME} NAME ${PKG_ARGS_NAME}
@ -612,18 +615,20 @@ function(AddCIPackage)
"${multiValueArgs}" "${multiValueArgs}"
${ARGN}) ${ARGN})
# TODO: use cpm_utils_message
if(NOT DEFINED PKG_ARGS_VERSION) if(NOT DEFINED PKG_ARGS_VERSION)
message(FATAL_ERROR "[CPMUtil] VERSION is required") cpm_utils_message(FATAL_ERROR "VERSION is required")
endif() endif()
if(NOT DEFINED PKG_ARGS_NAME) if(NOT DEFINED PKG_ARGS_NAME)
message(FATAL_ERROR "[CPMUtil] NAME is required") cpm_utils_message(FATAL_ERROR "NAME is required")
endif() endif()
if(NOT DEFINED PKG_ARGS_REPO) if(NOT DEFINED PKG_ARGS_REPO)
message(FATAL_ERROR "[CPMUtil] REPO is required") cpm_utils_message(FATAL_ERROR "REPO is required")
endif() endif()
if(NOT DEFINED PKG_ARGS_PACKAGE) if(NOT DEFINED PKG_ARGS_PACKAGE)
message(FATAL_ERROR "[CPMUtil] PACKAGE is required") cpm_utils_message(FATAL_ERROR "PACKAGE is required")
endif() endif()
if(NOT DEFINED PKG_ARGS_CMAKE_FILENAME) if(NOT DEFINED PKG_ARGS_CMAKE_FILENAME)
@ -674,7 +679,7 @@ function(AddCIPackage)
elseif(APPLE) elseif(APPLE)
set(platname macos) set(platname macos)
else() else()
cpm_utils_message(WARNING ${PKG_ARGS_NAME} cpm_utils_message(WARNING
"Unsupported platform ${CMAKE_SYSTEM_NAME} for CI packages") "Unsupported platform ${CMAKE_SYSTEM_NAME} for CI packages")
endif() endif()
@ -689,7 +694,7 @@ function(AddCIPackage)
elseif(ANDROID AND CPMUTIL_AMD64) elseif(ANDROID AND CPMUTIL_AMD64)
set(archname x86_64) set(archname x86_64)
else() else()
cpm_utils_message(WARNING ${PKG_ARGS_NAME} cpm_utils_message(WARNING
"Unsupported platform/arch combo for CI packages") "Unsupported platform/arch combo for CI packages")
endif() endif()
@ -707,7 +712,7 @@ function(AddCIPackage)
endif() endif()
# download sha512sum file # download sha512sum file
# TODO: # TODO: CI pkgs
set(sha512sum_url set(sha512sum_url
"https://${ARTIFACT_GIT_HOST}/${ARTIFACT_REPO}/releases/download/v${ARTIFACT_VERSION}/${ARTIFACT}.sha512sum") "https://${ARTIFACT_GIT_HOST}/${ARTIFACT_REPO}/releases/download/v${ARTIFACT_VERSION}/${ARTIFACT}.sha512sum")
set(sha512sum_file set(sha512sum_file

View file

@ -223,6 +223,6 @@ jq --arg key "$PKG" --argjson new "$JSON" \
'.[$key] = $new' "cpmfile.json" --indent 4 >"cpmfile.json.tmp" && '.[$key] = $new' "cpmfile.json" --indent 4 >"cpmfile.json.tmp" &&
mv "cpmfile.json.tmp" cpmfile.json mv "cpmfile.json.tmp" cpmfile.json
"$SCRIPTS"/format.sh "$SCRIPTS"/../format.sh
echo "Added package $PKG to cpmfile.json. Include it in your project with AddJsonPackage($PKG)" echo "Added package $PKG to cpmfile.json. Include it in your project with AddJsonPackage($PKG)"