Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make include directories added with AUTOUIC available to downstream targets?

Tags:

c++

cmake

qt

I have a problem with CMake's AUTOUIC option in my qt project.

I have a target that has *.ui qt-form files and changed it to use the AUTOUIC option to automatically generate the corresponding ui_*.h files and add their location to the target's include directory.

The problem is, that I inlcude the generated "ui_*.h" file in a header of the target, which is then included in another test-target. The test-target however does not have the directory with the generated files set to its include directories and therefore will not find the ui_*.h file.

So is there any way to get the directory of the generated files so I can add it to the INTERFACE_INCLUDE_DIRECTORIES of my first target. When I do this using hardcoded names It solves my compile errors, but I would rather do this by getting that directory from some target property or so. I failed with that because the AUTOUIC include dirs seem to be added only after processing all the CMakeLists files.

Btw., I am currently using CMake 3.8.2, but updating to 3.9 is an option if the problem has been solved there.

like image 992
Knitschi Avatar asked Mar 09 '23 18:03

Knitschi


1 Answers

From CMake version 3.9 onwards you can use the following snippet to add the autogenerated headers to a target's build interface include directories:

get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(_isMultiConfig)
  set(AUTOGEN_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}_autogen/include_$<CONFIG>)
else()
  set(AUTOGEN_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME}_autogen/include)
endif()

target_include_directories(${TARGET_NAME} INTERFACE
  $<BUILD_INTERFACE:${AUTOGEN_INCLUDE_DIR}>
)

See:

  • Use GENERATOR_IS_MULTI_CONFIG to detect multi-config generators
  • AUTOUIC
  • GENERATOR_IS_MULTI_CONFIG
  • AUTOGEN_BUILD_DIR
like image 159
globberwops Avatar answered Mar 11 '23 06:03

globberwops