Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMakeList set CMAKE_PREFIX_PATH

Tags:

c++

cmake

qt

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)
like image 626
Orion Avatar asked Mar 12 '19 11:03

Orion


People also ask

What is Cmake_prefix_path?

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).

How do I change my path in CMake?

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> .


2 Answers

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/...

like image 63
Guillaume Racicot Avatar answered Sep 20 '22 15:09

Guillaume Racicot


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>")
like image 39
CodeMonkey Avatar answered Sep 19 '22 15:09

CodeMonkey