2021-08-08 02:37:09 +03:00
|
|
|
#
|
|
|
|
# Functions for generating sources using host tools
|
|
|
|
#
|
|
|
|
|
|
|
|
function(compile_gml source output string_name)
|
|
|
|
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${output}
|
|
|
|
COMMAND ${SerenityOS_SOURCE_DIR}/Meta/text-to-cpp-string.sh ${string_name} ${source} > ${output}.tmp
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${output}.tmp ${output}
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -E remove ${output}.tmp
|
|
|
|
VERBATIM
|
|
|
|
DEPENDS ${SerenityOS_SOURCE_DIR}/Meta/text-to-cpp-string.sh
|
|
|
|
MAIN_DEPENDENCY ${source}
|
|
|
|
)
|
|
|
|
get_filename_component(output_name ${output} NAME)
|
|
|
|
add_custom_target(generate_${output_name} DEPENDS ${output})
|
2021-08-30 05:27:50 +03:00
|
|
|
add_dependencies(all_generated generate_${output_name})
|
2021-08-08 02:37:09 +03:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(compile_ipc source output)
|
|
|
|
set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${output}
|
2021-09-07 09:54:27 +03:00
|
|
|
COMMAND $<TARGET_FILE:Lagom::IPCCompiler> ${source} > ${output}.tmp
|
2021-08-08 02:37:09 +03:00
|
|
|
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${output}.tmp ${output}
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -E remove ${output}.tmp
|
|
|
|
VERBATIM
|
2021-09-07 09:54:27 +03:00
|
|
|
DEPENDS Lagom::IPCCompiler
|
2021-08-08 02:37:09 +03:00
|
|
|
MAIN_DEPENDENCY ${source}
|
|
|
|
)
|
|
|
|
get_filename_component(output_name ${output} NAME)
|
|
|
|
add_custom_target(generate_${output_name} DEPENDS ${output})
|
2021-08-30 05:27:50 +03:00
|
|
|
add_dependencies(all_generated generate_${output_name})
|
2022-03-19 13:31:59 +03:00
|
|
|
|
2022-03-19 18:15:08 +03:00
|
|
|
# TODO: Use cmake_path() when we upgrade the minimum CMake version to 3.20
|
|
|
|
# https://cmake.org/cmake/help/v3.23/command/cmake_path.html#relative-path
|
2022-03-19 13:31:59 +03:00
|
|
|
string(LENGTH ${SerenityOS_SOURCE_DIR} root_source_dir_length)
|
|
|
|
string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${root_source_dir_length} -1 current_source_dir_relative)
|
2022-07-04 20:01:05 +03:00
|
|
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${output} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${current_source_dir_relative}" OPTIONAL)
|
2021-08-08 02:37:09 +03:00
|
|
|
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}
|
2021-09-07 09:54:27 +03:00
|
|
|
COMMAND $<TARGET_FILE:Lagom::StateMachineGenerator> ${source} > ${output}.tmp
|
2021-08-08 02:37:09 +03:00
|
|
|
COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${output}.tmp ${output}
|
|
|
|
COMMAND "${CMAKE_COMMAND}" -E remove ${output}.tmp
|
|
|
|
VERBATIM
|
2021-09-07 09:54:27 +03:00
|
|
|
DEPENDS Lagom::StateMachineGenerator
|
2021-08-08 02:37:09 +03:00
|
|
|
MAIN_DEPENDENCY ${source}
|
|
|
|
)
|
|
|
|
add_custom_target(${target_name} DEPENDS ${output})
|
2021-08-30 05:27:50 +03:00
|
|
|
add_dependencies(all_generated ${target_name})
|
2021-08-08 02:37:09 +03:00
|
|
|
endif()
|
|
|
|
endfunction()
|