mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-22 17:31:58 -05:00
5d86305596
This is only used for CSS style sheets. One case wants it as a String, and the others don't care, but will in future also want to have the source as a String. (cherry picked from commit 8cbc2116162764479edeec78e4b2b7c41447b643; amended to fix conflicts in two cmake files, due to serenity still having more code_generators, and still buildling OutOfProcessWebView.cpp. Also kept embed_as_string_view because it's used by stringify_gml. Did this by giving embed_as_string.py a --type= argument that defaults to string but can also be set to string-view.)
111 lines
4.8 KiB
CMake
111 lines
4.8 KiB
CMake
#
|
|
# Functions for generating sources using host tools
|
|
#
|
|
|
|
function(embed_as_string 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()
|
|
find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
|
add_custom_command(
|
|
OUTPUT "${output}"
|
|
COMMAND "${Python3_EXECUTABLE}" "${SerenityOS_SOURCE_DIR}/Meta/embed_as_string.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.py"
|
|
MAIN_DEPENDENCY "${source_file}"
|
|
)
|
|
|
|
add_custom_target("generate_${name}" DEPENDS "${output}")
|
|
add_dependencies(all_generated "generate_${name}")
|
|
endfunction()
|
|
|
|
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()
|
|
find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
|
add_custom_command(
|
|
OUTPUT "${output}"
|
|
COMMAND "${Python3_EXECUTABLE}" "${SerenityOS_SOURCE_DIR}/Meta/embed_as_string.py" --type=string-view "${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.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})
|
|
get_filename_component(output_name ${output} NAME)
|
|
embed_as_string_view(${output_name} ${source} ${output} ${string_name})
|
|
endfunction()
|
|
|
|
function(compile_gml source output)
|
|
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
|
|
add_custom_command(
|
|
OUTPUT ${output}
|
|
COMMAND $<TARGET_FILE:Lagom::GMLCompiler> ${source} > ${output}.tmp
|
|
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${output}.tmp ${output}
|
|
COMMAND "${CMAKE_COMMAND}" -E remove ${output}.tmp
|
|
VERBATIM
|
|
DEPENDS Lagom::GMLCompiler
|
|
MAIN_DEPENDENCY ${source}
|
|
)
|
|
get_filename_component(output_name ${output} NAME)
|
|
add_custom_target(generate_${output_name} DEPENDS ${output})
|
|
add_dependencies(all_generated generate_${output_name})
|
|
endfunction()
|
|
|
|
function(compile_ipc source output)
|
|
if (NOT IS_ABSOLUTE ${source})
|
|
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
|
|
endif()
|
|
add_custom_command(
|
|
OUTPUT ${output}
|
|
COMMAND $<TARGET_FILE:Lagom::IPCCompiler> ${source} -o ${output}.tmp
|
|
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${output}.tmp ${output}
|
|
COMMAND "${CMAKE_COMMAND}" -E remove ${output}.tmp
|
|
VERBATIM
|
|
DEPENDS Lagom::IPCCompiler
|
|
MAIN_DEPENDENCY ${source}
|
|
)
|
|
get_filename_component(output_name ${output} NAME)
|
|
add_custom_target(generate_${output_name} DEPENDS ${output})
|
|
add_dependencies(all_generated generate_${output_name})
|
|
|
|
cmake_path(RELATIVE_PATH CMAKE_CURRENT_SOURCE_DIR BASE_DIRECTORY ${SerenityOS_SOURCE_DIR} OUTPUT_VARIABLE current_source_dir_relative)
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${output} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${current_source_dir_relative}" OPTIONAL)
|
|
endfunction()
|
|
|
|
function(generate_state_machine source header)
|
|
get_filename_component(header_name ${header} NAME)
|
|
set(target_name "generate_${header_name}")
|
|
# Note: This function is called twice with the same header, once in the kernel
|
|
# and once in Userland/LibVT, this check makes sure that only one target
|
|
# is generated for that header.
|
|
if(NOT TARGET ${target_name})
|
|
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
|
|
set(output ${CMAKE_CURRENT_BINARY_DIR}/${header})
|
|
add_custom_command(
|
|
OUTPUT ${output}
|
|
COMMAND $<TARGET_FILE:Lagom::StateMachineGenerator> ${source} -o ${output}.tmp
|
|
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${output}.tmp ${output}
|
|
COMMAND "${CMAKE_COMMAND}" -E remove ${output}.tmp
|
|
VERBATIM
|
|
DEPENDS Lagom::StateMachineGenerator
|
|
MAIN_DEPENDENCY ${source}
|
|
)
|
|
add_custom_target(${target_name} DEPENDS ${output})
|
|
add_dependencies(all_generated ${target_name})
|
|
endif()
|
|
endfunction()
|