mirror of https://github.com/microsoft/vcpkg.git
74 lines
3.1 KiB
CMake
74 lines
3.1 KiB
CMake
function(z_vcpkg_spdx_json_string_encode_compat out_var value)
|
|
set(encoded "${value}")
|
|
string(REPLACE "\\" "\\\\" encoded "${encoded}") # that is, replace \ with \\
|
|
string(REPLACE "\"" "\\\"" encoded "${encoded}") # that is, replace " with \"
|
|
string(ASCII 8 backspace)
|
|
string(ASCII 12 form_feed)
|
|
string(REPLACE "${backspace}" "\\b" encoded "${encoded}")
|
|
string(REPLACE "${form_feed}" "\\f" encoded "${encoded}")
|
|
string(REPLACE "\n" "\\n" encoded "${encoded}")
|
|
string(REPLACE "\r" "\\r" encoded "${encoded}")
|
|
string(REPLACE "\t" "\\t" encoded "${encoded}")
|
|
|
|
foreach(code RANGE 1 31)
|
|
string(ASCII "${code}" character)
|
|
math(EXPR hexadecimal "${code}" OUTPUT_FORMAT HEXADECIMAL)
|
|
string(SUBSTRING "${hexadecimal}" 2 -1 hexadecimal)
|
|
if(code LESS 16)
|
|
set(escape "\\u000${hexadecimal}")
|
|
else()
|
|
set(escape "\\u00${hexadecimal}")
|
|
endif()
|
|
string(REPLACE "${character}" "${escape}" encoded "${encoded}")
|
|
endforeach()
|
|
|
|
set("${out_var}" "\"${encoded}\"" PARENT_SCOPE)
|
|
endfunction()
|
|
|
|
function(z_vcpkg_spdx_json_string_encode out_var value)
|
|
if(CMAKE_VERSION VERSION_GREATER_EQUAL "4.3")
|
|
string(JSON encoded STRING_ENCODE "${value}")
|
|
else()
|
|
z_vcpkg_spdx_json_string_encode_compat(encoded "${value}")
|
|
endif()
|
|
set("${out_var}" "${encoded}" PARENT_SCOPE)
|
|
endfunction()
|
|
|
|
function(z_vcpkg_add_spdx_resource)
|
|
cmake_parse_arguments(PARSE_ARGV 0 "arg"
|
|
""
|
|
"NAME;DOWNLOAD_LOCATION;SHA512;FILENAME"
|
|
"")
|
|
if(DEFINED arg_UNPARSED_ARGUMENTS)
|
|
message(FATAL_ERROR "z_vcpkg_add_spdx_resource was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}")
|
|
endif()
|
|
|
|
get_property(Z_VCPKG_SPDX_OBJECTS GLOBAL PROPERTY Z_VCPKG_SPDX_OBJECTS)
|
|
list(LENGTH Z_VCPKG_SPDX_OBJECTS resource_index)
|
|
set(resource "{}")
|
|
|
|
string(JSON resource SET "${resource}" "SPDXID" "\"SPDXRef-resource-${resource_index}\"")
|
|
z_vcpkg_spdx_json_string_encode(value "${arg_NAME}")
|
|
string(JSON resource SET "${resource}" "name" "${value}")
|
|
if(DEFINED arg_FILENAME)
|
|
z_vcpkg_spdx_json_string_encode(value "${arg_FILENAME}")
|
|
string(JSON resource SET "${resource}" "packageFileName" "${value}")
|
|
endif()
|
|
z_vcpkg_spdx_json_string_encode(value "${arg_DOWNLOAD_LOCATION}")
|
|
string(JSON resource SET "${resource}" "downloadLocation" "${value}")
|
|
foreach(property IN ITEMS licenseConcluded licenseDeclared copyrightText)
|
|
string(JSON resource SET "${resource}" "${property}" [["NOASSERTION"]])
|
|
endforeach()
|
|
|
|
if(DEFINED arg_SHA512 AND NOT "${arg_SHA512}" STREQUAL "")
|
|
string(TOLOWER "${arg_SHA512}" sha512)
|
|
string(JSON checksum SET "{}" "algorithm" [["SHA512"]])
|
|
string(JSON checksum SET "${checksum}" "checksumValue" "\"${sha512}\"")
|
|
string(JSON checksums SET "[]" 0 "${checksum}")
|
|
string(JSON resource SET "${resource}" "checksums" "${checksums}")
|
|
endif()
|
|
|
|
vcpkg_list(APPEND Z_VCPKG_SPDX_OBJECTS "${resource}")
|
|
set_property(GLOBAL PROPERTY Z_VCPKG_SPDX_OBJECTS "${Z_VCPKG_SPDX_OBJECTS}")
|
|
endfunction()
|