在CMake中设置路径(C ++,ImageMagick)

时间:2011-10-26 12:58:31

标签: c++ imagemagick cmake

我正在尝试向使用CMake开发的更大的C ++项目添加内容。在我要添加的部分中,我想使用Magick ++。

如果我只编译我的小示例程序

#include <Magick++.h>

int main()
{
  Magick::Image image;

  return 0;
}

g++ -o example example.cxx

它失败了,因为它找不到“Magick ++。h”。

如果我正在使用

g++ -I /usr/include/ImageMagick -o example example.cxx

我收到“未定义的引用”错误。

如果我按照http://www.imagemagick.org/script/magick++.php上的说明进行操作并使用

进行编译
g++ `Magick++-config --cxxflags --cppflags` -o example example.cxx `Magick++-config --ldflags --libs`

它有效。

现在: 如何将其合并到使用CMake的大型项目中?我如何更改CMakeLists.txt?

1 个答案:

答案 0 :(得分:18)

基本的CMake发行版中有FindImageMagick.cmake模块,所以你很幸运。 您应该将这样的内容添加到CMakeLists.txt:

find_package(ImageMagick COMPONENTS Magick++)

之后,您可以使用以下变量:

ImageMagick_FOUND                    - TRUE if all components are found.
ImageMagick_INCLUDE_DIRS             - Full paths to all include dirs.
ImageMagick_LIBRARIES                - Full paths to all libraries.
ImageMagick_<component>_FOUND        - TRUE if <component> is found.
ImageMagick_<component>_INCLUDE_DIRS - Full path to <component> include dirs.
ImageMagick_<component>_LIBRARIES

所以你可以做到

include_directories(${ImageMagick_INCLUDE_DIRS})
target_link_libraries(YourApp ${ImageMagick_LIBRARIES})