summaryrefslogtreecommitdiff
path: root/runtimes
diff options
context:
space:
mode:
authorJoseph Huber <huberjn@outlook.com>2024-11-27 20:14:26 -0600
committerGitHub <noreply@github.com>2024-11-27 20:14:26 -0600
commit054f914741421ca9dd1eaa58ea74a20f8695bae6 (patch)
treed1f763c619116f053d1d702ee8fbd869cbbc98fc /runtimes
parenta24aa7dfa579c41365f23f8205b619b838e32184 (diff)
[Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
Summary: When building a project in a runtime mode, the compilation database is a separate CMake invocation. So its `compile_commands.json` file will be placed elsewhere in the `runtimes/runtime-bins` directory. This is somewhat annoying for ongoing development when a runtimes build is necessary. This patch adds some CMake magic to merge the two files.
Diffstat (limited to 'runtimes')
-rw-r--r--runtimes/CMakeLists.txt18
1 files changed, 18 insertions, 0 deletions
diff --git a/runtimes/CMakeLists.txt b/runtimes/CMakeLists.txt
index ef8ec171a165..17badc3ff96d 100644
--- a/runtimes/CMakeLists.txt
+++ b/runtimes/CMakeLists.txt
@@ -346,3 +346,21 @@ if(SUB_COMPONENTS)
${CMAKE_CURRENT_BINARY_DIR}/runtimes/Components.cmake)
endif()
endif()
+
+# If the user requested 'compile_commands.json' we merge the generated JSON from
+# the created directories.
+if(CMAKE_EXPORT_COMPILE_COMMANDS)
+ # Make a dependency so that we don't error if the file gets deleted somehow.
+ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/compile_commands.json
+ COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_BINARY_DIR}/compile_commands.json)
+
+ file(TO_NATIVE_PATH "${LLVM_MAIN_SRC_DIR}/utils/merge-json.py" MERGE_JSON_PATH)
+ add_custom_command(OUTPUT ${LLVM_BINARY_DIR}/compile_commands.json
+ COMMAND ${CMAKE_COMMAND} -E touch ${LLVM_BINARY_DIR}/compile_commands.json
+ COMMAND ${Python3_EXECUTABLE} ${MERGE_JSON_PATH}
+ ${LLVM_BINARY_DIR}/compile_commands.json
+ ${CMAKE_BINARY_DIR}/compile_commands.json
+ -o ${LLVM_BINARY_DIR}/compile_commands.json
+ DEPENDS ${CMAKE_BINARY_DIR}/compile_commands.json)
+ add_custom_target(merge_runtime_commands ALL DEPENDS ${LLVM_BINARY_DIR}/compile_commands.json)
+endif()