CMake Later than 3.5 with Xcode generator loses Qt header paths when using imported targets
If I use a CMake later than 3.5.2 (well, tested on 5.9, 5.10 and 5.11) and try to link against QT 5.7.0 with the Xcode generator, the include paths are lost. Here is a minimal example CMakeLists.txt:
cmake_minimum_required(VERSION 3.5.2)
project(testqt CXX)
set(CMAKE_PREFIX_PATH
"/Developer/qt-5.7.0"
${CMAKE_PREFIX_PATH})
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
add_executable(${PROJECT_NAME} main.cpp)
target_link_libraries(${PROJECT_NAME}
PUBLIC
Qt5::Gui
Qt5::Widgets)
message(STATUS "Qt5Widgets_INCLUDE_DIRS: ${Qt5Widgets_INCLUDE_DIRS}")
In both cases, it will print this list of includes:
Qt5Widgets_INCLUDE_DIRS: /Developer/qt-5.7.0/lib/QtWidgets.framework;/Developer/qt-5.7.0/lib/QtWidgets.framework/Headers;/Developer/qt-5.7.0/lib/QtGui.framework;/Developer/qt-5.7.0/lib/QtGui.framework/Headers;/Developer/qt-5.7.0/lib/QtCore.framework;/Developer/qt-5.7.0/lib/QtCore.framework/Headers;/Developer/qt-5.7.0/.//mkspecs/macx-clang;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/OpenGL.framework/Headers
With CMake 3.5.2, the header search paths in Xcode reflect this:
But in CMake 3.11.4 the header paths are empty:
In my real code base only the Qt headers are missing with the newer CMake, other third party library paths are still present. Strangely, neither of these work-arounds works in the newer CMake:
# include the whole list
target_include_directories(${PROJECT_NAME} PUBLIC ${Qt5Widgets_INCLUDE_DIRS})
Nor:
# include each item one by one
foreach(qtinclude ${Qt5Widgets_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME} PUBLIC "${qtinclude}")
message(STATUS "Adding QT include: ${qtinclude}")
endforeach()
In fact even directly adding the path does not work:
target_include_directories(${PROJECT_NAME}
PUBLIC
"/Developer/qt-5.7.0/lib/QtWidgets.framework/Headers")
However, if I remove the target_link_libraries
(or just the Qt imported targets) then all of the above correctly add the header paths in the newer CMake versions.