Add include header generated in configure_file

Viewed 430

I have a cmake project with an application and a library. The library has one header file generated with configure_file. The problem is that the application code cannot find the generated header file.

What is the proper way to include the generated header file path to the application -I options? target_link_libraries adds the path, but to the source but not to the binary directory? Is it possible to add a property to the library when add_library is used so that this property can be used when target_link_libraries is used?

1 Answers

If you have generated your header file with

configure_file(config.h.in config.h @ONLY)

and have your library target already created with

add_library(libtarget ${SOURCE_FILES})

it's simply a call to

target_include_directories(libtarget PUBLIC ${CMAKE_CURRENT_BINARY_DIR})

under the assumption that all commands are given in this order and are located in the same CMakeLists.txt file.

Related