Skip to content

Commit a5bdc06

Browse files
committed
Separate io dependencies
1 parent 5367a1a commit a5bdc06

40 files changed

+282
-59
lines changed

.travis.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
# one using CMake, and one using make.
33
env:
44
matrix:
5-
- WITH_CUDA=false WITH_CMAKE=false
6-
- WITH_CUDA=false WITH_CMAKE=true
7-
- WITH_CUDA=true WITH_CMAKE=false
8-
- WITH_CUDA=true WITH_CMAKE=true
9-
- WITH_CUDA=false WITH_CMAKE=true PYTHON_VERSION=3
5+
- WITH_CUDA=false WITH_CMAKE=false WITH_IO=true
6+
- WITH_CUDA=false WITH_CMAKE=true WITH_IO=true PYTHON_VERSION=3
7+
- WITH_CUDA=true WITH_CMAKE=false WITH_IO=true
8+
- WITH_CUDA=true WITH_CMAKE=true WITH_IO=true
9+
- WITH_CUDA=false WITH_CMAKE=false WITH_IO=false
10+
- WITH_CUDA=false WITH_CMAKE=true WITH_IO=false PYTHON_VERSION=3
1011

1112
language: cpp
1213

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ include(cmake/ConfigGen.cmake)
1616

1717
# ---[ Options
1818
caffe_option(CPU_ONLY "Build Caffe without CUDA support" OFF) # TODO: rename to USE_CUDA
19-
caffe_option(USE_CUDNN "Build Caffe with cuDNN libary support" ON IF NOT CPU_ONLY)
19+
caffe_option(USE_CUDNN "Build Caffe with cuDNN library support" ON IF NOT CPU_ONLY)
2020
caffe_option(BUILD_SHARED_LIBS "Build shared libraries" ON)
2121
caffe_option(BUILD_python "Build Python wrapper" ON)
2222
set(python_version "2" CACHE STRING "Specify which python version to use")
2323
caffe_option(BUILD_matlab "Build Matlab wrapper" OFF IF UNIX OR APPLE)
2424
caffe_option(BUILD_docs "Build documentation" ON IF UNIX OR APPLE)
25-
caffe_option(BUILD_python_layer "Build the Caffe python layer" ON)
25+
caffe_option(BUILD_python_layer "Build the caffe python layer" ON)
26+
caffe_option(USE_LMDB "Build with lmdb" ON)
27+
caffe_option(USE_LEVELDB "Build with levelDB" ON)
28+
caffe_option(USE_OPENCV "Build with OpenCV support" ON)
29+
caffe_option(USE_SNAPPY "Build with Snappy support" ON)
2630

2731
# ---[ Dependencies
2832
include(cmake/Dependencies.cmake)

Makefile

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,21 @@ ifneq ($(CPU_ONLY), 1)
169169
LIBRARY_DIRS += $(CUDA_LIB_DIR)
170170
LIBRARIES := cudart cublas curand
171171
endif
172-
LIBRARIES += glog gflags protobuf leveldb snappy \
173-
lmdb boost_system hdf5_hl hdf5 m \
174-
opencv_core opencv_highgui opencv_imgproc
172+
173+
LIBRARIES += glog gflags protobuf boost_system m hdf5_hl hdf5
174+
175+
ifeq ($(USE_LEVELDB), 1)
176+
LIBRARIES += leveldb
177+
endif
178+
ifeq ($(USE_SNAPPY), 1)
179+
LIBRARIES += snappy
180+
endif
181+
ifeq ($(USE_LMDB), 1)
182+
LIBRARIES += lmdb
183+
endif
184+
ifeq ($(USE_OPENCV), 1)
185+
LIBRARIES += opencv_core opencv_highgui opencv_imgproc
186+
endif
175187
PYTHON_LIBRARIES := boost_python python2.7
176188
WARNINGS := -Wall -Wno-sign-compare
177189

@@ -290,6 +302,20 @@ ifeq ($(USE_CUDNN), 1)
290302
COMMON_FLAGS += -DUSE_CUDNN
291303
endif
292304

