title: Building Google glog with CMake on Linux
body: <p>I want to build <a href="https://github.com/google/glog" rel="noreferrer">Google glog</a> with CMake as part of bigger project (solution, in words of Visual Studio). What I want to have as a result:</p>
  
  <pre><code>cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug
     -DCMAKE_INSTALL_PREFIX:PATH=xxx {MAIN CMakeLists.txt location}
  
  cmake --build . --target install --config Debug
  </code></pre>
  
  <p>will build solution in <code>Debug</code> configuration and install files to <code>xxx</code> folder.</p>
  
  <p>Ok, <code>glog</code> is sub project of main solution:</p>
  
  <pre><code>add_subdirectory(third_party/glog_0.3.4)
  </code></pre>
  
  <p>On Windows everything is ok (<a href="http://paste2.org/ZcJD02y2" rel="noreferrer">see CMakeLists.txt</a>): everything works as expected.</p>
  
  <p>To build <code>glog</code> on Linux, I need to configure <code>.h.in</code> files too (among other work). CMake <code>configure_file</code> does not works: I have <code>.h</code> files but they contain <code>#undef</code>'s only. But <code>glog</code>'s <code>./configure</code> works fine, so I found that <a href="http://www.cmake.org/cmake/help/v3.0/module/ExternalProject.html" rel="noreferrer">ExternalProject_Add()</a> may help:</p>
  
  <pre><code>if(UNIX)
  include(ExternalProject)
  
  ExternalProject_Add(glog
      SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
      CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/configure
      CMAKE_GENERATOR 'Unix Makefiles'
      BUILD_COMMAND ${MAKE})
  endif()
  </code></pre>
  
  <p>And <code>cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=xxx .</code> works fine, but <code>cmake --build . --target install --config Debug</code> will give me:</p>
  
  <pre><code>make: *** No rule to make target 'install'.  Stop.
  </code></pre>
  
  <p>If I invoke <code>cmake --build . --config Debug</code>, then it will <strong>build and install</strong> glog to <code>/usr/local/lib</code>. Next try:</p>
  
  <pre><code>if(UNIX)
  include(ExternalProject)
  
  get_filename_component(glog_absolute_install_dir ${CMAKE_INSTALL_PREFIX} ABSOLUTE)
  
  ExternalProject_Add(glog
      SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
      CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/configure --prefix=${glog_absolute_install_dir}
      CMAKE_GENERATOR 'Unix Makefiles'
      BUILD_COMMAND ${MAKE}
      INSTALL_DIR ${glog_absolute_install_dir}
      INSTALL_COMMAND "${MAKE}")
  endif()
  </code></pre>
  
  <p>will not install files to <code>xxx</code> and just build it to <code>glog-prefix/src/glog-build/</code>.</p>
  
  <p>Ok, I have no idea how to make it work.. And how to </p>
  
  <ol>
  <li>specify install dir</li>
  <li>lib build type (static/shared)</li>
  <li>configure type (Debug/Release) - not sure that now it works</li>
  </ol>
  
  <p>On Windows, according to glog's documentation, for 2nd case I do next:</p>
  
  <pre><code>add_library(${lib_name} ${lib_type} ${src_files})
  if(build_shared_lib)
      add_definitions(-DLIBGLOG_EXPORTS)
  else()
      add_definitions(-DGOOGLE_GLOG_DLL_DECL=)
  endif()
  </code></pre>
  
  <p>Thanks for any help</p>