@@ -25,6 +25,80 @@ target_link_libraries(${PROJECT_NAME} PRIVATE CUDA::cudart_static)
2525target_link_libraries (${PROJECT_NAME} PRIVATE CUDA::cuda_driver)
2626target_link_libraries (${PROJECT_NAME} PRIVATE CUDA::nvrtc)
2727
28+
29+ ##
30+ # Embed files from a directory into a target.
31+ #
32+ # Parameters:
33+ # target: The target for which the embedded files are created
34+ # directory: The directory where the files are located
35+ # files...: Multiple files can be listed
36+ #
37+ # Usage:
38+ # kernel_launcher_embed(my_target my_directory file1.bin file2.bin)
39+ ##
40+ function (kernel_launcher_embed target directory )
41+ string (MAKE_C_IDENTIFIER ${target} _embed_${directory} output_target)
42+ set (deps "" )
43+
44+ foreach (input IN LISTS ARGN)
45+ string (MAKE_C_IDENTIFIER ${input} input_identifier)
46+ set (output "${CMAKE_CURRENT_BINARY_DIR} /${input_identifier} .o" )
47+
48+ add_custom_command (
49+ OUTPUT ${output}
50+ COMMAND ${CMAKE_LINKER} --relocatable --format binary --output ${output} ${input}
51+ WORKING_DIRECTORY ${directory}
52+ DEPENDS ${input}
53+ )
54+
55+ set (deps ${deps} "${output} " )
56+ endforeach ()
57+
58+ add_custom_target (${output_target} ALL DEPENDS ${deps} )
59+
60+ add_dependencies (${target} ${output_target} )
61+ target_link_libraries (${target} ${output} )
62+ endfunction ()
63+
64+ ##
65+ # Embed files from a directory into a target with the ability to specify the embedded files using a glob pattern.
66+ #
67+ # Parameters:
68+ # target: The target for which the embedded files are created
69+ # directory: The directory where the files are located
70+ # patterns...: Multiple patterns can be listed
71+ #
72+ # Usage:
73+ # kernel_launcher_embed_glob(my_target my_directory *.cuh *.h)
74+ ##
75+ function (kernel_launcher_embed_glob target directory )
76+ file (GLOB_RECURSE files LIST_DIRECTORIES false RELATIVE "${directory} " ${ARGN} )
77+ kernel_launcher_embed("${target} " "${directory} " ${files} )
78+ endfunction ()
79+
80+ ##
81+ # Embed all files from a directory into a target.
82+ #
83+ # Parameters:
84+ # target: The target for which the embedded files are created
85+ # directory: The directory where the files are located
86+ #
87+ # Usage:
88+ # kernel_launcher_embed_directory(my_target my_directory)
89+ ##
90+ function (kernel_launcher_embed_directory target directory )
91+ kernel_launcher_embed_glob(target directory "*" )
92+ endfunction ()
93+
94+ if (NOT DEFINED KERNEL_LAUNCHER_EMBEDDED_DATA)
95+ set (KERNEL_LAUNCHER_EMBEDDED_DATA 1)
96+ endif ()
97+
98+ if (KERNEL_LAUNCHER_EMBEDDED_DATA)
99+ target_compile_definitions (${PROJECT_NAME} PRIVATE KERNEL_LAUNCHER_EMBEDDED_DATA=1)
100+ endif ()
101+
28102if (KERNEL_LAUNCHER_BUILD_TEST)
29103 add_subdirectory (tests)
30104endif ()
@@ -39,3 +113,4 @@ if (KERNEL_LAUNCHER_ZLIB)
39113 target_link_libraries (${PROJECT_NAME} PRIVATE ${ZLIB_LIBRARIES} )
40114 target_compile_definitions (${PROJECT_NAME} PRIVATE KERNEL_LAUNCHER_USE_ZLIB=1)
41115endif ()
116+
0 commit comments