我是c ++和cmake的新手。我通过端口以here编写了cairo库。现在我想将cairo包含在我的项目中。我编写了CmakeLists.txt命令,显示为here。
cmake_minimum_required(VERSION 3.6)
project(HelloOpenGL)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(HelloOpenGL ${SOURCE_FILES})
#find_package(ImageMagick COMPONENTS Magick++)
#include_directories(${ImageMagick_INCLUDE_DIRS})
#target_link_libraries(HelloOpenGL ${ImageMagick_LIBRARIES})
find_package(Cairo)
include_directories(${Cairo_INCLUDE_DIRS})
target_link_libraries(HelloOpenGL ${Cairo_LIBRARIES})
if(CAIRO_FOUND)
message("Cairo found")
else()
message("Cairo not found")
endif()
但它没有用,我得到了这个输出 -
CMake Warning at CMakeLists.txt:16 (find_package):
By not providing "FindCairo.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Cairo", but
CMake did not find one.
Could not find a package configuration file provided by "Cairo" with any of
the following names:
CairoConfig.cmake
cairo-config.cmake
Add the installation prefix of "Cairo" to CMAKE_PREFIX_PATH or set
"Cairo_DIR" to a directory containing one of the above files. If "Cairo"
provides a separate development package or SDK, be sure it has been
installed.
请帮我正确包含cairo,
答案 0 :(得分:3)
问题是你的CMake版本没有(顺便说一句,甚至连CMake的最新开发版都没有...... https://gitlab.kitware.com/cmake/cmake/tree/master/Modules)
运行命令FindCairo.cmake
所需的文件find_package(Cairo)
,但您尚未在包中包含此文件。
解决方案是从Web获取FindCairo.cmake
文件,在项目的根目录中创建一个cmake
目录,并在CMakeLists.txt
中添加额外的行
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
所以CMakeLists.txt
的代码段如下:
cmake_minimum_required(VERSION 3.6)
project(HelloOpenGL)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(HelloOpenGL ${SOURCE_FILES})
#find_package(ImageMagick COMPONENTS Magick++)
#include_directories(${ImageMagick_INCLUDE_DIRS})
#target_link_libraries(HelloOpenGL ${ImageMagick_LIBRARIES})
find_package(Cairo)
include_directories(${Cairo_INCLUDE_DIRS})
target_link_libraries(HelloOpenGL ${Cairo_LIBRARIES})
如果您不使用现有的FindCairo.cmake
(例如您安装的Cairo可能包含一个此类文件),则必须编写一个或找到另一种方法来包含该软件包。