2021-08-07 23:37:09 +00:00
|
|
|
#
|
|
|
|
# Functions for generating sources using host tools
|
|
|
|
#
|
|
|
|
|
2024-08-22 11:42:12 +00:00
|
|
|
function(embed_as_string name source_file output source_variable_name)
|
2023-08-23 19:38:28 +00:00
|
|
|
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()
|
2023-11-05 09:52:27 +00:00
|
|
|
find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
2023-08-23 19:38:28 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${output}"
|
2024-08-22 11:42:12 +00:00
|
|
|
COMMAND "${Python3_EXECUTABLE}" "${SerenityOS_SOURCE_DIR}/Meta/embed_as_string.py" "${source_file}" -o "${output}.tmp" -n "${source_variable_name}" ${namespace_arg}
|
2023-08-23 19:38:28 +00:00
|
|
|
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${output}.tmp" "${output}"
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -E remove "${output}.tmp"
|
|
|
|
VERBATIM
|
2024-08-22 11:42:12 +00:00
|
|
|
DEPENDS "${SerenityOS_SOURCE_DIR}/Meta/embed_as_string.py"
|
2023-08-23 19:38:28 +00:00
|
|
|
MAIN_DEPENDENCY "${source_file}"
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target("generate_${name}" DEPENDS "${output}")
|
|
|
|
add_dependencies(all_generated "generate_${name}")
|
|
|
|
endfunction()
|
2024-08-06 02:45:00 +00:00
|
|
|
|
|
|
|
function(generate_clang_module_map target_name)
|
2024-11-14 23:05:08 +00:00
|
|
|
cmake_parse_arguments(PARSE_ARGV 1 MODULE_MAP "" "DIRECTORY" "GENERATED_FILES;EXCLUDE_FILES")
|
2024-08-06 02:45:00 +00:00
|
|
|
if (NOT MODULE_MAP_DIRECTORY)
|
|
|
|
set(MODULE_MAP_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
|
|
|
|
endif()
|
|
|
|
|
2024-08-27 01:04:05 +00:00
|
|
|
string(REPLACE "Lib" "" module_name ${target_name})
|
|
|
|
set(module_name "${module_name}Cxx")
|
|
|
|
|
2024-08-06 02:45:00 +00:00
|
|
|
set(module_map_file "${CMAKE_CURRENT_BINARY_DIR}/module/module.modulemap")
|
2024-08-27 01:04:05 +00:00
|
|
|
set(vfs_overlay_file "${VFS_OVERLAY_DIRECTORY}/${target_name}_vfs_overlay.yaml")
|
2024-08-06 02:45:00 +00:00
|
|
|
|
|
|
|
find_package(Python3 REQUIRED COMPONENTS Interpreter)
|
|
|
|
# FIXME: Make this depend on the public headers of the target
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT "${module_map_file}"
|
2024-08-27 01:04:05 +00:00
|
|
|
COMMAND "${Python3_EXECUTABLE}" "${SerenityOS_SOURCE_DIR}/Meta/generate_clang_module_map.py"
|
|
|
|
"${MODULE_MAP_DIRECTORY}"
|
|
|
|
--module-name "${module_name}"
|
|
|
|
--module-map "${module_map_file}"
|
|
|
|
--vfs-map ${vfs_overlay_file}
|
2024-11-14 23:05:08 +00:00
|
|
|
--exclude-files ${MODULE_MAP_EXCLUDE_FILES}
|
|
|
|
--generated-files ${MODULE_MAP_GENERATED_FILES}
|
2024-08-06 02:45:00 +00:00
|
|
|
VERBATIM
|
|
|
|
DEPENDS "${SerenityOS_SOURCE_DIR}/Meta/generate_clang_module_map.py"
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target("generate_${target_name}_module_map" DEPENDS "${module_map_file}")
|
|
|
|
add_dependencies(all_generated "generate_${target_name}_module_map")
|
|
|
|
add_dependencies("${target_name}" "generate_${target_name}_module_map")
|
|
|
|
|
|
|
|
target_compile_options(${target_name} PUBLIC "SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xcc -ivfsoverlay${vfs_overlay_file}>")
|
|
|
|
endfunction()
|
2023-08-23 19:38:28 +00:00
|
|
|
|
2021-08-07 23:37:09 +00:00
|
|
|
function(compile_ipc source output)
|
2022-10-06 09:23:53 +00:00
|
|
|
if (NOT IS_ABSOLUTE ${source})
|
|
|
|
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
|
|
|
|
endif()
|
2021-08-07 23:37:09 +00:00
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${output}
|
2023-04-24 09:00:34 +00:00
|
|
|
COMMAND $<TARGET_FILE:Lagom::IPCCompiler> ${source} -o ${output}.tmp
|
2021-08-07 23:37:09 +00:00
|
|
|
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${output}.tmp ${output}
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -E remove ${output}.tmp
|
|
|
|
VERBATIM
|
2021-09-07 06:54:27 +00:00
|
|
|
DEPENDS Lagom::IPCCompiler
|
2021-08-07 23:37:09 +00:00
|
|
|
MAIN_DEPENDENCY ${source}
|
|
|
|
)
|
|
|
|
get_filename_component(output_name ${output} NAME)
|
|
|
|
add_custom_target(generate_${output_name} DEPENDS ${output})
|
2021-08-30 02:27:50 +00:00
|
|
|
add_dependencies(all_generated generate_${output_name})
|
2022-03-19 10:31:59 +00:00
|
|
|
|
2024-04-25 17:30:44 +00:00
|
|
|
cmake_path(RELATIVE_PATH CMAKE_CURRENT_SOURCE_DIR BASE_DIRECTORY ${SerenityOS_SOURCE_DIR} OUTPUT_VARIABLE current_source_dir_relative)
|
2024-07-20 17:03:24 +00:00
|
|
|
if (ENABLE_INSTALL_HEADERS)
|
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${output} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${current_source_dir_relative}" OPTIONAL)
|
|
|
|
endif()
|
2021-08-07 23:37:09 +00:00
|
|
|
endfunction()
|