Просмотр исходного кода

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.
Andrew Kaster 4 лет назад
Родитель
Сommit
20e904d87c
2 измененных файлов с 56 добавлено и 47 удалено
  1. 55 0
      Meta/CMake/code_generators.cmake
  2. 1 47
      Meta/CMake/utils.cmake

+ 55 - 0
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()

+ 1 - 47
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()