Build a QT project in VSCode on macOS.
-
Hi,
I have a very simple QT Quick application which builds successfully in these ways:
- Using QT Creator
- Using the cmake Xcode generator and build/run with Xcode.
- Using CMake from the command line with: CMAKE_PREFIX_PATH=/Users/myusername/Qt/6.8.1/macos/lib/cmake cmake ..
What I would love to do is work in VSCode on Mac. Unfortunately even after installing the QT extension pack and CMake Tools extensions, I have had no luck getting a project to configure and build. It does not seem to work out of the box.
Here is the build output in VSCode:
[main] Configuring project: MyProjectName [proc] Executing command: /Users/myusername/Qt/Tools/CMake/CMake.app/Contents/bin/cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++ -DCMAKE_TOOLCHAIN_FILE:FILEPATH=/Users/myusername/Qt/6.8.1/macos/lib/cmake/Qt6/qt.toolchain.cmake -DQT_QML_GENERATE_QMLLS_INI:STRING=ON --no-warn-unused-cli -S/Users/myusername/repos/MyOrgName/MyProjectName -B/Users/myusername/repos/MyOrgName/MyProjectName/build -G Ninja --debugger --debugger-pipe /tmp/cmake-debugger-pipe-dbba1bb2-6e98-42b1-9a74-c4b493bb98fa [cmake] Not searching for unused variables given on the command line. [cmake] Running with debugger on. [cmake] Waiting for debugger client to connect... [debugger] Connecting debugger on named pipe: "/tmp/cmake-debugger-pipe-dbba1bb2-6e98-42b1-9a74-c4b493bb98fa" [cmake] Debugger client connected. [cmake] -- Could NOT find OpenGL (missing: OPENGL_INCLUDE_DIR) [cmake] -- Could NOT find WrapOpenGL (missing: WrapOpenGL_FOUND) [cmake] CMake Warning at /Users/myusername/Qt/Tools/CMake/CMake.app/Contents/share/cmake-3.29/Modules/CMakeFindDependencyMacro.cmake:76 (find_package): [cmake] Found package configuration file: [cmake] [cmake] /Users/myusername/Qt/6.8.1/macos/lib/cmake/Qt6Gui/Qt6GuiConfig.cmake [cmake] [cmake] but it set Qt6Gui_FOUND to FALSE so package "Qt6Gui" is considered to be [cmake] NOT FOUND. Reason given by package: [cmake] [cmake] Qt6Gui could not be found because dependency WrapOpenGL could not be found. [cmake] [cmake] Configuring with --debug-find-pkg=WrapOpenGL might reveal details why the [cmake] package was not found. [cmake] [cmake] Configuring with -DQT_DEBUG_FIND_PACKAGE=ON will print the values of some [cmake] of the path variables that find_package uses to try and find the package. [cmake] [cmake] Call Stack (most recent call first): [cmake] /Users/myusername/Qt/6.8.1/macos/lib/cmake/Qt6/QtPublicDependencyHelpers.cmake:143 (find_dependency) [cmake] /Users/myusername/Qt/6.8.1/macos/lib/cmake/Qt6Quick/Qt6QuickDependencies.cmake:43 (_qt_internal_find_qt_dependencies) [cmake] /Users/myusername/Qt/6.8.1/macos/lib/cmake/Qt6Quick/Qt6QuickConfig.cmake:43 (include) [cmake] /Users/myusername/Qt/6.8.1/macos/lib/cmake/Qt6/Qt6Config.cmake:181 (find_package) [cmake] CMakeLists.txt:7 (find_package) [cmake] [cmake] [cmake] CMake Warning at /Users/myusername/Qt/6.8.1/macos/lib/cmake/Qt6/Qt6Config.cmake:181 (find_package): [cmake] Found package configuration file: [cmake] [cmake] /Users/myusername/Qt/6.8.1/macos/lib/cmake/Qt6Quick/Qt6QuickConfig.cmake [cmake] [cmake] but it set Qt6Quick_FOUND to FALSE so package "Qt6Quick" is considered to [cmake] be NOT FOUND. Reason given by package: [cmake] [cmake] Qt6Quick could not be found because dependency Qt6Gui could not be found. [cmake] [cmake] Configuring with --debug-find-pkg=Qt6Gui might reveal details why the [cmake] package was not found. [cmake] [cmake] Configuring with -DQT_DEBUG_FIND_PACKAGE=ON will print the values of some [cmake] of the path variables that find_package uses to try and find the package. [cmake] [cmake] Call Stack (most recent call first): [cmake] CMakeLists.txt:7 (find_package) [cmake] [cmake] [cmake] CMake Error at CMakeLists.txt:7 (find_package): [cmake] Found package configuration file: [cmake] [cmake] /Users/myusername/Qt/6.8.1/macos/lib/cmake/Qt6/Qt6Config.cmake [cmake] [cmake] but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT [cmake] FOUND. Reason given by package: [cmake] [cmake] Failed to find required Qt component "Quick". [cmake] [cmake] Expected Config file at [cmake] "/Users/myusername/Qt/6.8.1/macos/lib/cmake/Qt6Quick/Qt6QuickConfig.cmake" [cmake] exists [cmake] [cmake] [cmake] [cmake] Configuring with --debug-find-pkg=Qt6Quick might reveal details why the [cmake] package was not found. [cmake] [cmake] Configuring with -DQT_DEBUG_FIND_PACKAGE=ON will print the values of some [cmake] of the path variables that find_package uses to try and find the package. [cmake] [cmake] [cmake] [cmake] -- Configuring incomplete, errors occurred! [proc] The command: /Users/myusername/Qt/Tools/CMake/CMake.app/Contents/bin/cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/clang -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/clang++ -DCMAKE_TOOLCHAIN_FILE:FILEPATH=/Users/myusername/Qt/6.8.1/macos/lib/cmake/Qt6/qt.toolchain.cmake -DQT_QML_GENERATE_QMLLS_INI:STRING=ON --no-warn-unused-cli -S/Users/myusername/repos/MyOrgName/MyProjectName -B/Users/myusername/repos/MyOrgName/MyProjectName/build -G Ninja --debugger --debugger-pipe /tmp/cmake-debugger-pipe-dbba1bb2-6e98-42b1-9a74-c4b493bb98fa exited with code: 1 [proc] The command: clang -v failed with error: Error: spawn clang ENOENT [proc] The command: clang++ -v failed with error: Error: spawn clang++ ENOENT [proc] The command: pgrep -P 90202 exited with code: 1
If I manually specify a value for OPENGL_INCLUDE_DIR in the Cmake: Build Environment settings area it causes the "Could NOT find OpenGL" error to go away, but the "Could NOT find WrapOpenGL" error and all subsequent errors remain.
It's strange because obviously my QT installation and toolchain are working, as evidenced by all the other ways I can build my project. Something seems either broken or not configured properly out of the box in the VSCode extensions.
I am running macOS 15.2 on an M2 Pro processor.
Any suggestions on how to make this work are greatly appreciated!
Thanks,
Josh