Solo
Solo

Reputation: 429

CMake based Qt project links always to release Qt libraries

Context: Windows 11, CMake 3.31.5, VisualStudio 2022

I have successfully build Qt from sources (git cloned) as static libraries for both Debug & Release using: configure.bat -opensource -prefix C:\Qt -static -debug-and-release ....

I installed the result in C:\Qt and I have got in C:\Qt\lib both Debug & Release versions of the Qt libraries (e.g. Qt6core.lib & Qt6cored.lib)

For completness, here are the commands:

mkdir C:\Qt && cd C:\Qt
git clone git://code.qt.io/qt/qt5.git src
pushd src && init-repository.bat && popd

mkdir bld && pusd bld
..\src\configure.bat -opensource -prefix C:\Qt -static -debug-and-release -gif -qt-libjpeg -qt-libpng -qt-tiff -qt-webp -no-sql-db2 -no-sql-odbc -qt-sqlite -nomake examples -nomake tests -skip qtwebengine
popd

cmake --build bld --parallel

cmake --install bld

Then I created a minimal test project that uses the statically built Qt

main.cpp

#include <QCoreApplication>

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

CMakeLists.txt

cmake_minimum_required(VERSION 3.31)
project(Test)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(Qt6_DIR "C:/Qt/lib/cmake/Qt6")
set(CMAKE_PREFIX_PATH "C:/Qt")
find_package(Qt6 REQUIRED COMPONENTS Core)
qt_standard_project_setup()

qt_add_executable(${PROJECT_NAME} main.cpp)

target_link_libraries(${PROJECT_NAME} PRIVATE Qt6::Core)

The relese builds fine but the debug not! If I open the project in VisualStudio I see the same release version of Qt libraries used as dependencies for both Debug and Release (e.g. for Debug the Qt6core.lib is used instead Qt6Cored.lib)

Here is the output:

C:\Prj\Test\TestCMakeQt>cmake -S . -B bld
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
-- The C compiler identification is MSVC 19.43.34808.0
-- The CXX compiler identification is MSVC 19.43.34808.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.43.34808/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE
-- Using Qt bundled ZLIB.
-- Found WrapZLIB: TRUE (found version "6.10.0")
-- Performing Test HAVE_STDATOMIC
-- Performing Test HAVE_STDATOMIC - Success
-- Found WrapAtomic: TRUE
-- Using Qt bundled PCRE2.
-- Found WrapPCRE2: TRUE (found version "6.10.0")
Qt6_FOUND 1
Qt6_CONFIG C:/Qt/lib/cmake/Qt6/Qt6Config.cmake
Qt6_CONSIDERED_CONFIGS C:/Qt/lib/cmake/Qt6/Qt6Config.cmake
Qt6_CONSIDERED_VERSIONS 6.10.0
-- Configuring done (9.8s)
-- Generating done (0.2s)
-- Build files have been written to: C:/Prj/Test/TestCMakeQt/bld


C:\Prj\Test\TestCMakeQt>cmake --build bld --config Debug   
MSBuild version 17.13.9+e0f243f1e for .NET Framework

  1>Checking Build System
  Automatic MOC and UIC for target TestCMakeQt
  Building Custom Rule C:/Prj/Test/TestCMakeQt/CMakeLists.txt
  mocs_compilation_Debug.cpp
  main.cpp
  Generating Code...
