Skip to content

Commit

Permalink
added switches for glog, gflags, boost dependency
Browse files Browse the repository at this point in the history
added Eigen support
  • Loading branch information
sh1r0 committed Jun 18, 2015
1 parent 3cdff52 commit f60f000
Show file tree
Hide file tree
Showing 43 changed files with 1,082 additions and 51 deletions.
20 changes: 20 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ cmake_minimum_required(VERSION 2.8.7)
# ---[ 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 @@ -23,6 +36,9 @@ set(python_version "2" CACHE STRING "Specify which python version to use")
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_BOOST "Build with Boost support" ON)
caffe_option(USE_GLOG "Build with glog support" ON)
caffe_option(USE_GFLAGS "Build with gflags support" ON)
caffe_option(USE_LMDB "Build with lmdb" ON)
caffe_option(USE_LEVELDB "Build with levelDB" ON)
caffe_option(USE_HDF5 "Build with hdf5 support" ON)
Expand All @@ -42,6 +58,10 @@ if(USE_libstdcpp)
message("-- Warning: forcing libstdc++ (controlled by USE_libstdcpp option in cmake)")
endif()

if(NOT USE_BOOST)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()

add_definitions(-DGTEST_USE_OWN_TR1_TUPLE)

# ---[ Warnings
Expand Down
55 changes: 49 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,17 @@ ifneq ($(CPU_ONLY), 1)
LIBRARIES := cudart cublas curand
endif

LIBRARIES += glog gflags protobuf boost_system m
LIBRARIES += protobuf m

ifeq ($(USE_BOOST), 1)
LIBRARIES += boost_system
endif
ifeq ($(USE_GLOG), 1)
LIBRARIES += glog
endif
ifeq ($(USE_GFLAGS), 1)
LIBRARIES += gflags
endif
ifeq ($(USE_LEVELDB), 1)
LIBRARIES += leveldb
endif
Expand Down Expand Up @@ -246,9 +255,12 @@ ifeq ($(LINUX), 1)
ifeq ($(shell echo $(GCCVERSION) \< 4.6 | bc), 1)
WARNINGS += -Wno-uninitialized
endif
# boost::thread is reasonably called boost_thread (compare OS X)
ifeq ($(USE_BOOST), 1)
# boost::thread is reasonably called boost_thread (compare OS X)
LIBRARIES += boost_thread
endif
# We will also explicitly add stdc++ to the link target.
LIBRARIES += boost_thread stdc++
LIBRARIES += stdc++
endif

# OS X:
Expand All @@ -267,8 +279,10 @@ ifeq ($(OSX), 1)
endif
# gtest needs to use its own tuple to not conflict with clang
COMMON_FLAGS += -DGTEST_USE_OWN_TR1_TUPLE=1
# boost::thread is called boost_thread-mt to mark multithreading on OS X
LIBRARIES += boost_thread-mt
ifeq ($(USE_BOOST), 1)
# boost::thread is called boost_thread-mt to mark multithreading on OS X
LIBRARIES += boost_thread-mt
endif
# we need to explicitly ask for the rpath to be obeyed
DYNAMIC_FLAGS := -install_name @rpath/libcaffe.so
ORIGIN := @loader_path
Expand Down Expand Up @@ -305,6 +319,21 @@ ifeq ($(USE_CUDNN), 1)
COMMON_FLAGS += -DUSE_CUDNN
endif

# boost configuration.
ifeq ($(USE_BOOST), 1)
COMMON_FLAGS += -DUSE_BOOST
endif

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

# gflafs configuration.
ifeq ($(USE_GFLAGS), 1)
COMMON_FLAGS += -DUSE_GFLAGS
endif

# i/o libraries configuration
ifeq ($(USE_OPENCV), 1)
COMMON_FLAGS += -DUSE_OPENCV
Expand Down Expand Up @@ -347,6 +376,11 @@ ifeq ($(BLAS), mkl)
MKL_DIR ?= /opt/intel/mkl
BLAS_INCLUDE ?= $(MKL_DIR)/include
BLAS_LIB ?= $(MKL_DIR)/lib $(MKL_DIR)/lib/intel64
else ifeq ($(BLAS), eigen)
# Eigen
COMMON_FLAGS += -DUSE_EIGEN
EIGEN_DIR ?= /opt/eigen
BLAS_INCLUDE ?= $(EIGEN_DIR)
else ifeq ($(BLAS), open)
# OpenBLAS
LIBRARIES += openblas
Expand Down Expand Up @@ -382,10 +416,19 @@ CXXFLAGS += -MMD -MP
# Complete build flags.
COMMON_FLAGS += $(foreach includedir,$(INCLUDE_DIRS),-I$(includedir))
CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)
ifneq ($(USE_BOOST), 1)
CXXFLAGS += -std=c++11
endif
NVCCFLAGS += -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS)
ifneq ($(USE_BOOST), 1)
NVCCFLAGS += -std=c++11
endif
# mex may invoke an older gcc that is too liberal with -Wuninitalized
MATLAB_CXXFLAGS := $(CXXFLAGS) -Wno-uninitialized
LINKFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS)
ifneq ($(USE_BOOST), 1)
LINKFLAGS += -std=c++11
endif

USE_PKG_CONFIG ?= 0
ifeq ($(USE_PKG_CONFIG), 1)
Expand Down Expand Up @@ -502,7 +545,7 @@ runtest: $(TEST_ALL_BIN)

