2011-10-26 69 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