I have a multiple source files getting generated using custom command and custom target in the cmake_binary_dir. These source files are not getting build as they are generated during buildtime. I don't want to use execute_process to create the sources during configuration time as I dont want these files to get generated over and over again. Add_library( OBJECT) and Target_sources() only works if these sources are already present before the build starts.
Is there any way to achieve this?, also I tried creating custom _command using file(glob...) to capture all source file but file commands also gets executed before the build time
add_custom_command(
OUTPUT test.txt #phony txt script created to link command to target, the generated src files are dynamic and the names are not constant
COMMAND ${CMAKE_COMMAND} -E make_directory out_dir
COMMAND start.bat -i test.ini -o out_dir
)
add_custom_target(gen_src
DEPENDS test.txt
)
add_dependency(mainlib gen_src)
#There are multiple .c files that gets generated when this target is executed inside the out_dir folder
file(GLOB_RECURSE SOURCE_FILES
out_dir/*.c
)
add_library(test_objs OBJECT)
target_sources(test_objs PUBLIC
test.txt
${SOURCE_FILES}
)
add_dependencies(testobjs gensrc)
add_dependencies(mainlib testobjs)
target_link_libraries(mainlib PRIVATE testobjs)
The above code only builds the SOURCE_FILES to .c.o object files on building the project twice. This is because the file(glob) fails to list the generated src files in the first run