In the below minimal example, if I know the name of the generated source file in advance (test1.txt
), I could do the below
cmake_minimum_required(VERSION 3.20)
project(example)
add_executable(example main.cpp ${CMAKE_BINARY_DIR}/test1.txt)
set_source_files_properties(${CMAKE_BINARY_DIR}/test1.txt PROPERTIES GENERATED TRUE)
However, how can I achieve the same thing if I don't know the name of the generated files in advance? For my application, it will also work if the generated files are added to another target instead of the original one. Please see below of my failed attempt
cmake_minimum_required(VERSION 3.20)
project(example)
add_executable(example main.cpp)
add_custom_target(
example-generate
COMMAND $<TARGET_FILE:example>
COMMAND "using bash commands to glob the generated files but need to find a way to output the result to a cmake variable"
DEPENDS example)
add_library(example2 OBJECT) # the target with the generated unknown sources, but I can't find a way to add sources to it in build time
add_dependencies(example2 example-generate)