summaryrefslogtreecommitdiff
path: root/Meta/CMake
diff options
context:
space:
mode:
authorAndrew Kaster <akaster@serenityos.org>2021-08-07 17:37:09 -0600
committerLinus Groh <mail@linusgroh.de>2021-08-28 08:44:17 +0100
commit20e904d87cbf225a3d8c0228fb1587951757485e (patch)
tree7b5e8e42ce90ce93906ac3977e0d6d5319531dce /Meta/CMake
parenta83847f8bf512e42dca28560f71de0800a9709af (diff)
downloadserenity-20e904d87cbf225a3d8c0228fb1587951757485e.zip
Meta: Move code generator helpers to their own CMake helper file
compile_gml, compile_ipc, and generate_state_machine all use host tools to generate sources for the target build. As part of trying to organize host tools into a common area, let's move these helper rules to a common file that we can add other host tools to later. And, keep the host tool helpers separate from the CMake target helpers for apps and libraries.
Diffstat (limited to 'Meta/CMake')
-rw-r--r--Meta/CMake/code_generators.cmake55
-rw-r--r--Meta/CMake/utils.cmake48
2 files changed, 56 insertions, 47 deletions
diff --git a/Meta/CMake/code_generators.cmake b/Meta/CMake/code_generators.cmake
new file mode 100644
index 0000000000..24a4f0f390
--- /dev/null
+++ b/Meta/CMake/code_generators.cmake
@@ -0,0 +1,55 @@
+#
+# 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})
+endfunction()
+
+function(compile_ipc source output)
+ set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
+ add_custom_command(
+ OUTPUT ${output}
+ COMMAND $<TARGET_FILE:IPCCompiler> ${source} > ${output}.tmp
+ COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${output}.tmp ${output}
+ COMMAND "${CMAKE_COMMAND}" -E remove ${output}.tmp
+ VERBATIM
+ DEPENDS IPCCompiler
+ MAIN_DEPENDENCY ${source}
+ )
+ get_filename_component(output_name ${output} NAME)
+ add_custom_target(generate_${output_name} DEPENDS ${output})
+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:StateMachineGenerator> ${source} > ${output}.tmp
+ COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${output}.tmp ${output}
+ COMMAND "${CMAKE_COMMAND}" -E remove ${output}.tmp
+ VERBATIM
+ DEPENDS StateMachineGenerator
+ MAIN_DEPENDENCY ${source}
+ )
+ add_custom_target(${target_name} DEPENDS ${output})
+ endif()
+endfunction()
diff --git a/Meta/CMake/utils.cmake b/Meta/CMake/utils.cmake
index e2a88b2375..7d1ef03552 100644
--- a/Meta/CMake/utils.cmake
+++ b/Meta/CMake/utils.cmake
@@ -1,5 +1,6 @@
include(${CMAKE_CURRENT_LIST_DIR}/serenity_components.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/code_generators.cmake)
function(serenity_install_headers target_name)
file(GLOB_RECURSE headers RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h")
@@ -137,33 +138,6 @@ function(serenity_app target_name)
endif()
endfunction()
-function(compile_gml source output string_name)
- set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
- add_custom_command(
- OUTPUT ${output}
- COMMAND ${write_if_different} ${output} ${CMAKE_SOURCE_DIR}/Meta/text-to-cpp-string.sh ${string_name} ${source}
- VERBATIM
- DEPENDS ${CMAKE_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})
-endfunction()
-
-
-function(compile_ipc source output)
- set(source ${CMAKE_CURRENT_SOURCE_DIR}/${source})
- add_custom_command(
- OUTPUT ${output}
- COMMAND ${write_if_different} ${output} ${CMAKE_BINARY_DIR}/Userland/DevTools/IPCCompiler/IPCCompiler ${source}
- VERBATIM
- DEPENDS IPCCompiler
- MAIN_DEPENDENCY ${source}
- )
- get_filename_component(output_name ${output} NAME)
- add_custom_target(generate_${output_name} DEPENDS ${output})
-endfunction()
-
function(embed_resource target section file)
get_filename_component(asm_file "${file}" NAME)
set(asm_file "${CMAKE_CURRENT_BINARY_DIR}/${target}-${section}.s")
@@ -177,23 +151,3 @@ function(embed_resource target section file)
)
target_sources("${target}" PRIVATE "${asm_file}")
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 ${write_if_different} ${output} ${CMAKE_BINARY_DIR}/Userland/DevTools/StateMachineGenerator/StateMachineGenerator ${source}
- VERBATIM
- DEPENDS StateMachineGenerator
- MAIN_DEPENDENCY ${source}
- )
- add_custom_target(${target_name} DEPENDS ${output})
- endif()
-endfunction()