Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set path in CMake (C++, ImageMagick)

I'm trying to add something to a larger C++ project which is developed using CMake. In the part I'm adding, I want to use Magick++.

If I'm only compiling my small example program

#include <Magick++.h>

int main()
{
  Magick::Image image;

  return 0;
}

with

g++ -o example example.cxx

it fails since it doesn't find "Magick++.h".

If I'm using

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

I get "undefined reference" errors.

If I follow the instructions on http://www.imagemagick.org/script/magick++.php and compile using

g++ `Magick++-config --cxxflags --cppflags` -o example example.cxx `Magick++-config --ldflags --libs`

it works.

Now: How do I incorporate this into the larger project that uses CMake? How do I have to change the CMakeLists.txt?

like image 714
boothby81 Avatar asked Oct 26 '11 12:10

boothby81


1 Answers

There is FindImageMagick.cmake module in the basic CMake distribution, so you are lucky. You should add something like this this to the CMakeLists.txt:

find_package(ImageMagick COMPONENTS Magick++)

After that, you can use following variables:

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

So you can do just

include_directories(${ImageMagick_INCLUDE_DIRS})
target_link_libraries(YourApp ${ImageMagick_LIBRARIES})
like image 140
arrowd Avatar answered Oct 05 '22 11:10

arrowd