aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2023-10-08 00:09:11 +0800
committercrupest <crupest@outlook.com>2023-10-08 00:09:11 +0800
commit4283858191d39d0babdaa63f5f3c1a0f365b6543 (patch)
tree68e3be0b78c21c1082f36cadf35da1a90a1fa993
parentb8777965040e0f5e80b4395a912ddca7999fd80c (diff)
downloadcru-4283858191d39d0babdaa63f5f3c1a0f365b6543.tar.gz
cru-4283858191d39d0babdaa63f5f3c1a0f365b6543.tar.bz2
cru-4283858191d39d0babdaa63f5f3c1a0f365b6543.zip
Add patch_compile_commands. So slow, useless.
-rw-r--r--CMakeLists.txt27
1 files changed, 27 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cca0b97e..9e364e63 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,4 +53,31 @@ add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(demos)
+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()