how to link to release build of Qt in cmake with debug build

Viewed 1396

I noticed this inconsistency between qmake and CMake: qmake always links to release build of Qt, while CMake will link to debug build of Qt if build type is debug.

Small project to demonstrate:

one.cpp

#include <QApplication>

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    return app.exec();
}

one.pro

TEMPLATE += app
CONFIG += debug
QT += core gui widgets
SOURCES += one.cpp
TARGET = one

CMakeLists.txt

project(one)
set(CMAKE_BUILD_TYPE DEBUG)
set(CMAKE_MACOSX_RPATH 1)    
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
add_executable(one MACOSX_BUNDLE one.cpp)
target_link_libraries(one Qt5::Core Qt5::Gui Qt5::Widgets)

Comparing the two builds:

Building with qmake:

$ (mkdir build-qmake && cd build-qmake && ~/Qt/5.12.5/clang_64/bin/qmake .. && make)

$ otool -L build-qmake/one.app/Contents/MacOS/one
build-qmake/one.app/Contents/MacOS/one:
    @rpath/QtWidgets.framework/Versions/5/QtWidgets (compatibility version 5.12.0, current version 5.12.5)
    @rpath/QtGui.framework/Versions/5/QtGui (compatibility version 5.12.0, current version 5.12.5)
    @rpath/QtCore.framework/Versions/5/QtCore (compatibility version 5.12.0, current version 5.12.5)
    /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
    /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/AGL.framework/Versions/A/AGL (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.4)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.200.5)

Building with CMake:

$ (mkdir build-cmake && cd build-cmake && cmake .. && cmake --build .)

$ otool -L build-cmake/one.app/Contents/MacOS/one
build-cmake/one.app/Contents/MacOS/one:
    @rpath/QtWidgets.framework/Versions/5/QtWidgets_debug (compatibility version 5.12.0, current version 5.12.5)
    @rpath/QtGui.framework/Versions/5/QtGui_debug (compatibility version 5.12.0, current version 5.12.5)
    @rpath/QtCore.framework/Versions/5/QtCore_debug (compatibility version 5.12.0, current version 5.12.5)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 400.9.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.50.4)

(note it links to the _debug builds)

Question: how to make CMake link against Qt release despite being in debug build?

0 Answers
Related