rapids_cmake_target_sources#

Added in version v27.02.00.

Add the source files defined in a JSON file to a target.

rapids_cmake_target_sources(<target> JSON <file>)

Reads the list of source files from the JSON <file> and adds each one to <target> as a PRIVATE source.

<target>

Name of an existing target.

JSON

Path to the JSON file that defines the sources. If relative, it is evaluated relative to CMAKE_CURRENT_SOURCE_DIR.

JSON file format#

The file must contain a JSON object with a top-level srcs key whose value is an array of strings, each naming a source file:

{
  "srcs": [
    "srcs/a.cpp",
    "srcs/b.cu",
    "/absolute/path/c.cpp"
  ]
}
  • Relative entries are evaluated relative to the directory containing the JSON file, not the directory of the calling CMakeLists.txt.

  • Absolute entries are used as is.

  • An empty srcs array is valid and adds no sources.

  • Keys other than srcs are ignored.

  • It is an error if the file doesn’t exist, isn’t valid JSON, doesn’t contain a srcs array.

Example on how to properly use rapids_cmake_target_sources():

add_library(example SHARED)
rapids_cmake_target_sources(example JSON srcs.json)

This function requires CMake 4.3 or newer.