How to generate header in source using cmake?

In my project, I have a file and a schema utility that I wrote to create a header file. I use cmake from the source assembly to create the application.

Currently, I need to restore the header file manually, and then create the application.

Then I came up with CMakeLists.txt instructions, but they generate a header in the assembly directory, not 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 a header in the source directory?

edit (to reflect the answer):

A file can be reached directly, fully defining its path using

${CMAKE_CURRENT_SOURCE_DIR}

or

${CMAKE_CURRENT_BINARY_DIR}

So, to generate the title in the source directory, the previous excerpt from CMakeLists.txt will look like this:

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 easier. Thanks

- at

+5
1

, , , .

, :

include_directories(${CMAKE_CURRENT_BINARY_DIR})
+5

All Articles