diff options
author | Nuno Subtil <nsubtil@nvidia.com> | 2015-04-01 19:10:55 -0700 |
---|---|---|
committer | Nuno Subtil <nsubtil@nvidia.com> | 2015-04-01 19:15:42 -0700 |
commit | 10ddfd32cb5ca4132902e9453fb05242ef52ec07 (patch) | |
tree | 14638a35bafb39f90a2b8507228d9c1d3abe3cb4 /cmake/External/glog.cmake | |
parent | 2a7fe03b5d5d7e1d30a1eb0b0e894eb4f72d3701 (diff) | |
download | caffeonacl-10ddfd32cb5ca4132902e9453fb05242ef52ec07.tar.gz caffeonacl-10ddfd32cb5ca4132902e9453fb05242ef52ec07.tar.bz2 caffeonacl-10ddfd32cb5ca4132902e9453fb05242ef52ec07.zip |
Build gflags and glog through CMake if not found in the system
This adds functionality to fetch gflags and glog from GitHub and build
them during the Caffe build. This happens only if a system-wide
installed version is not found (i.e., when find_package() fails).
If built as part of the Caffe build, gflags and glog are compiled as
position-independent static libraries. This avoids doing a system-wide
install of these libraries during the Caffe install target.
Diffstat (limited to 'cmake/External/glog.cmake')
-rw-r--r-- | cmake/External/glog.cmake | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/cmake/External/glog.cmake b/cmake/External/glog.cmake new file mode 100644 index 00000000..02b39dde --- /dev/null +++ b/cmake/External/glog.cmake @@ -0,0 +1,56 @@ +# glog depends on gflags +include("cmake/External/gflags.cmake") + +if (NOT __GLOG_INCLUDED) + set(__GLOG_INCLUDED TRUE) + + # try the system-wide glog first + find_package(Glog) + if (GLOG_FOUND) + set(GLOG_EXTERNAL FALSE) + else() + # fetch and build glog from github + + # build directory + set(glog_PREFIX ${CMAKE_BINARY_DIR}/external/glog-prefix) + # install directory + set(glog_INSTALL ${CMAKE_BINARY_DIR}/external/glog-install) + + # we build glog statically, but want to link it into the caffe shared library + # this requires position-independent code + if (UNIX) + set(GLOG_EXTRA_COMPILER_FLAGS "-fPIC") + endif() + + set(GLOG_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${GLOG_EXTRA_COMPILER_FLAGS}) + set(GLOG_C_FLAGS ${CMAKE_C_FLAGS} ${GLOG_EXTRA_COMPILER_FLAGS}) + + # depend on gflags if we're also building it + if (GFLAGS_EXTERNAL) + set(GLOG_DEPENDS gflags) + endif() + + ExternalProject_Add(glog + DEPENDS ${GLOG_DEPENDS} + PREFIX ${glog_PREFIX} + GIT_REPOSITORY "https://github.com/google/glog" + GIT_TAG "v0.3.4" + UPDATE_COMMAND "" + INSTALL_DIR ${gflags_INSTALL} + CONFIGURE_COMMAND env "CFLAGS=${GLOG_C_FLAGS}" "CXXFLAGS=${GLOG_CXX_FLAGS}" ${glog_PREFIX}/src/glog/configure --prefix=${glog_INSTALL} --enable-shared=no --enable-static=yes --with-gflags=${GFLAGS_LIBRARY_DIRS}/.. + LOG_DOWNLOAD 1 + LOG_CONFIGURE 1 + LOG_INSTALL 1 + ) + + set(GLOG_FOUND TRUE) + set(GLOG_INCLUDE_DIRS ${glog_INSTALL}/include) + set(GLOG_LIBRARIES ${GFLAGS_LIBRARIES} ${glog_INSTALL}/lib/libglog.a) + set(GLOG_LIBRARY_DIRS ${glog_INSTALL}/lib) + set(GLOG_EXTERNAL TRUE) + + list(APPEND external_project_dependencies glog) + endif() + +endif() + |