Qt6Core.lib(qcoreapplication.cpp.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj [C:\Prj\Test\TestCMakeQt\bld\TestCMakeQt.vcxproj]
Qt6Core.lib(qcoreapplication.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.obj [C:\Prj\Test\TestCMakeQt\bld\TestCMakeQt.vcxproj]
...

I expect CMake & Qt scripts to properly handle this... There is a C:\Qt\lib\cmake\Qt6\Qt6Config.cmake:

# Copyright (C) 2024 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause


####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was QtConfig.cmake.in                            ########

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)

macro(set_and_check _var _file)
  set(${_var} "${_file}")
  if(NOT EXISTS "${_file}")
    message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  endif()
endmacro()

macro(check_required_components _NAME)
  foreach(comp ${${_NAME}_FIND_COMPONENTS})
    if(NOT ${_NAME}_${comp}_FOUND)
      if(${_NAME}_FIND_REQUIRED_${comp})
        set(${_NAME}_FOUND FALSE)
      endif()
    endif()
  endforeach()
endmacro()

####################################################################################

cmake_minimum_required(VERSION 3.16...3.21)

include("${CMAKE_CURRENT_LIST_DIR}/Qt6ConfigExtras.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicCMakeVersionHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtPublicCMakeHelpers.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/QtInstallPaths.cmake")

__qt_internal_require_suitable_cmake_version_for_using_qt()

get_filename_component(_qt_cmake_dir "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
set(_qt_6_config_cmake_dir "${CMAKE_CURRENT_LIST_DIR}")

if (NOT QT_NO_CREATE_TARGETS)
    include("${CMAKE_CURRENT_LIST_DIR}/Qt6Targets.cmake")
    if(NOT QT_NO_CREATE_VERSIONLESS_TARGETS)
        if(CMAKE_VERSION VERSION_LESS 3.18 OR QT_USE_OLD_VERSION_LESS_TARGETS)
            include("${CMAKE_CURRENT_LIST_DIR}/Qt6VersionlessTargets.cmake")
        else()
            include("${CMAKE_CURRENT_LIST_DIR}/Qt6VersionlessAliasTargets.cmake")
        endif()
    endif()
else()
    # For examples using `find_package(...)` inside their CMakeLists.txt files:
    # Make CMake's AUTOGEN detect this Qt version properly
    set_directory_properties(PROPERTIES
                             QT_VERSION_MAJOR 6
                             QT_VERSION_MINOR 10
                             QT_VERSION_PATCH 0)
endif()

if(TARGET Qt6::PlatformCommonInternal)
    get_target_property(_qt_platform_internal_common_target
        Qt6::PlatformCommonInternal ALIASED_TARGET)
    if(NOT _qt_platform_internal_common_target)
        set(_qt_platform_internal_common_target Qt6::PlatformCommonInternal)
    endif()
    set_target_properties(${_qt_platform_internal_common_target}
        PROPERTIES
            _qt_internal_cmake_generator "${CMAKE_GENERATOR}"
    )
    unset(_qt_platform_internal_common_target)
endif()

get_filename_component(_qt_import_prefix "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_qt_import_prefix "${_qt_import_prefix}" REALPATH)
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}")
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}/3rdparty/extra-cmake-modules/find-modules")
list(APPEND CMAKE_MODULE_PATH "${_qt_import_prefix}/3rdparty/kwin")

if(APPLE)
    if(NOT CMAKE_SYSTEM_NAME OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
        set(__qt_internal_cmake_apple_support_files_path "${_qt_import_prefix}/macos")
    elseif(CMAKE_SYSTEM_NAME STREQUAL "iOS")
        set(__qt_internal_cmake_apple_support_files_path "${_qt_import_prefix}/ios")
    elseif(CMAKE_SYSTEM_NAME STREQUAL "visionOS")
        set(__qt_internal_cmake_apple_support_files_path "${_qt_import_prefix}/visionos")
    endif()
endif()

# Public helpers available to all Qt packages.
set(__qt_public_files_to_include
    QtFeature
    QtFeatureCommon
    QtPublicAndroidHelpers
    QtPublicAppleHelpers
    QtPublicCMakeHelpers
    QtPublicCMakeVersionHelpers
    QtPublicDependencyHelpers
    QtPublicExternalProjectHelpers
    QtPublicFinalizerHelpers
    QtPublicFindPackageHelpers
    QtPublicGitHelpers
    QtPublicPluginHelpers
    QtPublicPluginHelpers_v2
    QtPublicSbomAttributionHelpers
    QtPublicSbomCpeHelpers
    QtPublicSbomDepHelpers
    QtPublicSbomFileHelpers
    QtPublicSbomGenerationHelpers
    QtPublicSbomHelpers
    QtPublicSbomLicenseHelpers
    QtPublicSbomOpsHelpers
    QtPublicSbomPurlHelpers
    QtPublicSbomPythonHelpers
    QtPublicSbomSystemDepHelpers
    QtPublicTargetHelpers
    QtPublicTestHelpers
    QtPublicToolHelpers
    QtPublicWalkLibsHelpers
    QtPublicWindowsHelpers
)
foreach(__qt_public_file_to_include IN LISTS __qt_public_files_to_include)
    include("${__qt_public_file_to_include}")
endforeach()

if(NOT DEFINED QT_CMAKE_EXPORT_NAMESPACE)
    set(QT_CMAKE_EXPORT_NAMESPACE Qt6)
endif()

set(QT_ADDITIONAL_PACKAGES_PREFIX_PATH "" CACHE STRING
    "Additional directories where find(Qt6 ...) components are searched")
set(QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH "" CACHE STRING
    "Additional directories where find(Qt6 ...) host Qt components are searched")

__qt_internal_collect_additional_prefix_paths(_qt_additional_packages_prefix_paths
    QT_ADDITIONAL_PACKAGES_PREFIX_PATH)
__qt_internal_collect_additional_prefix_paths(_qt_additional_host_packages_prefix_paths
    QT_ADDITIONAL_HOST_PACKAGES_PREFIX_PATH)

__qt_internal_prefix_paths_to_roots(_qt_additional_host_packages_root_paths
    "${_qt_additional_host_packages_prefix_paths}")

__qt_internal_collect_additional_module_paths()

# Propagate sanitizer flags to both internal Qt builds and user projects.
# Allow opt-out in case if downstream projects handle it in a different way.
set(QT_CONFIGURED_SANITIZER_OPTIONS "")

if(QT_CONFIGURED_SANITIZER_OPTIONS
   AND NOT __qt_sanitizer_options_set
   AND NOT QT_NO_ADD_SANITIZER_OPTIONS)
    set(ECM_ENABLE_SANITIZERS "${QT_CONFIGURED_SANITIZER_OPTIONS}")
    include(
        "${CMAKE_CURRENT_LIST_DIR}/3rdparty/extra-cmake-modules/modules/ECMEnableSanitizers.cmake")
endif()
# Mark that the current directory scope has its sanitizer flags set.
set(__qt_sanitizer_options_set TRUE)

# Find required dependencies, if any.
include(CMakeFindDependencyMacro)
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/Qt6Dependencies.cmake")
    include("${CMAKE_CURRENT_LIST_DIR}/Qt6Dependencies.cmake")

    _qt_internal_suggest_dependency_debugging(Qt6
        __qt_Qt6_pkg ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE)

    if(NOT Qt6_FOUND)
        # Clear the components, no need to look for them if dependencies were not found, otherwise
        # you get a wall of recursive error messages.
        set(Qt6_FIND_COMPONENTS "")
    endif()
endif()

set(_Qt6_FIND_PARTS_QUIET)
if(Qt6_FIND_QUIETLY)
     set(_Qt6_FIND_PARTS_QUIET QUIET)
endif()

set(__qt_use_no_default_path_for_qt_packages "NO_DEFAULT_PATH")
if(QT_DISABLE_NO_DEFAULT_PATH_IN_QT_PACKAGES)
    set(__qt_use_no_default_path_for_qt_packages "")
endif()

foreach(module ${Qt6_FIND_COMPONENTS})
    if(NOT "${QT_HOST_PATH}" STREQUAL ""
       AND "${module}" MATCHES "Tools$"
       AND NOT "${module}" MATCHES "UiTools$"
       AND NOT "${module}" MATCHES "ShaderTools$"
       AND NOT "${module}" MATCHES "^Tools$"
       AND NOT QT_NO_FIND_HOST_TOOLS_PATH_MANIPULATION)
        # Make sure that a Qt*Tools package is also looked up in QT_HOST_PATH.
        # But don't match QtShaderTools and QtTools which are cross-compiled target package names.
        # Allow opt out just in case.
        get_filename_component(__qt_find_package_host_qt_path
            "${Qt6HostInfo_DIR}/.." ABSOLUTE)
        set(__qt_backup_cmake_prefix_path "${CMAKE_PREFIX_PATH}")
        set(__qt_backup_cmake_find_root_path "${CMAKE_FIND_ROOT_PATH}")
        list(PREPEND CMAKE_PREFIX_PATH "${__qt_find_package_host_qt_path}"
            ${_qt_additional_host_packages_prefix_paths})
        list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_HOST_PATH}"
            ${_qt_additional_host_packages_root_paths})
    endif()

    _qt_internal_save_find_package_context_for_debugging(Qt6${module})

    if(NOT Qt6${module}_FOUND)
        find_package(Qt6${module}
            ${Qt6_FIND_VERSION}
            ${_Qt6_FIND_PARTS_QUIET}
            PATHS
                ${QT_BUILD_CMAKE_PREFIX_PATH}
                ${_qt_cmake_dir}
                ${_qt_additional_packages_prefix_paths}
                ${__qt_find_package_host_qt_path}
                ${_qt_additional_host_packages_prefix_paths}
            ${__qt_use_no_default_path_for_qt_packages}
        )
    endif()

    if(NOT "${__qt_find_package_host_qt_path}" STREQUAL "")
        set(CMAKE_PREFIX_PATH "${__qt_backup_cmake_prefix_path}")
        set(CMAKE_FIND_ROOT_PATH "${__qt_backup_cmake_find_root_path}")
        unset(__qt_backup_cmake_prefix_path)
        unset(__qt_backup_cmake_find_root_path)
        unset(__qt_find_package_host_qt_path)
    endif()

    if (NOT Qt6${module}_FOUND)
        set(_qt_expected_component_config_path
            "${_qt_cmake_dir}/Qt6${module}/Qt6${module}Config.cmake")
        get_filename_component(
            _qt_expected_component_dir_path "${_qt_expected_component_config_path}" DIRECTORY)

        set(_qt_component_not_found_msg
            "\nExpected Config file at \"${_qt_expected_component_config_path}\"")

        if(EXISTS "${_qt_expected_component_config_path}")
            string(APPEND _qt_component_not_found_msg " exists \n")
        else()
            string(APPEND _qt_component_not_found_msg " does NOT exist\n")
        endif()

        set(_qt_candidate_component_dir_path "${Qt6${module}_DIR}")

        if(_qt_candidate_component_dir_path AND
            NOT _qt_expected_component_dir_path STREQUAL _qt_candidate_component_dir_path)
            string(APPEND _qt_component_not_found_msg
               "\nQt6${module}_DIR was computed by CMake or specified on the "
               "command line by the user: \"${_qt_candidate_component_dir_path}\" "
               "\nThe expected and computed paths are different, which might be the reason for "
               "the package not to be found.")
        endif()

        if(Qt6_FIND_REQUIRED_${module})
            set(Qt6_FOUND False)
            set(_Qt_NOTFOUND_MESSAGE
                "${_Qt_NOTFOUND_MESSAGE}Failed to find required Qt component \"${module}\". ${_qt_component_not_found_msg}")
            set(_qt_full_component_name "Qt6${module}")
            _qt_internal_suggest_dependency_debugging(${_qt_full_component_name}
                _qt_full_component_name _Qt_NOTFOUND_MESSAGE)
            unset(_qt_full_component_name)
            break()
        elseif(NOT Qt6_FIND_QUIETLY)
            message(WARNING
                "Failed to find optional Qt component \"${module}\". ${_qt_component_not_found_msg}")
        endif()

        unset(_qt_expected_component_config_path)
        unset(_qt_expected_component_dir_path)
        unset(_qt_candidate_component_dir_path)
        unset(_qt_component_not_found_msg)
    endif()
