Upgraded to QtCreator 9.0.0 and now CMake can't find boost? (QtCreator + CMAKE + VCPKG + Boost)
-
I have a Qt Project that uses CMake and VCPKG. It used to work with vcpkg configuration through setting the CMAKE_TOOLCHAIN_FILE in the system environment.
I updated to QtCreator 9.0.0 and deleted my build output folder and the CMakeLists.txt.user file. Opened the cmake project selected the same kit and now CMake can't find boost and doesn't seem to know about VCPKG at all.
If I run CMake from a developer shell it works fine.
I found that I can make it work in QtCreator by explicitly setting "-DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake" in the "Additional CMake options in the initial configuration tab of the Project Build settings. Then I have to click "Re- configure with Initial Parameters". I'm not a fan of this because I'd have to instruct our team to do this for every project which will increase friction of using QtCreator more.
It's possible that I'm remembering wrong, but my recollection is that QtCreator would work with VCPKG by pulling CMAKE_TOOLCHAIN_FILE from the system environment. Now that doesn't seem to happen.
-----Output from non working cmake run-----
Running C:\Program Files\CMake\bin\cmake.exe -S C:/Projects/ASIO_Client -B C:/Projects/Projects/build-ASIO_Client-Desktop_Qt_6_4_1_MSVC2022_64bit-Debug "-DCMAKE_GENERATOR:STRING=Ninja" "-DCMAKE_BUILD_TYPE:STRING=Debug" "-DQT_QMAKE_EXECUTABLE:FILEPATH=C:/Qt/6.4.1/msvc2019_64/bin/qmake.exe" "-DCMAKE_PREFIX_PATH:PATH=C:/Qt/6.4.1/msvc2019_64" "-DCMAKE_C_COMPILER:FILEPATH=C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.33.31629/bin/HostX64/x64/cl.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.33.31629/bin/HostX64/x64/cl.exe" "-DCMAKE_CXX_FLAGS_INIT:STRING=" in C:\Projects\build-ASIO_Client-Desktop_Qt_6_4_1_MSVC2022_64bit-Debug.
-- The CXX compiler identification is MSVC 19.33.31629.0
-- 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.33.31629/bin/HostX64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_TOOLCHAIN_FILE = C:\vcpkg\scripts\buildsystems\vcpkg.cmake
CMake Error at C:/Program Files/CMake/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Boost (missing: Boost_INCLUDE_DIR system regex date_time)
(Required is at least version "1.54.0")
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.25/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.25/Modules/FindBoost.cmake:2376 (find_package_handle_standard_args)
CMakeLists.txt:42 (find_package)-----Output when CMAKE_TOOL_CHAIN_FILE is explicitly specified----
Running C:\Program Files\CMake\bin\cmake.exe -S C:/Projects/ASIO_Client -B C:/Projects/build-ASIO_Client-Desktop_Qt_6_4_1_MSVC2022_64bit-Debug "-DCMAKE_GENERATOR:STRING=Ninja" "-DCMAKE_BUILD_TYPE:STRING=Debug" "-DQT_QMAKE_EXECUTABLE:FILEPATH=C:/Qt/6.4.1/msvc2019_64/bin/qmake.exe" "-DCMAKE_PREFIX_PATH:PATH=C:/Qt/6.4.1/msvc2019_64" "-DCMAKE_C_COMPILER:FILEPATH=C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.33.31629/bin/HostX64/x64/cl.exe" "-DCMAKE_CXX_COMPILER:FILEPATH=C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.33.31629/bin/HostX64/x64/cl.exe" "-DCMAKE_CXX_FLAGS_INIT:STRING=" "-DCMAKE_TOOLCHAIN_FILE=C:\vcpkg\scripts\buildsystems\vcpkg.cmake" in C:\Projects\build-ASIO_Client-Desktop_Qt_6_4_1_MSVC2022_64bit-Debug.
-- The CXX compiler identification is MSVC 19.33.31629.0
-- 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.33.31629/bin/HostX64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CMAKE_TOOLCHAIN_FILE = C:\vcpkg\scripts\buildsystems\vcpkg.cmake
-- Found Boost: C:/vcpkg/installed/x64-windows/include (found suitable version "1.78.0", minimum required is "1.54.0") found components: system regex date_time
-- Boost: 1.78.0
-- 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
-- Performing Test HAVE_STDATOMIC
-- Performing Test HAVE_STDATOMIC - Success
-- Found WrapAtomic: TRUE
-- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR)
-- Configuring done
-- Generating done -
Qt Creator 9 has changed the default value of Package manager auto setup to Disabled.
Make sure to enable it like this:

