Zum Beispiel nach der Verwendung des Folgenden Befehl fehlt das Qt5_DIR im Cache:
Code: Select all
cmake -DQt5_DIR=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5 -S .. -B .
Gibt es eine Möglichkeit, diese Variable abzurufen? Soll bestehen bleiben, wenn cmake in der Befehlszeile aufgerufen wird?
*Getestet mit CMake 3.24.3 und 3.31.4.
Update: Ich habe dieses Problem reproduziert ein sehr einfaches Projekt
- Erstellen Sie CMakeLists.txt und füllen Sie es mit dem folgenden Code:
cmake_minimum_required( VERSION 3.24)Code: Select all
project(testprog) variable_watch("Qt5_DIR") if(POLICY CMP0020) cmake_policy(SET CMP0020 NEW) endif() if(POLICY CMP0043) cmake_policy(SET CMP0043 NEW) endif() #necessary for QT stuff set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) find_package(Qt5 COMPONENTS Widgets Core SerialPort QML Quick LinguistTools Sql REQUIRED) #set qt5 include dirs as 'system' dirs include_directories(SYSTEM ${Qt5Widgets_INCLUDE_DIRS}) include_directories(.) qt5_wrap_ui(UI_HEADERS mainwindow.ui) SET(PROG_SOURCES mainwindow.cpp main.cpp ${UI_HEADERS} ) add_executable(testprog WIN32 ${PROG_SOURCES}) qt5_use_modules(testprog Widgets Core SerialPort QuickWidgets Sql)
- Erstellen Sie die folgenden Dateien im Ordner mit CMakeLists.txt (sie können leer sein):
main.cpp
mainwindow.cpp
mainwindow.ui - Erstellen Sie einen Unterordner namens „build“ und wechseln Sie dorthin.
- Führen Sie in der Befehlszeile in „build“ den folgenden cmake-Befehl aus:
cmake "-DCMAKE_CONFIGURATION_TYPES=Debug;Release;MinSizeRel;RelWithDebInfo" -DQt5_DIR= C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5 -G "Visual Studio 17 2022" -A x64 ..
Code: Select all
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.41.34123.0
-- The CXX compiler identification is MSVC 19.41.34123.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/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/Community/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Debug Log at CMakeLists.txt:21 (find_package):
Variable "Qt5_DIR" was accessed using READ_ACCESS with value
"C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5".
CMake Debug Log at CMakeLists.txt:21 (find_package):
Variable "Qt5_DIR" was accessed using READ_ACCESS with value
"C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5".
-- Configuring done (4.0s)
-- Generating done (0.2s)
-- Build files have been written to: C:/Users/Documents/git/testcmakeqt/build
- Cache-Inhalte beobachten
cmake -L
Code: Select all
-- Cache values
CMAKE_INSTALL_PREFIX:PATH=C:/Program Files/testprog
Qt5Core_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Core
Qt5Gui_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Gui
Qt5LinguistTools_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5LinguistTools
Qt5Network_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Network
Qt5QML_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Qml
Qt5Qml_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Qml
Qt5QuickWidgets_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5QuickWidgets
Qt5Quick_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Quick
Qt5SerialPort_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5SerialPort
Qt5Sql_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Sql
Qt5Widgets_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Widgets
- Konfigurieren Sie das Projekt stattdessen mit der CMake-GUI und beachten Sie, dass Qt5_DIR nach der Angabe dort immer noch vorhanden ist.
cmake -L
Code: Select all
-- Cache values
CMAKE_BACKWARDS_COMPATIBILITY:STRING=2.4
CMAKE_CONFIGURATION_TYPES:STRING=Debug;Release;MinSizeRel;RelWithDebInfo
CMAKE_INSTALL_PREFIX:PATH=C:/Program Files/Project
EXECUTABLE_OUTPUT_PATH:PATH=
LIBRARY_OUTPUT_PATH:PATH=
Qt5Core_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Core
Qt5Gui_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Gui
Qt5LinguistTools_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5LinguistTools
Qt5Network_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Network
Qt5QML_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Qml
Qt5Qml_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Qml
Qt5QuickWidgets_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5QuickWidgets
Qt5Quick_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Quick
Qt5SerialPort_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5SerialPort
Qt5Sql_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Sql
Qt5Widgets_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5Widgets
Qt5_DIR:PATH=C:/Qt/Qt5.12.12/5.12.12/msvc2017_64/lib/cmake/Qt5