305+
# i/o libraries configuration
306+
ifeq ($(USE_OPENCV), 1)
307+
COMMON_FLAGS += -DUSE_OPENCV
308+
endif
309+
ifeq ($(USE_SNAPPY), 1)
310+
COMMON_FLAGS += -DUSE_SNAPPY
311+
endif
312+
ifeq ($(USE_LEVELDB), 1)
313+
COMMON_FLAGS += -DUSE_LEVELDB
314+
endif
315+
ifeq ($(USE_LMDB), 1)
316+
COMMON_FLAGS += -DUSE_LMDB
317+
endif
318+
293319
# CPU-only configuration
294320
ifeq ($(CPU_ONLY), 1)
295321
OBJS := $(PROTO_OBJS) $(CXX_OBJS)

Makefile.config.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
# CPU-only switch (uncomment to build without GPU support).
88
# CPU_ONLY := 1
99

10+
# comment out to disable IO dependencies
11+
USE_LEVELDB := 1
12+
USE_LMDB := 1
13+
USE_OPENCV := 1
14+
USE_SNAPPY := 1
15+
1016
# To customize your choice of compiler, uncomment and set the following.
1117
# N.B. the default for Linux is g++ and the default for OSX is clang++
1218
# CUSTOM_CXX := g++

cmake/ConfigGen.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ function(caffe_generate_export_configs)
5656
list(APPEND Caffe_DEFINITIONS -DCPU_ONLY)
5757
endif()
5858

59+
if(USE_OPENCV)
60+
list(APPEND Caffe_DEFINITIONS -DUSE_OPENCV)
61+
endif()
62+
63+
if(USE_LMDB)
64+
list(APPEND Caffe_DEFINITIONS -DUSE_LMDB)
65+
endif()
66+
67+
if(USE_LEVELDB)
68+
list(APPEND Caffe_DEFINITIONS -DUSE_LEVELDB)
69+
endif()
70+
71+
if(USE_SNAPPY)
72+
list(APPEND Caffe_DEFINITIONS -DUSE_SNAPPY)
73+
endif()
74+
5975
if(NOT HAVE_CUDNN)
6076
set(HAVE_CUDNN FALSE)
6177
else()

cmake/Dependencies.cmake

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,28 @@ include_directories(SYSTEM ${HDF5_INCLUDE_DIRS} ${HDF5_HL_INCLUDE_DIR})
2929
list(APPEND Caffe_LINKER_LIBS ${HDF5_LIBRARIES})
3030

3131
# ---[ LMDB
32-
find_package(LMDB REQUIRED)
33-
include_directories(SYSTEM ${LMDB_INCLUDE_DIR})
34-
list(APPEND Caffe_LINKER_LIBS ${LMDB_LIBRARIES})
32+
if(USE_LMDB)
33+
find_package(LMDB REQUIRED)
34+
include_directories(SYSTEM ${LMDB_INCLUDE_DIR})
35+
list(APPEND Caffe_LINKER_LIBS ${LMDB_LIBRARIES})
36+
add_definitions(-DUSE_LMDB)
37+
endif()
3538

3639
# ---[ LevelDB
37-
find_package(LevelDB REQUIRED)
38-
include_directories(SYSTEM ${LevelDB_INCLUDE})
39-
list(APPEND Caffe_LINKER_LIBS ${LevelDB_LIBRARIES})
40+
if(USE_LEVELDB)
41+
find_package(LevelDB REQUIRED)
42+
include_directories(SYSTEM ${LevelDB_INCLUDE})
43+
list(APPEND Caffe_LINKER_LIBS ${LevelDB_LIBRARIES})
44+
add_definitions(-DUSE_LEVELDB)
45+
endif()
4046

4147
# ---[ Snappy
42-
find_package(Snappy REQUIRED)
43-
include_directories(SYSTEM ${Snappy_INCLUDE_DIR})
44-
list(APPEND Caffe_LINKER_LIBS ${Snappy_LIBRARIES})
48+
if(USE_SNAPPY)
49+
find_package(Snappy REQUIRED)
50+
include_directories(SYSTEM ${Snappy_INCLUDE_DIR})
51+
list(APPEND Caffe_LINKER_LIBS ${Snappy_LIBRARIES})
52+
add_definitions(-DUSE_SNAPPY)
53+
endif()
4554