I'll make sure to bring it back as Enabled in Qt Creator 10 by fixing the issue that caused it to be disabled in Qt Creator 9.
-
The feature has been documented https://www.qt.io/blog/qt-creator-cmake-package-manager-auto-setup
-
Thanks for the replies. "Package manager auto setup" wasn't checked in my QtCreator setup. Enabling that option didn't help. I'm going to have to process the link/documentation from cristian-adam. That looks like it might help however I'm confused why (or even how) pulling "CMAKE_TOOLCHAIN_FILE" is no longer working.
-
Thanks for the replies. "Package manager auto setup" wasn't checked in my QtCreator setup. Enabling that option didn't help. I'm going to have to process the link/documentation from cristian-adam. That looks like it might help however I'm confused why (or even how) pulling "CMAKE_TOOLCHAIN_FILE" is no longer working.
@MRiedel I am using the following CMake code in my project to setup vcpkg and qt for my windows projects. With it you only need a
VCPKG_ROOTenvironment var and toolchain will be configured automatically.
Although I am primarily using CLion with that setup code I am able to also switch to Qt Creator when necessary. Hope this helps:cmake_minimum_required(VERSION 3.24) if (DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "") endif () # set vcpkg target triplet to silence some warnings if (DEFINED ENV{VCPKG_DEFAULT_TRIPLET} AND NOT DEFINED VCPKG_TARGET_TRIPLET) set(VCPKG_TARGET_TRIPLET "$ENV{VCPKG_DEFAULT_TRIPLET}" CACHE STRING "") endif () IF (WIN32) set(CMAKE_PREFIX_PATH C:\\Qt\\6.4.1\\msvc2019_64\\lib\\cmake) ENDIF (WIN32)project definition follows after...
-
@MRiedel CMake should work in Qt Creator in the same way it works from the command line.
That being said, Qt Creator 9 introduced the notion of Configure Environment due to support of CMake presets.

If you were not aware of this distinction, you might have set the value in the build part, which is too late and CMake can't find vcpkg and nothing works.
The auto-setup will set the
CMAKE_TOOLCHAIN_FILEfor you, but vcpkg needs to be inPATH. -
I've decided to give it a try with https://code.qt.io/cgit/qt-creator/qt-creator.git/tree/tests/manual/vcpkg
Since CMAKE_TOOLCHAIN_FILE is taken into consideration from version 3.21 I've modified the
CMakeLists.txtas:cmake_minimum_required(VERSION 3.21) message(STATUS "CMake version: ${CMAKE_VERSION}") message(STATUS "CMAKE_TOOLCHAIN_FILE: -D ${CMAKE_TOOLCHAIN_FILE} ENV: $ENV{CMAKE_TOOLCHAIN_FILE}") project(vcpkg-libfmt) find_package(fmt CONFIG REQUIRED) add_executable(vcpkg-libfmt main.cpp) target_link_libraries(vcpkg-libfmt PRIVATE fmt::fmt) install(TARGETS vcpkg-libfmt)And to my surprise I've got:
-- CMake version: 3.22.1 -- CMAKE_TOOLCHAIN_FILE: -D ENV: c:\Projects\github\vcpkg\scripts\buildsystems\vcpkg.cmakeWhich means that CMake for some reason is not setting the value to
CMAKE_TOOLCHAIN_FILEfrom the environment variable.Adding the line:
file(TO_CMAKE_PATH "$ENV{CMAKE_TOOLCHAIN_FILE}" CMAKE_TOOLCHAIN_FILE)Results in proper project configuration:
-- CMake version: 3.22.1 -- CMAKE_TOOLCHAIN_FILE: -D c:/Projects/github/vcpkg/scripts/buildsystems/vcpkg.cmake ENV: c:\Projects\github\vcpkg\scripts\buildsystems\vcpkg.cmake -- Running vcpkg install Detecting compiler hash for triplet x64-windows... The following packages will be built and installed: fmt[core]:x64-windows -> 7.1.3