开罗图书馆和Cmake [英] Cairo library and Cmake
问题描述
我是c ++和cmake的新手。我通过端口此处安装了cairo库。现在我想将开罗纳入我的项目。我写了CmakeLists.txt命令,如此处所示。
I'm new to c++ and cmake. I installed cairo library as written here via port. Now i want to include cairo to my project. I wrote the CmakeLists.txt commands as shown 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()
但是它不起作用,我得到了这个输出-
But it's not working, I get this output -
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.
请帮助我正确包含开罗,
Help me to properly include cairo, please
推荐答案
问题是您的CMake版本不具备(顺便说一句,即使是最新的CMake开发版本也没有它…… https://gitlab.kitware.com/cmake/cmake/tree/master/Modules )
文件 FindCairo.cmake
,您需要运行命令 find_package(Cairo)
,而您尚未
一种解决方案是从网上获取 FindCairo.cmake
文件,创建一个 cmake
目录位于项目的根目录中,并在 CMakeLists.txt
中有多余的行
The problem is that your version of CMake doesn't have (by the way, not even the latest development version of CMake has it ... https://gitlab.kitware.com/cmake/cmake/tree/master/Modules)
the file FindCairo.cmake
that you need to have to run the command find_package(Cairo)
and you haven't included this file in your package.
A solution is to grab a FindCairo.cmake
file from the web, create a cmake
directory inside the root directory of your project and have in CMakeLists.txt
the extra line
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
,所以您来自 CMakeLists.txt
的代码段看起来像:
so your snippet from CMakeLists.txt
would look like:
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可能包含一个这样的文件),您将不得不编写一个文件或找到其他方法来包含该软件包。
If you will not use an already existing FindCairo.cmake
(e.g. Cairo that you installed might contain one such file) you will have to write one or find an alternative way to include the package.
这篇关于开罗图书馆和Cmake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!