Set path in CMake (C ++, ImageMagick)

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

If I only compile my small sample program

#include <Magick++.h> int main() { Magick::Image image; return 0; } 

from

 g++ -o example example.cxx 

it fails because it does not find "Magick ++. h".

If i use

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

I get "undefined links".

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

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

it works.

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

+6
source share
1 answer

The base CMake distribution has a FindImageMagick.cmake module, so you're in luck. You should add something like this to CMakeLists.txt:

 find_package(ImageMagick COMPONENTS Magick++) 

After that, you can use the 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 only do

 include_directories(${ImageMagick_INCLUDE_DIRS}) target_link_libraries(YourApp ${ImageMagick_LIBRARIES}) 
+14
source

Source: https://habr.com/ru/post/900129/


All Articles