As part of the configuration stage of my project, I create a small executable program somewhere in the CMAKE_BINARY_DIR tree. I’m then trying to use that program as part of an ‘add_custom_command’ call to generate some source files at build time.
I’m running into an issue where add_custom_command seems to be switching out my absolute path (obtained via find_program) with a relative path. Then the command fails to execute correctly as part of the custom command.
In my case, the generated program gets installed into ${CMAKE_BINARY_DIR}/generated/bin/
directory. I then add ${CMAKE_BINARY_DIR}/generated
to my CMAKE_PREFIX_PATH
Then I use the generated program as follows:
find_program(PROGNAME progname)
message(STATUS "PROGNAME is: ${PROGNAME}") # prints the correct absolute path to the generated program
add_custom_command(
OUTPUT my_output_file.generated.cpp
COMMAND ${PROGNAME} my_output_file.template.cpp -o my_output_file.generated.cpp
)
When trying to build the file generated by this rule, I get the following error on my console:
: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
Re-running the build with VERBOSE=1 to get the command lines for the build steps, I see the following:
cd (cmake binary dir)/src && ../generated/bin/progname (program arguments)
: program not found or is not executable
Please specify a program using absolute path or make sure the program is available in your PATH system variable
I have checked and the program is in the correct location specified, but I still get the error. I also verified that the program does in fact load and run correctly.
At this point I’m trying to figure out why the program path in the makefile got changed from an absolute path to a relative path. I think it has something to do with the program being under the CMAKE_BINARY_DIR?
Is this a known issue? Is there any way to force CMake to use an absolute path here?