diff options
author | crupest <crupest@outlook.com> | 2023-10-08 00:53:16 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-10-08 01:06:10 +0800 |
commit | c216f37a9dd3c360d390a3e134881539731186d1 (patch) | |
tree | 6705ebc8695407e6dfdbc00c4a544cd9ac73a788 /scripts/cmake | |
parent | 4283858191d39d0babdaa63f5f3c1a0f365b6543 (diff) | |
download | cru-c216f37a9dd3c360d390a3e134881539731186d1.tar.gz cru-c216f37a9dd3c360d390a3e134881539731186d1.tar.bz2 cru-c216f37a9dd3c360d390a3e134881539731186d1.zip |
Use clangd config file in emscripten.
Diffstat (limited to 'scripts/cmake')
-rw-r--r-- | scripts/cmake/patch-compile-commands.cmake | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/scripts/cmake/patch-compile-commands.cmake b/scripts/cmake/patch-compile-commands.cmake new file mode 100644 index 00000000..d855ce3c --- /dev/null +++ b/scripts/cmake/patch-compile-commands.cmake @@ -0,0 +1,28 @@ +function (patch_compile_commands input output_var) + set(ENTRY_FILE ${CMAKE_BINARY_DIR}/compile_commands_entry) + set(RESULT "[]") + string(JSON COUNT LENGTH "${input}") + message("Total commands need to patch: " ${COUNT}) + math(EXPR COUNT "${COUNT} - 1") + foreach(INDEX RANGE ${COUNT}) + message("Patching: " ${INDEX} "/" ${COUNT}) + string(JSON ORIGINAL_COMMAND GET "${input}" ${INDEX} command) + string(JSON WORKING_DIR GET "${input}" ${INDEX} directory) + string(FIND "${ORIGINAL_COMMAND}" " " COMMAND_FIRST_SPACE) + string(SUBSTRING "${ORIGINAL_COMMAND}" 0 ${COMMAND_FIRST_SPACE} COMMAND_COMPILER) + string(SUBSTRING "${ORIGINAL_COMMAND}" ${COMMAND_FIRST_SPACE} -1 ORIGINAL_COMMAND_ARGS) + string(CONCAT COMMAND_GENERATE "${COMMAND_COMPILER}" " -MJ ${ENTRY_FILE}" "${ORIGINAL_COMMAND_ARGS}") + #message("Run: " "${COMMAND_GENERATE}") + execute_process(COMMAND sh -c "${COMMAND_GENERATE}" WORKING_DIRECTORY "${WORKING_DIR}") + file(READ ${ENTRY_FILE} ENTRY) + string(JSON RESULT SET "${RESULT}" ${INDEX} "${ENTRY}") + endforeach() + set(${output_var} "${RESULT}" PARENT_SCOPE) +endfunction() + +function (patch_compile_commands_file) + file(READ ${CMAKE_BINARY_DIR}/compile_commands.json COMPILE_COMMANDS) + patch_compile_commands("${COMPILE_COMMANDS}" COMPILE_COMMANDS_PATCHED) + file(WRITE ${CMAKE_BINARY_DIR}/compile_commands-patched.json "${COMPILE_COMMANDS_PATCHED}") +endfunction() + |