title: How can I optionally link against static or dynamic boost library using CMake?
body: <p>I have a CMake project that I sometimes want to compile against the static boost libraries, but I want to also make it easy to just use the dynamic libraries from the cmake GUI.  In my top level CMakeLists.txt I have this:</p>
  
  <pre><code>option(USE_STATIC_BOOST "Build with static BOOST libraries instead of dynamic" NO)
  </code></pre>
  
  <p>Then in a different file, I have the following logic set up:</p>
  
  <pre><code>if(USE_STATIC_BOOST)
     unset(Boost_LIBRARIES)
     message(WARNING "Linking against boost static libraries")
     set(Boost_USE_STATIC_LIBS ON)
     set(Boost_USE_MULTITHREADED ON)
     find_package(Boost REQUIRED COMPONENTS thread program_options system)
  else(USE_STATIC_BOOST)
     unset(Boost_LIBRARIES)
     message(WARNING "Linking against boost dynamic libraries")
     set(Boost_USE_STATIC_LIBS OFF)
     set(Boost_USE_MULTITHREADED ON)
     find_package(Boost REQUIRED COMPONENTS thread program_options system)
  endif(USE_STATIC_BOOST)
  </code></pre>
  
  <p>This seems to work fine if I start from scratch and use:</p>
  
  <pre><code>cmake ../.. -DUSE_STATIC_BOOST=YES
  </code></pre>
  
  <p>However, when I use</p>
  
  <pre><code>ccmake ../..
  </code></pre>
  
  <p>I cannot get it to use the static libraries no matter what I do.  CMake appears to load the dynamic option into cache on startup and changing USE_STATIC_BOOST doesn't switch it.  I even tried to unset(Boost_LIBRARIES) to explicitly clear it out.  Is there a way to do what I'm trying to do?</p>
  
  <p>Using x86_64 Linux and g++ to compile.  Thanks in advance!</p>