Meta: Make embed_as_string_view.py usable by CMake builds :^)

This commit is contained in:
Sam Atkins 2023-08-23 20:38:28 +01:00 committed by Sam Atkins
parent 4ead33d8fc
commit af4642c826
Notes: sideshowbarker 2024-07-16 23:05:02 +09:00
3 changed files with 21 additions and 1 deletions

View file

@ -2,6 +2,26 @@
# Functions for generating sources using host tools
#
function(embed_as_string_view name source_file output source_variable_name)
cmake_parse_arguments(PARSE_ARGV 4 EMBED_STRING_VIEW "" "NAMESPACE" "")
set(namespace_arg "")
if (EMBED_STRING_VIEW_NAMESPACE)
set(namespace_arg "-s ${EMBED_STRING_VIEW_NAMESPACE}")
endif()
add_custom_command(
OUTPUT "${output}"
COMMAND "python3" "${SerenityOS_SOURCE_DIR}/Meta/embed_as_string_view.py" "${source_file}" -o "${output}.tmp" -n "${source_variable_name}" ${namespace_arg}
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${output}.tmp" "${output}"
COMMAND "${CMAKE_COMMAND}" -E remove "${output}.tmp"
VERBATIM
DEPENDS "${SerenityOS_SOURCE_DIR}/Meta/embed_as_string_view.py"
MAIN_DEPENDENCY "${source_file}"
)
add_custom_target("generate_${name}" DEPENDS "${output}")
add_dependencies(all_generated "generate_${name}")
endfunction()
function(stringify_gml source output string_name)
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
add_custom_command(

View file

@ -33,7 +33,7 @@ template("embed_as_string_view") {
"must set 'variable_name' in $target_name")
action(target_name) {
script = "//Meta/gn/build/embed_as_string_view.py"
script = "//Meta/embed_as_string_view.py"
sources = [ invoker.input ]
outputs = [ invoker.output ]