forked from lijiext/lammps
Simplify GenerateBinaryHeader utility
The function implementation was incomplete for handling the case of multiple files. It would generate wrong C code in case more than one files were specified. Since we don't have this use case, it's safe to only leave the single input file implementation. Closes issue #2294
This commit is contained in:
parent
7d07d04989
commit
acb5fd2ebf
|
@ -1,3 +1,3 @@
|
|||
# utility script to call GenerateBinaryHeader function
|
||||
include(${SOURCE_DIR}/Modules/LAMMPSUtils.cmake)
|
||||
GenerateBinaryHeader(${VARNAME} ${HEADER_FILE} ${SOURCE_FILES})
|
||||
GenerateBinaryHeader(${VARNAME} ${HEADER_FILE} ${SOURCE_FILE})
|
||||
|
|
|
@ -71,19 +71,15 @@ macro(pkg_depends PKG1 PKG2)
|
|||
endmacro()
|
||||
|
||||
# CMake-only replacement for bin2c and xxd
|
||||
function(GenerateBinaryHeader varname outfile files)
|
||||
function(GenerateBinaryHeader varname outfile infile)
|
||||
message("Creating ${outfile}...")
|
||||
file(WRITE ${outfile} "// CMake generated file\n")
|
||||
math(EXPR ARG_END "${ARGC}-1")
|
||||
|
||||
foreach(IDX RANGE 2 ${ARG_END})
|
||||
list(GET ARGV ${IDX} filename)
|
||||
file(READ ${filename} content HEX)
|
||||
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," content "${content}")
|
||||
string(REGEX REPLACE ",$" "" content "${content}")
|
||||
file(APPEND ${outfile} "const unsigned char ${varname}[] = { ${content} };\n")
|
||||
file(APPEND ${outfile} "const unsigned int ${varname}_size = sizeof(${varname});\n")
|
||||
endforeach()
|
||||
file(READ ${infile} content HEX)
|
||||
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," content "${content}")
|
||||
string(REGEX REPLACE ",$" "" content "${content}")
|
||||
file(APPEND ${outfile} "const unsigned char ${varname}[] = { ${content} };\n")
|
||||
file(APPEND ${outfile} "const unsigned int ${varname}_size = sizeof(${varname});\n")
|
||||
endfunction(GenerateBinaryHeader)
|
||||
|
||||
# fetch missing potential files
|
||||
|
|
|
@ -309,7 +309,7 @@ elseif(GPU_API STREQUAL "HIP")
|
|||
endif()
|
||||
|
||||
add_custom_command(OUTPUT ${CUBIN_H_FILE}
|
||||
COMMAND ${CMAKE_COMMAND} -D SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -D VARNAME=${CU_NAME} -D HEADER_FILE=${CUBIN_H_FILE} -D SOURCE_FILES=${CUBIN_FILE} -P ${CMAKE_CURRENT_SOURCE_DIR}/Modules/GenerateBinaryHeader.cmake
|
||||
COMMAND ${CMAKE_COMMAND} -D SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -D VARNAME=${CU_NAME} -D HEADER_FILE=${CUBIN_H_FILE} -D SOURCE_FILE=${CUBIN_FILE} -P ${CMAKE_CURRENT_SOURCE_DIR}/Modules/GenerateBinaryHeader.cmake
|
||||
DEPENDS ${CUBIN_FILE}
|
||||
COMMENT "Generating ${CU_NAME}_cubin.h")
|
||||
|
||||
|
|
Loading…
Reference in New Issue