Skip to content

Commit

Permalink
added switches for dependency on glog and hdf5
Browse files Browse the repository at this point in the history
MINIGLOG is modified from [Ceres Solver](http://ceres-solver.org/)
  • Loading branch information
sh1r0 committed Jan 1, 2016
1 parent b086cc3 commit 0797029
Show file tree
Hide file tree
Showing 24 changed files with 842 additions and 17 deletions.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ endif()
# ---[ Caffe project
project(Caffe C CXX)

# Search packages for host system instead of packages for target system
# in case of cross compilation these macro should be defined by toolchain file
if(NOT COMMAND find_host_package)
macro(find_host_package)
find_package(${ARGN})
endmacro()
endif()
if(NOT COMMAND find_host_program)
macro(find_host_program)
find_program(${ARGN})
endmacro()
endif()

# ---[ Using cmake scripts and modules
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)

Expand All @@ -30,9 +43,11 @@ caffe_option(BUILD_matlab "Build Matlab wrapper" OFF IF UNIX OR APPLE)
caffe_option(BUILD_docs "Build documentation" ON IF UNIX OR APPLE)
caffe_option(BUILD_python_layer "Build the Caffe Python layer" ON)
caffe_option(USE_OPENCV "Build with OpenCV support" ON)
caffe_option(USE_GLOG "Build with glog support" ON)
caffe_option(USE_LEVELDB "Build with levelDB" ON)
caffe_option(USE_LMDB "Build with lmdb" ON)
caffe_option(ALLOW_LMDB_NOLOCK "Allow MDB_NOLOCK when reading LMDB files (only if necessary)" OFF)
caffe_option(USE_HDF5 "Build with hdf5" ON)

# ---[ Dependencies
include(cmake/Dependencies.cmake)
Expand Down
29 changes: 25 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,20 @@ LIB_BUILD_DIR := $(BUILD_DIR)/lib
STATIC_NAME := $(LIB_BUILD_DIR)/lib$(PROJECT).a
DYNAMIC_NAME := $(LIB_BUILD_DIR)/lib$(PROJECT).so

# toggle glog or miniglog
USE_GLOG ?= 1
ifeq ($(USE_GLOG), 1)
LIBRARIES += glog
else
CXX_SRCS := ./src/ceres/internal/miniglog/glog/logging.cpp
INCLUDE_DIRS := ./include/ceres/internal/miniglog/ $(INCLUDE_DIRS)
endif

##############################
# Get all source files
##############################
# CXX_SRCS are the source files excluding the test ones.
CXX_SRCS := $(shell find src/$(PROJECT) ! -name "test_*.cpp" -name "*.cpp")
CXX_SRCS += $(shell find src/$(PROJECT) ! -name "test_*.cpp" -name "*.cpp")
# CU_SRCS are the cuda source files
CU_SRCS := $(shell find src/$(PROJECT) ! -name "test_*.cu" -name "*.cu")
# TEST_SRCS are the test source files
Expand Down Expand Up @@ -170,11 +179,12 @@ ifneq ($(CPU_ONLY), 1)
LIBRARIES := cudart cublas curand
endif

LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5
LIBRARIES += gflags protobuf boost_system boost_filesystem m

# handle IO dependencies
USE_LEVELDB ?= 1
USE_LMDB ?= 1
USE_HDF5 ?= 1
USE_OPENCV ?= 1

ifeq ($(USE_LEVELDB), 1)
Expand All @@ -183,13 +193,16 @@ endif
ifeq ($(USE_LMDB), 1)
LIBRARIES += lmdb
endif
ifeq ($(USE_HDF5), 1)
LIBRARIES += hdf5_hl hdf5
endif
ifeq ($(USE_OPENCV), 1)
LIBRARIES += opencv_core opencv_highgui opencv_imgproc
LIBRARIES += opencv_core opencv_highgui opencv_imgproc

ifeq ($(OPENCV_VERSION), 3)
LIBRARIES += opencv_imgcodecs
endif

endif
PYTHON_LIBRARIES := boost_python python2.7
WARNINGS := -Wall -Wno-sign-compare
Expand Down Expand Up @@ -309,6 +322,11 @@ ifeq ($(USE_CUDNN), 1)
COMMON_FLAGS += -DUSE_CUDNN
endif

# glog configuration.
ifeq ($(USE_GLOG), 1)
COMMON_FLAGS += -DUSE_GLOG
endif

