[CMake] qt4_wrap_cpp: questions about TARGET option

David Demelier demelier.david at gmail.com
Tue Jan 14 08:12:25 EST 2014


Hello folks,

I had a question a long time ago about the qt4_wrap_cpp and the
target_include_directories commands.

To explain the problem, I wanted to use target_include_directories to
add include directories to dependent target easier. However I really
wanted to use qt4_wrap_cpp and not AUTOMOC (just to understand what
happens under the hood).

But the problem, is that qt4_wrap_cpp also needs the include
directories, and to add the include directories you must create a
target with source files, so you're stuck because you can't add the
source of qt4_wrap_cpp after.

So I heard that qt4_wrap_cpp has a TARGET option that specify a target
even if it does not currently exist. So that solve my problem:

# a/CMakeLists.txt
# A library that add a lots of include directories
add_library(A SHARED foo.cpp)
target_include_directories(foo PUBLIC a/ b/ c/ d/)

And now the executable that requires `A' but use qt4_wrap_cpp before.

# CMakeLists.txt
qt4_wrap_cpp(output myheader.h TARGET exe)
add_executable(exe ${output} main.cpp)
target_link_libraries(exe A)

Then the qt4_wrap_cpp seems to work and use the include directories
from A. Is this the correct behavior ?

If it's correct, I must say that the TARGET option is not shown in the
qt4_wrap_cpp macro defined in the help message of FindQt4 module.

Kind regards,

-- 
Demelier David


More information about the CMake mailing list