If I run
cmake -DCMAKE_PREFIX_PATH=/home/rip/Qt/5.12.1/gcc_64/lib/cmake
everything works well. But if I write
set(CMAKE_PREFIX_PATH "/home/rip/Qt/5.12.1/gcc_64/lib/cmake")
in the CMakeLists.txt
and run only cmake, the error message below is shown:
Could not find a package configuration file provided by "Qt5Quick" with any
of the following names:
Qt5QuickConfig.cmake
qt5quick-config.cmake
This is the complete code:
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)
CMAKE_PREFIX_PATH works as a build directive, rather than as an environment variable. Moreover, you may perform the build into a dedicated temporary directory (it's cleaner, because when done, you can remove that temporary directory and you get back a clean pristine source tree).
CMake will use whatever path the running CMake executable is in. Furthermore, it may get confused if you switch paths between runs without clearing the cache. So what you have to do is simply instead of running cmake <path_to_src> from the command line, run ~/usr/cmake-path/bin/cmake <path_to_src> .
The prefix path is a list of paths. Use this:
list(APPEND CMAKE_PREFIX_PATH "/home/rip/Qt/5.12.1/gcc_64")
Also you don't have to point directly into the config file path, you also can point into the directory containing the lib/cmake/...
For me @guillaume-racicot's suggstion doesn't work. The CMAKE_PREFIX_PATH is set, but everything that's on it is ignored.
I found out that you can access the environment variable, split that into a list and append to that to actually append to the prefix path instead of replacing it.
# 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>")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With