4655
# ---[ CUDA
4756
include(cmake/Cuda.cmake)
@@ -57,13 +66,16 @@ if(NOT HAVE_CUDA)
5766
endif()
5867

5968
# ---[ OpenCV
60-
find_package(OpenCV QUIET COMPONENTS core highgui imgproc imgcodecs)
61-
if(NOT OpenCV_FOUND) # if not OpenCV 3.x, then imgcodecs are not found
62-
find_package(OpenCV REQUIRED COMPONENTS core highgui imgproc)
69+
if(USE_OPENCV)
70+
find_package(OpenCV QUIET COMPONENTS core highgui imgproc imgcodecs)
71+
if(NOT OpenCV_FOUND) # if not OpenCV 3.x, then imgcodecs are not found
72+
find_package(OpenCV REQUIRED COMPONENTS core highgui imgproc)
73+
endif()
74+
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
75+
list(APPEND Caffe_LINKER_LIBS ${OpenCV_LIBS})
76+
message(STATUS "OpenCV found (${OpenCV_CONFIG_PATH})")
77+
add_definitions(-DUSE_OPENCV)
6378
endif()
64-
include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
65-
list(APPEND Caffe_LINKER_LIBS ${OpenCV_LIBS})
66-
message(STATUS "OpenCV found (${OpenCV_CONFIG_PATH})")
6779

6880
# ---[ BLAS
6981
if(NOT APPLE)

cmake/Summary.cmake

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,29 @@ function(caffe_print_configuration_summary)
114114
caffe_status(" BUILD_matlab : ${BUILD_matlab}")
115115
caffe_status(" BUILD_docs : ${BUILD_docs}")
116116
caffe_status(" CPU_ONLY : ${CPU_ONLY}")
117+
caffe_status(" USE_LMDB : ${USE_LMDB}")
118+
caffe_status(" USE_LEVELDB : ${USE_LEVELDB}")
119+
caffe_status(" USE_OPENCV : ${USE_OPENCV}")
120+
caffe_status(" USE_SNAPPY : ${USE_SNAPPY}")
117121
caffe_status("")
118122
caffe_status("Dependencies:")
119123
caffe_status(" BLAS : " APPLE THEN "Yes (vecLib)" ELSE "Yes (${BLAS})")
120124
caffe_status(" Boost : Yes (ver. ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION})")
121125
caffe_status(" glog : Yes")
122126
caffe_status(" gflags : Yes")
123127
caffe_status(" protobuf : " PROTOBUF_FOUND THEN "Yes (ver. ${PROTOBUF_VERSION})" ELSE "No" )
124-
caffe_status(" lmdb : " LMDB_FOUND THEN "Yes (ver. ${LMDB_VERSION})" ELSE "No")
125-
caffe_status(" Snappy : " SNAPPY_FOUND THEN "Yes (ver. ${Snappy_VERSION})" ELSE "No" )
126-
caffe_status(" LevelDB : " LEVELDB_FOUND THEN "Yes (ver. ${LEVELDB_VERSION})" ELSE "No")
127-
caffe_status(" OpenCV : Yes (ver. ${OpenCV_VERSION})")
128+
if(USE_LMDB)
129+
caffe_status(" lmdb : " LMDB_FOUND THEN "Yes (ver. ${LMDB_VERSION})" ELSE "No")
130+
endif()
131+
if(USE_SNAPPY)
132+
caffe_status(" Snappy : " SNAPPY_FOUND THEN "Yes (ver. ${Snappy_VERSION})" ELSE "No" )
133+
endif()
134+
if(USE_LEVELDB)
135+
caffe_status(" LevelDB : " LEVELDB_FOUND THEN "Yes (ver. ${LEVELDB_VERSION})" ELSE "No")
136+
endif()
137+
if(USE_OPENCV)
138+
caffe_status(" OpenCV : Yes (ver. ${OpenCV_VERSION})")
139+
endif()
128140
caffe_status(" CUDA : " HAVE_CUDA THEN "Yes (ver. ${CUDA_VERSION})" ELSE "No" )
129141
caffe_status("")
130142
if(HAVE_CUDA)
@@ -165,4 +177,3 @@ function(caffe_print_configuration_summary)
165177
caffe_status(" Install path : ${CMAKE_INSTALL_PREFIX}")
166178
caffe_status("")
167179
endfunction()
168-

