Cmake and GenerateExportHeader

I am trying to use the GenerateExportHeader module from cmake.

part of my CmakeLists.txt:

add_compiler_export_flags() add_library(gui SHARED ${gui_CPP} ${gui_HPP}) generate_export_header(gui) 

it works fine for the gui project itself, but when I try to include the gui.h files in another project, #include "gui_export.h" cannot be found. This is obvious since gui_export.h was created in gui build dir, which is not included in the path of including other projects.

A simple solution is to add gui build dir to another project, but: 1. I do not consider this a kosher solution 2. I could not even find how to find out what the target assembly array is

How can I solve this problem?

+6
source share
3 answers

With a modern (i.e. 2.8.11 or newer) CMake, the preferred mechanism is:

 target_include_directories(gui PUBLIC ${CMAKE_BINARY_DIR}/exports) 

Then, when you export () your library (which you must do!) Or otherwise use it in a context where the properties of the target interface are known (for example, in the same general CMake project, which seems to be what you do), target_link_libraries (foo gui) will also find the necessary include directory.

Putting it in a well-known catalog is somewhat orthogonal. In any case, it is recommended that you use target_include_directories to tell consumers where to find the headers of your library.

+5
source

I solved this problem using EXPORT_FILE_NAME, so now I have:

 generate_export_header(gui EXPORT_FILE_NAME ${CMAKE_BINARY_DIR}/exports/gui_export.h) 

and in all projects I add $ {CMAKE_BINARY_DIR} / exports / include

+4
source

Use export () to let CMake find your assembly tree. You can take a look at openobex at gitorious to see what the config.cmake file looks like.

OTOH, you should not use this generated export header in your public header or set it.

-2
source

Source: https://habr.com/ru/post/946766/


All Articles