endforeach()

if(Qt6_FIND_COMPONENTS AND _Qt_NOTFOUND_MESSAGE)
    set(Qt6_NOT_FOUND_MESSAGE "${_Qt_NOTFOUND_MESSAGE}")
    unset(_Qt_NOTFOUND_MESSAGE)
endif()

if(Qt6_FOUND
    AND COMMAND _qt_internal_override_example_install_dir_to_dot
    AND NOT _qt_internal_example_dir_set_to_dot)
    _qt_internal_override_example_install_dir_to_dot()
endif()

__qt_internal_defer_promote_targets_in_dir_scope_to_global()
if(CMAKE_VERSION VERSION_LESS 3.21)
    __qt_internal_check_link_order_matters()
    __qt_internal_check_cmp0099_available()
endif()

and C:\Qt\lib\cmake\Qt6Core\Qt6CoreConfig.cmake:

# Copyright (C) 2024 The Qt Company Ltd.
# SPDX-License-Identifier: BSD-3-Clause


####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
####### Any changes to this file will be overwritten by the next CMake run ####
####### The input file was QtModuleConfig.cmake.in                            ########

get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)

macro(set_and_check _var _file)
  set(${_var} "${_file}")
  if(NOT EXISTS "${_file}")
    message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
  endif()
endmacro()

