开罗图书馆和 Cmake

Cairo library and Cmake

我是 c++ 和 cmake 的新手。我按照 here via port. Now i want to include cairo to my project. I wrote the CmakeLists.txt commands as shown here 安装了 cairo 库。

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

问题是你的CMake版本没有(顺便说一句,即使最新的CMake开发版也没有... https://gitlab.kitware.com/cmake/cmake/tree/master/Modules) 您需要 运行 命令 find_package(Cairo) 的文件 FindCairo.cmake 并且您没有将此文件包含在您的包中。
一个解决方案是从网络上获取一个 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 可能包含一个这样的文件),您将必须编写一个或找到另一种方法来包含该软件包。