I'm trying to make a single CMakeLists.txt
that calls an external command to generate a bunch of C files in a folder, then compile those C files. Currently it looks like this:
set (OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Generated)
set (OUTPUT_FILES
${OUTPUT_DIR}/*.c
${OUTPUT_DIR}/*.h
)
add_custom_command(OUTPUT ${OUTPUT_FILES}
COMMAND external_c_files_generator --output-folder ${PYTHON_WRAPPER_OUTPUT_DIR}
COMMENT "Generating C code..."
)
add_executable (my_executable ${OUTPUT_FILES})
Problem: the sample above obviously doesn't work because CMake doesn't support wildcards this way. It does work if I don't use wildcards. But I need to allow my external C files generator to generate "whatever it wants", including multiple C files which names I can't predict, and just take all the files it generates and compile them.
A very common solution that can be found regarding usage of wildcards in CMake is file(GLOB)
. Unfortunately it's not applicable in this case because file(GLOB)
is called during the build system generation, not during the build itself.
Other solutions that can't be employed:
- Generate the files outside cmake, and generate the
CMakeLists.txt
along it, then finally call CMake: can't be done in my case because my custom command actually relies on other CMake steps that generate other files.
Everything in in the details.