title: cmake try_compile: Using library found in configure
body: <p>I am building a project with cmake. The project uses the external library plplot; I have configured cmake to the library and headers, and that is cached in variables <code>${PLPLOT_LIBRARY}, ${PLPLOT_LIB_PATH} and ${PLPLOT_INCLUDE_PATH}</code>. In the plplot library a function has changed name: <code>plwid -&gt; plwidth</code> and I want to detect that. I have written a small <code>try_compile()</code> test:</p>
  
  <pre><code>try_compile(HAVE_PLWID ${CMAKE_BINARY_DIR} cmake/tests/test_plwid.c)
  </code></pre>
  
  <p>However this test will always fail, because I have to pass header and library information to the <code>try_compile</code> process. Invoking <code>gcc</code> manually like this:</p>
  
  <pre><code>gcc -I${PLPLOT_INCLUDE_PATH} cmake/tests/test_plwid.c -L${PLPLOT_LIB_PATH} -l${PLPLOT_LIBRARY}
  </code></pre>
  
  <p>works. However I don understand how to pass the necessary flags to the <code>try_compile</code>command: I have tried:</p>
  
  <pre><code> try_compile(HAVE_PLWID ${CMAKE_BINARY_DIR} cmake/tests/test_plwid.c
               INCLUDE_DIRECTORIES ${PLPLOT_INCLUDE_PATH}
               LINK_DIRECTORIES ${PLPLOT_LIB_PATH}
               LINK_LIBRARIES ${PLPLOT_LIBRARY})
  </code></pre>
  
  <p>Then I just get the cmake configure error: </p>
  
  <pre><code>Attempt at a recursive or nested TRY_COMPILE in directory
  
      /path/to/build
  </code></pre>
  
  <p>I am quite confident the <code>${PLPLOT_XXX}</code> variables are correct, at least the rest of the build works fine based on these variables.</p>
  
  <p><strong>Update:</strong> If I invoke <code>cmake</code>with the <code>--debug_trycompile</code> command and go to the <code>build/CMakeFiles/CMakeTmp</code> directory and invoke <code>cmake</code>there manually as:</p>
  
  <pre><code>cmake . -DINCLUDE_DIRECTORIES=/path/plplot/include -DLINK_DIRECTORIES=/path/to/plplot/lib -DLINK_LIBRARIES=plplotd
  </code></pre>
  
  <p>The test program will build and link correctly; so it seems the challenge is to pass these options correctly to the <code>try_compile()</code> <code>cmake</code> command invocation? </p>