title: CMake build & link to library without installing to /usr/local or elsewhere
body: <p>I'm trying to include an external library in a build environment that uses CMake.  I'm not trying to install it on the local system (in fact I'd rather <em>not</em> do that, I don't want <code>/usr/local</code> clogged up with all kinds of libraries); I'd just like to have the resulting <code>libxml2.a</code> available for linking with my executable.  I can build it fine with the following in CMakeLists.txt:</p>
  
  <pre><code>set (LIBXML_PATH ${MY_SOURCE_DIR}/libxml2-2.9.1)
  add_custom_target (build_libxml ALL
      COMMENT "Building libxml"
      COMMAND ./configure --prefix=/tmp
      COMMAND make
      WORKING_DIRECTORY ${LIBXML_PATH}
  )
  </code></pre>
  
  <p>But I'm still having trouble with the following:</p>
  
  <p>1)  Is this the right approach in the first place, for the general purpose of getting libraries built with <code>configure</code> and <code>make</code> into a CMake environment?</p>
  
  <p>2)  How do I get the resulting library (i.e. <code>libxml2.a</code>) under my <code>build</code> output directory?</p>
  
  <p>3)  How can I link to that library for my executable builds?</p>
  
  <p>I tried a fiddly solution with </p>
  
  <pre><code>ADD_LIBRARY( xml2 STATIC libxml2.a )
  </code></pre>
  
  <p>but it seems like there must be a better way than hauling a whole library's contents into… a library.</p>
  
  <p>Thanks.</p>