Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-141181

What do with CMP0156 and CMake 4

XMLWordPrintable

    • Windows
    • b2402684c (dev), 41c410f21 (6.10), 157d99a51 (tqtc/lts-6.8)

      See attached test project. This is with

      • Windows 11
      • CMake 4.1.1
      • Latest MSVC 2022

      I'm confused what to do here. Is it fine to just ` set(QT_FORCE_CMP0156_TO_VALUE NEW)` globally on Windows? 

      cmake_minimum_required(VERSION 4.0.0)
      
      project(
        qt6_add_library_CMP0156
        VERSION 0.1
        LANGUAGES CXX)
      
      set(CMAKE_CXX_STANDARD_REQUIRED ON)
      
      
      find_package(
          Qt6 REQUIRED
          COMPONENTS Quick)
      
      qt_standard_project_setup(REQUIRES 6.8)
      
      qt6_add_library(testLib STATIC test.cpp test.h)
      
      qt_add_executable(appqt6_add_library_CMP0156 main.cpp)
      
      
      [cmake] Running C:\Program Files\CMake\bin\cmake.exe -S C:/workspace/Qt/qt6_add_library_CMP0156 -B C:/workspace/Qt/qt6_add_library_CMP0156/build/Desktop_Qt_6_10_0_MSVC2022_64bit-Debug in C:\workspace\Qt\qt6_add_library_CMP0156\build\Desktop_Qt_6_10_0_MSVC2022_64bit-Debug.
      [cmake] CMake Warning at C:/Qt/6.10.0/msvc2022_64/lib/cmake/Qt6/QtPublicCMakeVersionHelpers.cmake:184 (message):
      [cmake]   CMP0156 is set to 'NEW'.  Qt forces the 'OLD' behavior of this policy for
      [cmake]   non-Apple platforms by default.  Set QT_FORCE_CMP0156_TO_VALUE=NEW to force
      [cmake]   the 'NEW' behavior for Qt commands that create library or executable
      [cmake]   targets.
      [cmake] Call Stack (most recent call first):
      [cmake]   C:/Qt/6.10.0/msvc2022_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:2856 (__qt_internal_set_cmp0156)
      [cmake]   C:/Qt/6.10.0/msvc2022_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:2770 (_qt_internal_add_library)
      [cmake]   CMakeLists.txt:22 (qt6_add_library)
      [cmake] 
      [cmake] 
      [cmake] CMake Warning at C:/Qt/6.10.0/msvc2022_64/lib/cmake/Qt6/QtPublicCMakeVersionHelpers.cmake:184 (message):
      [cmake]   CMP0156 is set to 'NEW'.  Qt forces the 'OLD' behavior of this policy for
      [cmake]   non-Apple platforms by default.  Set QT_FORCE_CMP0156_TO_VALUE=NEW to force
      [cmake]   the 'NEW' behavior for Qt commands that create library or executable
      [cmake]   targets.
      [cmake] Call Stack (most recent call first):
      [cmake]   C:/Qt/6.10.0/msvc2022_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:746 (__qt_internal_set_cmp0156)
      [cmake]   C:/Qt/6.10.0/msvc2022_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:671 (_qt_internal_create_executable)
      [cmake]   C:/Qt/6.10.0/msvc2022_64/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:1000 (qt6_add_executable)
      [cmake]   CMakeLists.txt:24 (qt_add_executable)
      [cmake] 
      [cmake] 
      [cmake] -- Configuring done (0.6s)
      [cmake] -- Generating done (0.2s)
      [cmake] -- Build files have been written to: C:/workspace/Qt/qt6_add_library_CMP0156/build/Desktop_Qt_6_10_0_MSVC2022_64bit-Debug
      [cmake] 
      [cmake] Elapsed time: 00:01.
      
      

      Another test project testing CMP0156

      
      cmake_minimum_required(VERSION 3.31.0)
      
      cmake_policy(GET CMP0156 policy_value)
      
      if(policy_value STREQUAL "")
      message(STATUS "CMP0156 policy is UNSET (will default to NEW for CMake 3.31+)")
      else()
      message(STATUS "CMP0156 policy is set to: ${policy_value}")
      endif()
      
      cmake_minimum_required(VERSION 3.29.0)
      cmake_policy(GET CMP0156 policy_value_329)
      message(STATUS "With cmake_minimum_required 3.29: CMP0156 = '${policy_value_329}'")
      
      cmake_minimum_required(VERSION 3.28.0)
      cmake_policy(GET CMP0156 policy_value_328)
      message(STATUS "With cmake_minimum_required 3.28: CMP0156 = '${policy_value_328}'")
      
      

      Prints:

      
      cmake --version
      cmake version 4.1.1
      
      cmake -P test_cmp0156.cmake
      – CMP0156 policy is set to: NEW
      – With cmake_minimum_required 3.29: CMP0156 = 'NEW'
      – With cmake_minimum_required 3.28: CMP0156 = ''
      

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qtbuildsystem Qt Build System Team
            kelteseth Elias Steurer
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes