Building Google glog with CMake on Linux

I want to build Google glog with CMake as part of a larger project (solution, in Visual Studio's words). As a result, I want:

cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug
   -DCMAKE_INSTALL_PREFIX:PATH=xxx {MAIN CMakeLists.txt location}

cmake --build . --target install --config Debug

      

will build solution in config Debug

and install files to folder xxx

.

Ok, glog

is a sub-draft of the main solution:

add_subdirectory(third_party/glog_0.3.4)

      

On Windows everything is fine ( see CMakeLists.txt ): everything works as expected.

To build glog

on Linux I also need to set up files .h.in

(among other works). CMake configure_file

doesn't work: I have files .h

, but they only contain #undef

. But glog

./configure

works fine, so I found ExternalProject_Add () can help:

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()

      

And cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=xxx .

works fine, but cmake --build . --target install --config Debug

will give me:

make: *** No rule to make target 'install'.  Stop.

      

If I call cmake --build . --config Debug

it will build and set glog to /usr/local/lib

. Next try:

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()

      

will not install files on xxx

and just build it on glog-prefix/src/glog-build/

.

Ok, I have no idea how to make it work. And How

  • specify dir install
  • Lib build type (static / shared)
  • configure type (Debug / Release) - not sure if it works now

On Windows, according to glog documentation, for the second option, I do the following:

add_library(${lib_name} ${lib_type} ${src_files})
if(build_shared_lib)
    add_definitions(-DLIBGLOG_EXPORTS)
else()
    add_definitions(-DGOOGLE_GLOG_DLL_DECL=)
endif()

      

Thanks for any help

+3


source to share


1 answer


Currently (presumably it will be in glog release 0.3.5), a is CMakeLists.txt

enabled
with glog, so there is no longer any need for ExternalProject.



0


source







All Articles