Generated Xcode project uses "-F" instead of "-iframework" for Qt

Hello

We have a C++ project that uses Qt and we are in the process of switching from make/qmake to CMake as our build tool. Development is on macOS. When we use CMake to generate an Xcode project and then build the project, we get warnings for Qt code, usually QVector:

qvector.h:174:35: warning: implicit conversion loses integer precision: ‘typename iterator_traits<ComponentDI *const *>::difference_type’ (aka ‘long’) to ‘const int’ [-Wshorten-64-to-32]

This is a warning we explicitly enable, but we do not want to see warnings about the code of 3rd party libraries when we compile our project.

The problem seems to be that Qt frameworks are included using the “-F” flag instead of the “-iframework” flag. When building the project on the command line with CMake/make, “-iframework” is used.

I created a small example that shows the “-F”/"-iframework" difference. So far I haven’t been able to create a small example that also shows the above warning. However, when I copy one of the compiler calls used by Xcode for our real project and execute it on the command line, I get the warning, and when I change “-F” to “-iframework” I do not get the warning.

Suppose we have a source file main.cpp with the following contents:

#include
#include

int main(int argc, char** argv)
{
QVector v = { 1, 2, 3, 4, 5 };

qWarning() << “My vector:”;
qWarning() << v;

return 0;
}

And a CMakeLists.txt with the following contents:

cmake_minimum_required(VERSION 3.15)

project(helloworld VERSION 1.0.0 LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_PREFIX_PATH /usr/local/Trolltech/Qt-5.15.7-64)

find_package(Qt5 COMPONENTS Core REQUIRED)

add_executable(helloworld
main.cpp
)

target_link_libraries(helloworld Qt5::Core)

Building on the command line:

cmake …/src
make VERBOSE=1

will produce the following output:


/Applications/Xcode_12_4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DQT_CORE_LIB -DQT_NAMESPACE=QtFoo -DQT_NO_DEBUG -iframework /usr/local/Trolltech/Qt-5.15.7-64/lib -isystem /usr/local/Trolltech/Qt-5.15.7-64/lib/QtCoreFoo.framework/Headers … -c …/src/main.cpp

On the other hand, creating an Xcode project:

cmake -G Xcode …/src

then opening the generated project and compiling it will produce the following output:


/Applications/Xcode_12_4.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c++ … -isystem /usr/local/Trolltech/Qt-5.15.7-64/lib/QtCoreFoo.framework/Headers … -F/usr/local/Trolltech/Qt-5.15.7-64/lib … -c …/src/main.cpp

So, “-iframework” in the first case and “-F” in the second case. Note that we use our own Qt namespace and library infix (“Foo” above).

Environment:
macOS Catalina 10.15.7
CMake 3.22.0
Xcode 12.4
Qt 5.15.7 (our own build)

My question is: why is there different behaviour between a command line build and an Xcode build, and how can we make sure the generated Xcode project is configured to use “-iframework” instead of “-F” for Qt frameworks?

Thanks.
Daniel

This seems like some kind of -isystem behavior? I suspect we’ll need similar logic added for frameworks to use the flag if the target framework uses SYSTEM. Could you please file an issue?

Thank you. I am not an expert, but yes, I think -iframework is to -F as -isystem is to -I. You use the former if you do not want to see warnings.

I have filed this CMake GitLab issue.

Is there a workaround we can use in the meantime?

Thanks.

Not as far as I know, but macOS isn’t my normal stomping grounds, so someone else may have suggestions.