pytest: py
cd python; python -m unittest discover -s caffe/test

mattest: mat
cd matlab; $(MATLAB_DIR)/bin/matlab -nodisplay -r 'caffe.run_tests(), exit()'

Expand Down
7 changes: 6 additions & 1 deletion Makefile.config.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1

USE_BOOST := 1
USE_GLOG := 1
USE_GFLAGS := 1

# comment out to disable IO dependencies
USE_LEVELDB := 1
USE_LMDB := 1
Expand Down Expand Up @@ -35,10 +39,11 @@ CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \

# BLAS choice:
# atlas for ATLAS (default)
# eigen for Eigen
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Custom (MKL/Eigen/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
Expand Down
16 changes: 16 additions & 0 deletions cmake/ConfigGen.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ function(caffe_generate_export_configs)
list(APPEND Caffe_DEFINITIONS -DCPU_ONLY)
endif()

if(USE_BOOST)
list(APPEND Caffe_DEFINITIONS -DUSE_BOOST)
endif()

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

if(USE_GFLAGS)
list(APPEND Caffe_DEFINITIONS -DUSE_GFLAGS)
endif()

if(USE_OPENCV)
list(APPEND Caffe_DEFINITIONS -DUSE_OPENCV)
endif()
Expand Down Expand Up @@ -86,6 +98,10 @@ function(caffe_generate_export_configs)
list(APPEND Caffe_DEFINITIONS -DUSE_MKL)
endif()

if(BLAS STREQUAL "Eigen" OR BLAS STREQUAL "eigen")
list(APPEND Caffe_DEFINITIONS -DUSE_EIGEN)
endif()

configure_file("cmake/Templates/CaffeConfig.cmake.in" "${PROJECT_BINARY_DIR}/CaffeConfig.cmake" @ONLY)

# Add targets to the build-tree export set
Expand Down
37 changes: 25 additions & 12 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,32 @@
set(Caffe_LINKER_LIBS "")

# ---[ Boost
find_package(Boost 1.46 REQUIRED COMPONENTS system thread)
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
list(APPEND Caffe_LINKER_LIBS ${Boost_LIBRARIES})
if(USE_BOOST)
find_package(Boost 1.46 REQUIRED COMPONENTS system thread)
include_directories(SYSTEM ${Boost_INCLUDE_DIR})
list(APPEND Caffe_LINKER_LIBS ${Boost_LIBRARIES})
add_definitions(-DUSE_BOOST)
endif()

# ---[ Threads
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)
endif()

# ---[ Google-gflags
include("cmake/External/gflags.cmake")
include_directories(SYSTEM ${GFLAGS_INCLUDE_DIRS})
list(APPEND Caffe_LINKER_LIBS ${GFLAGS_LIBRARIES})
if(USE_GFLAGS)
include("cmake/External/gflags.cmake")
include_directories(SYSTEM ${GFLAGS_INCLUDE_DIRS})
list(APPEND Caffe_LINKER_LIBS ${GFLAGS_LIBRARIES})
add_definitions(-DUSE_GFLAGS)
endif()

# ---[ Google-protobuf
include(cmake/ProtoBuf.cmake)
Expand Down Expand Up @@ -98,6 +107,10 @@ if(NOT APPLE)
include_directories(SYSTEM ${MKL_INCLUDE_DIR})
list(APPEND Caffe_LINKER_LIBS ${MKL_LIBRARIES})
add_definitions(-DUSE_MKL)
elseif(BLAS STREQUAL "Eigen" OR BLAS STREQUAL "eigen")
find_package(Eigen REQUIRED)
include_directories(SYSTEM ${EIGEN_INCLUDE_DIR})
add_definitions(-DUSE_EIGEN)
endif()
elseif(APPLE)
find_package(vecLib REQUIRED)
Expand All @@ -114,18 +127,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( REGEX MATCHALL "([0-9.]+).[0-9]+" has_more_version ${version} )
if("${has_more_version}" STREQUAL "")
break()
endif()

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})
Expand Down
32 changes: 32 additions & 0 deletions cmake/Modules/FindEigen.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
SET(EIGEN_INCLUDE_SEARCH_PATHS
/usr/include
/usr/include/eigen3
/usr/local/include
/usr/local/include/eigen3
$ENV{EIGEN_HOME}
)

FIND_PATH(EIGEN_INCLUDE_DIR NAMES Eigen/Dense PATHS ${EIGEN_INCLUDE_SEARCH_PATHS})

SET(EIGEN_FOUND ON)

# Check include files
IF(NOT EIGEN_INCLUDE_DIR)
SET(EIGEN_FOUND OFF)
MESSAGE(STATUS "Could not find EIGEN include. Turning EIGEN_FOUND off")
ENDIF()

IF (EIGEN_FOUND)
IF (NOT EIGEN_FIND_QUIETLY)
MESSAGE(STATUS "Found EIGEN include: ${EIGEN_INCLUDE_DIR}")
ENDIF (NOT EIGEN_FIND_QUIETLY)
ELSE (EIGEN_FOUND)
IF (EIGEN_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find EIGEN")
ENDIF (EIGEN_FIND_REQUIRED)
ENDIF (EIGEN_FOUND)

MARK_AS_ADVANCED(
EIGEN_INCLUDE_DIR
EIGEN
)
Loading

0 comments on commit f60f000

Please sign in to comment.