CMake: Rebuild OpenCL kernel headers when code changes

This commit is contained in:
Richard Berger 2021-04-30 17:04:12 -04:00
parent 6029445ab5
commit d8220e2773
No known key found for this signature in database
GPG Key ID: A9E83994E0BA0CAB
2 changed files with 18 additions and 5 deletions

View File

@ -0,0 +1,3 @@
# utility script to call GenerateOpenCLHeader function
include(${SOURCE_DIR}/Modules/OpenCLUtils.cmake)
WriteOpenCLHeader(${VARNAME} ${HEADER_FILE} ${SOURCE_FILES})

View File

@ -1,10 +1,8 @@
function(GenerateOpenCLHeader varname outfile files)
message("Creating ${outfile}...")
function(WriteOpenCLHeader varname outfile files)
file(WRITE ${outfile} "const char * ${varname} = \n")
math(EXPR ARG_END "${ARGC}-1")
separate_arguments(files)
foreach(IDX RANGE 2 ${ARG_END})
list(GET ARGV ${IDX} filename)
foreach(filename ${files})
file(READ ${filename} content)
string(REGEX REPLACE "\\s*//[^\n]*\n" "\n" content "${content}")
string(REGEX REPLACE "\\\\" "\\\\\\\\" content "${content}")
@ -15,4 +13,16 @@ function(GenerateOpenCLHeader varname outfile files)
endforeach()
file(APPEND ${outfile} ";\n")
endfunction(WriteOpenCLHeader)
function(GenerateOpenCLHeader varname outfile files)
list(REMOVE_AT ARGV 0 1)
add_custom_command(OUTPUT ${outfile}
COMMAND ${CMAKE_COMMAND} -D SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
-D VARNAME=${varname}
-D HEADER_FILE=${outfile}
-D SOURCE_FILES="${ARGV}"
-P ${CMAKE_CURRENT_SOURCE_DIR}/Modules/GenerateOpenCLHeader.cmake
DEPENDS ${ARGV}
COMMENT "Generating ${outfile}...")
endfunction(GenerateOpenCLHeader)