how to get CMake to add MagickWand library linking automatically everywhere
<p>I want to use CMake in my software that uses MagickWand.</p>

<p>CMake works on my machine and generates a useful Makefile.
On another machine, I have to manually add</p>

<pre><code>set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lMagickWand-6.Q16 -lMagickCore-6.Q16")
</code></pre>

<p>otherwise the linker can't find MagickWandGenesis() and other functions.</p>

<p>I found that -l flags via <code>pkg-config --cflags --libs MagickWand</code>.</p>

<p>Shouldn't CMake already generate linker flags for me with <code>TARGET_LINK_LIBRARIES</code>?</p>

<p>Did I miss something obvious, or why is this not working everywhere?</p>

<hr>

<p>I have this code in CMakeLists.txt:</p>

<pre><code>FIND_PACKAGE(ImageMagick
  REQUIRED
  COMPONENTS MagickWand
)
</code></pre>

<p>[...]</p>

<pre><code>set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16")
</code></pre>

<p>[...]</p>

<pre><code>INCLUDE_DIRECTORIES(
  ${Boost_INCLUDE_DIR}
  ${ImageMagick_INCLUDE_DIRS}
  ${ImageMagick_MagickWand_INCLUDE_DIRS}
)
</code></pre>

<p>[...]</p>

<pre><code>TARGET_LINK_LIBRARIES(application_name
  [...]
  ${Boost_LIBRARIES}
  ${CURL_LIBRARIES}
  ${ImageMagick_LIBRARIES}
  ${ImageMagick_MagickWand_LIBRARY}
)
</code></pre>

<p>That last <code>${ImageMagick_MagickWand_LIBRARY}</code> shouldn't even be necessary.</p>

<p>Using Magick 6.8.9.9, CMake 3.0.2 on both machines (Debian Jessie).</p>