From 7571fab20d7e4ee75f13ce95f87807dcafbebe82 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Mon, 9 Oct 2017 13:48:55 +0200 Subject: [PATCH] Properly detect glog and Caffe using CMake. --- CMakeLists.txt | 25 ++++++++++++++---- cmake/modules/FindCaffe.cmake | 14 ++++++++++ cmake/modules/FindGlog.cmake | 48 +++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 cmake/modules/FindCaffe.cmake create mode 100644 cmake/modules/FindGlog.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 1030215..578dddc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required (VERSION 3.1.0) project(FMRI CXX) +# Allow us to define custom modules +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules") + set(CMAKE_CXX_STANDARD 17) file(GLOB fmri_SRC @@ -12,13 +15,25 @@ add_definitions(-DCPU_ONLY) # Locate libraries -find_package(OpenCV REQUIRED) -find_package(Boost REQUIRED COMPONENTS system) add_executable(fmri ${fmri_SRC}) -# Add libraries to link +# Require OpenCV +find_package(OpenCV REQUIRED) +include_directories(${OpenCV_INCLUDE_DIRS}) target_link_libraries(fmri ${OpenCV_LIBS}) + +# Require Boost +find_package(Boost REQUIRED COMPONENTS system) +include_directories(${Boost_INCLUDE_DIRS}) target_link_libraries(fmri ${Boost_LIBRARIES}) -# These do not have CMake support, so link manually -target_link_libraries(fmri caffe glog) + +# Require Caffe +find_package(Caffe REQUIRED) +include_directories(${Caffe_INCLUDE_DIR}) +target_link_libraries(fmri ${Caffe_LIBS}) + +# Require glog +find_package(Glog REQUIRED) +include_directories(${GLOG_INCLUDE_DIRS}) +target_link_libraries(fmri ${GLOG_LIBRARIES}) diff --git a/cmake/modules/FindCaffe.cmake b/cmake/modules/FindCaffe.cmake new file mode 100644 index 0000000..21fa95c --- /dev/null +++ b/cmake/modules/FindCaffe.cmake @@ -0,0 +1,14 @@ +# Caffe package for CNN Triplet training +unset(Caffe_FOUND) + +find_path(Caffe_INCLUDE_DIR NAMES caffe/caffe.hpp caffe/common.hpp caffe/net.hpp caffe/proto/caffe.pb.h caffe/util/io.hpp + HINTS + /usr/local/include) + +find_library(Caffe_LIBS NAMES caffe + HINTS + /usr/local/lib) + +if(Caffe_LIBS AND Caffe_INCLUDE_DIR) + set(Caffe_FOUND 1) +endif() diff --git a/cmake/modules/FindGlog.cmake b/cmake/modules/FindGlog.cmake new file mode 100644 index 0000000..b340dd1 --- /dev/null +++ b/cmake/modules/FindGlog.cmake @@ -0,0 +1,48 @@ + +# - Try to find Glog +# +# The following variables are optionally searched for defaults +# GLOG_ROOT_DIR: Base directory where all GLOG components are found +# +# The following are set after configuration is done: +# GLOG_FOUND +# GLOG_INCLUDE_DIRS +# GLOG_LIBRARIES + +include(FindPackageHandleStandardArgs) + +set(GLOG_ROOT_DIR "" CACHE PATH "Folder contains Google glog") + +if(WIN32) + find_path(GLOG_INCLUDE_DIR glog/logging.h + PATHS ${GLOG_ROOT_DIR}/src/windows) +else() + find_path(GLOG_INCLUDE_DIR glog/logging.h + PATHS ${GLOG_ROOT_DIR}) +endif() + +if(MSVC) + find_library(GLOG_LIBRARY_RELEASE libglog_static + PATHS ${GLOG_ROOT_DIR} + PATH_SUFFIXES Release) + + find_library(GLOG_LIBRARY_DEBUG libglog_static + PATHS ${GLOG_ROOT_DIR} + PATH_SUFFIXES Debug) + + set(GLOG_LIBRARY optimized ${GLOG_LIBRARY_RELEASE} debug ${GLOG_LIBRARY_DEBUG}) +else() + find_library(GLOG_LIBRARY glog + PATHS ${GLOG_ROOT_DIR} + PATH_SUFFIXES + lib + lib64) +endif() + +find_package_handle_standard_args(GLOG DEFAULT_MSG + GLOG_INCLUDE_DIR GLOG_LIBRARY) + +if(GLOG_FOUND) + set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR}) + set(GLOG_LIBRARIES ${GLOG_LIBRARY}) +endif()