macro(check_required_components _NAME)
  foreach(comp ${${_NAME}_FIND_COMPONENTS})
    if(NOT ${_NAME}_${comp}_FOUND)
      if(${_NAME}_FIND_REQUIRED_${comp})
        set(${_NAME}_FOUND FALSE)
      endif()
    endif()
  endforeach()
endmacro()

####################################################################################

cmake_minimum_required(VERSION 3.16...3.21)

include(CMakeFindDependencyMacro)

# Extra cmake code begin
set(QT_KNOWN_POLICY_QTP0002 TRUE)
set(QT_KNOWN_POLICY_QTP0003 TRUE)

# Extra cmake code end

# Find required dependencies, if any.
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/Qt6CoreDependencies.cmake")
    include("${CMAKE_CURRENT_LIST_DIR}/Qt6CoreDependencies.cmake")
    _qt_internal_suggest_dependency_debugging(Core
        __qt_Core_pkg ${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE)
endif()

# If *ConfigDependencies.cmake exists, the variable value will be defined there.
# Don't override it in that case.
if(NOT DEFINED "Qt6Core_FOUND")
    set("Qt6Core_FOUND" TRUE)
endif()

if (NOT QT_NO_CREATE_TARGETS AND Qt6Core_FOUND)
    include("${CMAKE_CURRENT_LIST_DIR}/Qt6CoreTargets.cmake")
    include("${CMAKE_CURRENT_LIST_DIR}/Qt6CoreAdditionalTargetInfo.cmake")
    include("${CMAKE_CURRENT_LIST_DIR}/Qt6CoreExtraProperties.cmake"
        OPTIONAL)
endif()

# Find the private module counterpart.
if (Qt6Core_FOUND AND NOT FALSE)
    if(NOT Qt6CorePrivate_FOUND)
        if("${_qt_cmake_dir}" STREQUAL "")
            set(_qt_cmake_dir "${QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR}")
        endif()
        set(__qt_use_no_default_path_for_qt_packages "NO_DEFAULT_PATH")
        if(QT_DISABLE_NO_DEFAULT_PATH_IN_QT_PACKAGES)
            set(__qt_use_no_default_path_for_qt_packages "")
        endif()
        find_package(Qt6CorePrivate "6.10.0" EXACT
            QUIET
            CONFIG
            PATHS
                ${QT_BUILD_CMAKE_PREFIX_PATH}
                "${CMAKE_CURRENT_LIST_DIR}/.."
                "${_qt_cmake_dir}"
                ${_qt_additional_packages_prefix_paths}
            ${__qt_use_no_default_path_for_qt_packages}
        )
    endif()
    if(NOT Qt6CorePrivate_FOUND)
        get_property(Qt6CorePrivate_warning_shown GLOBAL PROPERTY
            Qt6CorePrivate_warning_shown
        )
        if(NOT Qt6CorePrivate_warning_shown)
            message(VERBOSE
                "The private module package 'Qt6CorePrivate' "
                "could not be found. It possibly needs to be installed separately with your "
                "package manager."
            )
            set_property(GLOBAL PROPERTY
                Qt6CorePrivate_warning_shown ON
            )
        endif()
    endif()
endif()

if (NOT QT_NO_CREATE_TARGETS AND Qt6Core_FOUND)
    # DEPRECATED
    # Provide old style variables for includes, compile definitions, etc.
    # These variables are deprecated and only provided on a best-effort basis to facilitate porting.
    # Consider using target_link_libraries(app PRIVATE Qt6Core) instead.
    set(Qt6Core_LIBRARIES "Qt6::Core")

    get_target_property(_Qt6Core_OWN_INCLUDE_DIRS
                        Qt6::Core INTERFACE_INCLUDE_DIRECTORIES)
    if(NOT _Qt6Core_OWN_INCLUDE_DIRS)
        set(_Qt6Core_OWN_INCLUDE_DIRS "")
    endif()

    if(TARGET Qt6::CorePrivate)
        get_target_property(_Qt6Core_OWN_PRIVATE_INCLUDE_DIRS
                            Qt6::CorePrivate INTERFACE_INCLUDE_DIRECTORIES)
        if(NOT _Qt6Core_OWN_PRIVATE_INCLUDE_DIRS)
            set(_Qt6Core_OWN_PRIVATE_INCLUDE_DIRS "")
        endif()
    endif()

    get_target_property(Qt6Core_DEFINITIONS
                        Qt6::Core INTERFACE_COMPILE_DEFINITIONS)
    if(NOT Qt6Core_DEFINITIONS)
        set(Qt6Core_DEFINITIONS "")
    else()
        set(updated_defs "")
        foreach(def IN LISTS  Qt6Core_DEFINITIONS)
             if(def MATCHES "^[A-Za-z_]")
                 list(APPEND updated_defs "-D${def}")
             else()
                 list(APPEND updated_defs "${def}")
             endif()
        endforeach()
        set(Qt6Core_DEFINITIONS "${updated_defs}")
        unset(updated_defs)
    endif()

    get_target_property(Qt6Core_COMPILE_DEFINITIONS
                        Qt6::Core INTERFACE_COMPILE_DEFINITIONS)
    if(NOT Qt6Core_COMPILE_DEFINITIONS)
        set(Qt6Core_COMPILE_DEFINITIONS "")
    endif()

    set(Qt6Core_INCLUDE_DIRS
        ${_Qt6Core_OWN_INCLUDE_DIRS})

    set(Qt6Core_PRIVATE_INCLUDE_DIRS
        ${_Qt6Core_OWN_PRIVATE_INCLUDE_DIRS})

    foreach(_module_dep ${_Qt6Core_MODULE_DEPENDENCIES})
        if(_module_dep MATCHES ".+Private$")
            set(_private_suffix "Private")
        else()
            set(_private_suffix "")
        endif()
        list(APPEND Qt6Core${_private_suffix}_INCLUDE_DIRS
             ${Qt6${_module_dep}_INCLUDE_DIRS})
        list(APPEND Qt6Core${_private_suffix}_PRIVATE_INCLUDE_DIRS
             ${Qt6${_module_dep}_PRIVATE_INCLUDE_DIRS})
        if(_private_suffix)
            list(APPEND Qt6Core_PRIVATE_INCLUDE_DIRS
                ${Qt6${_module_dep}_PRIVATE_INCLUDE_DIRS})
        endif()
        list(APPEND Qt6Core${_private_suffix}_DEFINITIONS
             ${Qt6${_module_dep}_DEFINITIONS})
        list(APPEND Qt6Core${_private_suffix}_COMPILE_DEFINITIONS
             ${Qt6${_module_dep}_COMPILE_DEFINITIONS})
    endforeach()
    unset(_private_suffix)

    list(REMOVE_DUPLICATES Qt6Core_INCLUDE_DIRS)
    list(REMOVE_DUPLICATES Qt6Core_PRIVATE_INCLUDE_DIRS)
    list(REMOVE_DUPLICATES Qt6Core_DEFINITIONS)
    list(REMOVE_DUPLICATES Qt6Core_COMPILE_DEFINITIONS)
endif()

if (TARGET Qt6::Core)
    qt_make_features_available(Qt6::Core)

    foreach(extra_cmake_include Qt6CoreMacros.cmake;Qt6CoreConfigExtras.cmake)
        include("${CMAKE_CURRENT_LIST_DIR}/${extra_cmake_include}")
    endforeach()

    if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/Qt6CorePlugins.cmake")
        include("${CMAKE_CURRENT_LIST_DIR}/Qt6CorePlugins.cmake")
    endif()

    list(APPEND QT_ALL_MODULES_FOUND_VIA_FIND_PACKAGE "Core")

    get_target_property(_qt_module_target_type "Qt6::Core" TYPE)
    if(NOT _qt_module_target_type STREQUAL "INTERFACE_LIBRARY")
        get_target_property(_qt_module_plugin_types
                            Qt6::Core MODULE_PLUGIN_TYPES)
        if(_qt_module_plugin_types)
            list(APPEND QT_ALL_PLUGIN_TYPES_FOUND_VIA_FIND_PACKAGE "${_qt_module_plugin_types}")
        endif()
    endif()


    # Load Module's BuildInternals should any exist
    if (Qt6BuildInternals_DIR AND
        EXISTS "${CMAKE_CURRENT_LIST_DIR}/Qt6CoreBuildInternals.cmake")
        include("${CMAKE_CURRENT_LIST_DIR}/Qt6CoreBuildInternals.cmake")
    endif()

    if(NOT QT_NO_CREATE_VERSIONLESS_TARGETS)
        if(CMAKE_VERSION VERSION_LESS 3.18 OR QT_USE_OLD_VERSION_LESS_TARGETS)
            include("${CMAKE_CURRENT_LIST_DIR}/Qt6CoreVersionlessTargets.cmake")
        else()
            include("${CMAKE_CURRENT_LIST_DIR}/Qt6CoreVersionlessAliasTargets.cmake")
        endif()
    endif()
else()

    set(Qt6Core_FOUND FALSE)
    if(NOT DEFINED Qt6Core_NOT_FOUND_MESSAGE)
        set(Qt6Core_NOT_FOUND_MESSAGE
            "Target \"Qt6::Core\" was not found.")

        if(QT_NO_CREATE_TARGETS)
            string(APPEND Qt6Core_NOT_FOUND_MESSAGE
                "Possibly due to QT_NO_CREATE_TARGETS being set to TRUE and thus "
                "${CMAKE_CURRENT_LIST_DIR}/Qt6CoreTargets.cmake was not "
                "included to define the target.")
        endif()
    endif()
endif()

I've added in CMakeLists.txt the path to it (set(Qt6_DIR "C:/Qt/lib/cmake/Qt6")) but the issue remains despite the fact that the Qt6 & Core package seems to be found correctly:

Qt6_FOUND 1
Qt6_CONFIG C:/Qt/lib/cmake/Qt6/Qt6Config.cmake
Qt6_CONSIDERED_CONFIGS C:/Qt/lib/cmake/Qt6/Qt6Config.cmake
Qt6_CONSIDERED_VERSIONS 6.10.0

Qt6Core_FOUND                      1
Qt6Core_CONFIG                     C:/Qt/lib/cmake/Qt6Core/Qt6CoreConfig.cmake
Qt6Core_CONSIDERED_CONFIGS         C:/Qt/lib/cmake/Qt6Core/Qt6CoreConfig.cmake
Qt6Core_CONSIDERED_VERSIONS        6.10.0
Qt6Core_LIBRARIES                  Qt6::Core
Qt6Core_VERSION                    6.10.0
Qt6Core_COMPILE_DEFINITIONS        QT_CORE_LIB
Qt6Core_DEFINITIONS                -DQT_CORE_LIB
Qt6Core_EXECUTABLE_COMPILE_FLAGS
Qt6Core_INCLUDE_DIRS               C:/Qt/include/QtCore;C:/Qt/include

Did I missed something? Or is it a bug in CMake & Qt?

PS: manually specifying Qt6cored.lib with target_link_libraries(...) for Debug (and equivalent for Release), will work for this small example but it will not be scalable therefore it is not an acceptable solution

Upvotes: 2

Views: 90

Answers (0)

Related Questions