In my project I have a "schema" file and utility that I wrote to generate a header file. I'm using cmake and out of source build to build the application.
Currently I have to regenerate the header file by hand then build the application.
Then I came up with this CMakeLists.txt statements, but they generate the header in the build directory instead of in the source directory.
configure_file( generator.pl generator COPYONLY )
configure_file( schema.txt.in schema.txt COPYONLY )
add_custom_command(
OUTPUT generated.h
COMMAND ./generator schema.txt generated.h
DEPENDS mib_schema.txt.in generator.pl
COMMENT "Regenerating header file..."
)
Is it possible to generate the header in the source directory?
edit (to reflect the answer):
The file can be reached directly by fully qualifying its path with either
${CMAKE_CURRENT_SOURCE_DIR}
or:
${CMAKE_CURRENT_BINARY_DIR}
So, to generate the header in my source dir, the previous excerpt from CMakeLists.txt becomes:
add_custom_command(
OUTPUT generated.h
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/generator.pl ${CMAKE_CURRENT_SOURCE_DIR}/schema.txt.in ${CMAKE_CURRENT_SOURCE_DIR}/generated.h
DEPENDS mib_schema.txt.in generator.pl
COMMENT "Regenerating header file..."
)
which is actually simpler. Thanks
--to