cmake/Templates/CaffeConfig.cmake.in

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,24 @@
1717
# Caffe_HAVE_CUDNN - signals about cuDNN support
1818

1919

20-
# OpenCV dependency
20+
# OpenCV dependency (optional)
2121

22-
if(NOT OpenCV_FOUND)
23-
set(Caffe_OpenCV_CONFIG_PATH "@OpenCV_CONFIG_PATH@")
24-
if(Caffe_OpenCV_CONFIG_PATH)
25-
get_filename_component(Caffe_OpenCV_CONFIG_PATH ${Caffe_OpenCV_CONFIG_PATH} ABSOLUTE)
22+
if(@USE_OPENCV@)
23+
if(NOT OpenCV_FOUND)
24+
set(Caffe_OpenCV_CONFIG_PATH "@OpenCV_CONFIG_PATH@")
25+
if(Caffe_OpenCV_CONFIG_PATH)
26+
get_filename_component(Caffe_OpenCV_CONFIG_PATH ${Caffe_OpenCV_CONFIG_PATH} ABSOLUTE)
2627

27-
if(EXISTS ${Caffe_OpenCV_CONFIG_PATH} AND NOT TARGET opencv_core)
28-
message(STATUS "Caffe: using OpenCV config from ${Caffe_OpenCV_CONFIG_PATH}")
29-
include(${Caffe_OpenCV_CONFIG_PATH}/OpenCVModules.cmake)
30-
endif()
28+
if(EXISTS ${Caffe_OpenCV_CONFIG_PATH} AND NOT TARGET opencv_core)
29+
message(STATUS "Caffe: using OpenCV config from ${Caffe_OpenCV_CONFIG_PATH}")
30+
include(${Caffe_OpenCV_CONFIG_PATH}/OpenCVModules.cmake)
31+
endif()
3132

32-
else()
33-
find_package(OpenCV REQUIRED)
33+
else()
34+
find_package(OpenCV REQUIRED)
35+
endif()
36+
unset(Caffe_OpenCV_CONFIG_PATH)
3437
endif()
35-
unset(Caffe_OpenCV_CONFIG_PATH)
3638
endif()
3739

3840
# Compute paths

cmake/Templates/caffe_config.h.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@
3030

3131
/* Matlab */
3232
#cmakedefine HAVE_MATLAB
33+
34+
/* IO libraries */
35+
#cmakedefine USE_OPENCV
36+
#cmakedefine USE_LMDB
37+
#cmakedefine USE_LEVELDB
38+
#cmakedefine USE_SNAPPY

docs/installation.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@ When updating Caffe, it's best to `make clean` before re-compiling.
1717

1818
## Prerequisites
1919

20-
Caffe has several dependencies.
20+
Caffe has several dependencies:
2121

2222
* [CUDA](https://developer.nvidia.com/cuda-zone) is required for GPU mode.
2323
* library version 7.0 and the latest driver version are recommended, but 6.* is fine too
2424
* 5.5, and 5.0 are compatible but considered legacy
2525
* [BLAS](http://en.wikipedia.org/wiki/Basic_Linear_Algebra_Subprograms) via ATLAS, MKL, or OpenBLAS.
2626
* [Boost](http://www.boost.org/) >= 1.55
27+
* `protobuf`, `glog`, `gflags`, `hdf5`
28+
29+
Optional dependencies:
30+
2731
* [OpenCV](http://opencv.org/) >= 2.4 including 3.0
28-
* `protobuf`, `glog`, `gflags`
29-
* IO libraries `hdf5`, `leveldb`, `snappy`, `lmdb`
32+
* IO libraries: `leveldb`, `snappy`, `lmdb`
3033

3134
Pycaffe and Matcaffe interfaces have their own natural needs.
3235

0 commit comments

Comments
 (0)