Skip to content

Commit

Permalink
Changes to incline local includes:
Browse files Browse the repository at this point in the history
- #include must be the start of a line
- the inlined included is placed in the same line as the original
  #include
  • Loading branch information
loostrum committed Jul 18, 2024
1 parent f91ffff commit 8fe7d64
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions cmake/cudawrappers-helper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
# '#include "helper.h"` will lead to `helper.h` being inlined.
function(inline_local_includes input_file output_file)
file(READ ${input_file} input_file_contents)
set(include_regex "#include[ \t]*\"([^\"]+)\"")
set(include_regex "(^|\r?\n)(#include[ \t]*\"([^\"]+)\")")
string(REGEX MATCHALL ${include_regex} includes ${input_file_contents})
string(REGEX REPLACE ${include_regex} "" input_file_contents
"${input_file_contents}"
)
set(include_files "")
foreach(include ${includes})
string(REGEX REPLACE ${include_regex} "\\1" include ${include})
file(GLOB_RECURSE INCLUDE_PATHS "${PROJECT_SOURCE_DIR}/*/${include}")
string(REGEX REPLACE ${include_regex} "\\3" include_name ${include})
string(REGEX REPLACE ${include_regex} "\\2" include_line ${include})
file(GLOB_RECURSE INCLUDE_PATHS "${PROJECT_SOURCE_DIR}/*/${include_name}")
if(NOT INCLUDE_PATHS STREQUAL "")
list(SORT INCLUDE_PATHS ORDER DESCENDING)
list(GET INCLUDE_PATHS 0 include_PATH)
list(APPEND include_files ${include_PATH})
file(READ ${include_PATH} include_contents)
string(APPEND processed_file_contents "${include_contents}\n\n")
string(REPLACE "${include_line}" "${include_contents}"
input_file_contents "${input_file_contents}"
)
endif()
endforeach()
string(APPEND processed_file_contents "${input_file_contents}\n")
file(WRITE ${output_file} "${processed_file_contents}")
file(WRITE ${output_file} "${input_file_contents}")
set(include_files
${include_files}
PARENT_SCOPE
Expand Down

0 comments on commit 8fe7d64

Please sign in to comment.