2011-10-26 68 views
6

我正在尝试向使用CMake开发的更大的C++项目添加一些东西。在我添加的部分中,我想使用Magick ++。在CMake中设置路径(C++,ImageMagick)

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

#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?

回答

14

基本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}) 
+0

的感谢!这就像一个魅力。 – boothby81