# configure IO libraries
ifeq ($(USE_OPENCV), 1)
COMMON_FLAGS += -DUSE_OPENCV
Expand All @@ -322,6 +340,9 @@ ifeq ($(ALLOW_LMDB_NOLOCK), 1)
COMMON_FLAGS += -DALLOW_LMDB_NOLOCK
endif
endif
ifeq ($(USE_HDF5), 1)
COMMON_FLAGS += -DUSE_HDF5
endif

# CPU-only configuration
ifeq ($(CPU_ONLY), 1)
Expand Down
4 changes: 4 additions & 0 deletions Makefile.config.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0
# USE_HDF5 := 0

# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
# You should not set this flag if you will be reading LMDBs with any
Expand All @@ -20,6 +21,9 @@
# Uncomment if you're using OpenCV 3
# OPENCV_VERSION := 3

# uncomment to disable glog
# USE_GLOG := 0

# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++
Expand Down
8 changes: 8 additions & 0 deletions cmake/ConfigGen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ function(caffe_generate_export_configs)
list(APPEND Caffe_DEFINITIONS -DCPU_ONLY)
endif()

if(USE_GLOG)
list(APPEND Caffe_DEFINITIONS -DUSE_GLOG)
endif()

if(USE_OPENCV)
list(APPEND Caffe_DEFINITIONS -DUSE_OPENCV)
endif()
Expand All @@ -71,6 +75,10 @@ function(caffe_generate_export_configs)
list(APPEND Caffe_DEFINITIONS -DUSE_LEVELDB)
endif()

if(USE_HDF5)
list(APPEND Caffe_DEFINITIONS -DUSE_HDF5)
endif()

if(NOT HAVE_CUDNN)
set(HAVE_CUDNN FALSE)
else()
Expand Down
28 changes: 18 additions & 10 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ find_package(Threads REQUIRED)
list(APPEND Caffe_LINKER_LIBS ${CMAKE_THREAD_LIBS_INIT})

# ---[ Google-glog
include("cmake/External/glog.cmake")
include_directories(SYSTEM ${GLOG_INCLUDE_DIRS})
list(APPEND Caffe_LINKER_LIBS ${GLOG_LIBRARIES})
if(USE_GLOG)
include("cmake/External/glog.cmake")
include_directories(SYSTEM ${GLOG_INCLUDE_DIRS})
list(APPEND Caffe_LINKER_LIBS ${GLOG_LIBRARIES})
add_definitions(-DUSE_GLOG)
else()
include_directories("include/ceres/internal/miniglog")
endif()

# ---[ Google-gflags
include("cmake/External/gflags.cmake")
Expand All @@ -24,9 +29,12 @@ list(APPEND Caffe_LINKER_LIBS ${GFLAGS_LIBRARIES})
include(cmake/ProtoBuf.cmake)

# ---[ HDF5
find_package(HDF5 COMPONENTS HL REQUIRED)
include_directories(SYSTEM ${HDF5_INCLUDE_DIRS} ${HDF5_HL_INCLUDE_DIR})
list(APPEND Caffe_LINKER_LIBS ${HDF5_LIBRARIES})
if(USE_HDF5)
find_package(HDF5 COMPONENTS HL REQUIRED)
include_directories(SYSTEM ${HDF5_INCLUDE_DIRS} ${HDF5_HL_INCLUDE_DIR})
list(APPEND Caffe_LINKER_LIBS ${HDF5_LIBRARIES})
add_definitions(-DUSE_HDF5)
endif()

# ---[ LMDB
if(USE_LMDB)
Expand Down Expand Up @@ -113,18 +121,18 @@ if(BUILD_python)
find_package(NumPy 1.7.1)
# Find the matching boost python implementation
set(version ${PYTHONLIBS_VERSION_STRING})

STRING( REPLACE "." "" boost_py_version ${version} )
find_package(Boost 1.46 COMPONENTS "python-py${boost_py_version}")
set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND})

while(NOT "${version}" STREQUAL "" AND NOT Boost_PYTHON_FOUND)
STRING( REGEX REPLACE "([0-9.]+).[0-9]+" "\\1" version ${version} )

STRING( REPLACE "." "" boost_py_version ${version} )
find_package(Boost 1.46 COMPONENTS "python-py${boost_py_version}")
set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND})

STRING( REGEX MATCHALL "([0-9.]+).[0-9]+" has_more_version ${version} )
if("${has_more_version}" STREQUAL "")
break()
Expand Down
Loading

0 comments on commit 0797029

Please sign in to comment.