如果我跑步
cmake -DCMAKE_PREFIX_PATH=/home/rip/Qt/5.12.1/gcc_64/lib/cmake
一切正常。但是如果我写
set(CMAKE_PREFIX_PATH "/home/rip/Qt/5.12.1/gcc_64/lib/cmake")
在CMakeLists.txt
中并且仅运行cmake,将显示以下错误消息:
Could not find a package configuration file provided by "Qt5Quick" with any
of the following names:
Qt5QuickConfig.cmake
qt5quick-config.cmake
这是完整的代码:
set(CMAKE_CXX_FLAGS " -O3 -fopenmp")
set(CMAKE_PREFIX_PATH "/home/rip/Qt/5.12.1/gcc_64/lib/cmake")
project(${PROJECT_NAME} LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SOURCES main.cpp Test5.cpp )
set(HAEDERS Test5.h )
set(RESOURCES qml.qrc )
find_package(Qt5 COMPONENTS Core Quick REQUIRED)
add_executable(${PROJECT_NAME} ${SOURCES} ${HAEDERS} ${RESOURCES})
target_compile_definitions(${PROJECT_NAME} PRIVATE $,$>:QT_QML_DEBUG>)
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Quick)
答案 0 :(得分:0)
对我来说@guillaume-racicot 的建议不起作用。 CMAKE_PREFIX_PATH 已设置,但其上的所有内容都将被忽略。
我发现您可以访问环境变量,将其拆分为一个列表并附加到该列表中,以实际附加到前缀路径而不是替换它。
# Create a list by replacing colon with semicolon
string(REPLACE ":" ";" CMAKE_PREFIX_PATH "$ENV{CMAKE_PREFIX_PATH}")
# Append to the newly created list
list(APPEND CMAKE_PREFIX_PATH "<YOUR_ADDITIONAL_SEARCH_PATH>")