1 # These lists are later turned into target properties on main caffe library target
2 set(Caffe_LINKER_LIBS "")
3 set(Caffe_INCLUDE_DIRS "")
4 set(Caffe_DEFINITIONS "")
5 set(Caffe_COMPILE_OPTIONS "")
8 find_package(Boost 1.46 REQUIRED COMPONENTS system thread filesystem)
9 list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${Boost_INCLUDE_DIRS})
10 list(APPEND Caffe_LINKER_LIBS PUBLIC ${Boost_LIBRARIES})
13 find_package(Threads REQUIRED)
14 list(APPEND Caffe_LINKER_LIBS PRIVATE ${CMAKE_THREAD_LIBS_INIT})
18 # Ideally, this should be provided by the BLAS library IMPORTED target. However,
19 # nobody does this, so we need to link to OpenMP explicitly and have the maintainer
20 # to flick the switch manually as needed.
22 # Moreover, OpenMP package does not provide an IMPORTED target as well, and the
23 # suggested way of linking to OpenMP is to append to CMAKE_{C,CXX}_FLAGS.
24 # However, this naïve method will force any user of Caffe to add the same kludge
25 # into their buildsystem again, so we put these options into per-target PUBLIC
26 # compile options and link flags, so that they will be exported properly.
27 find_package(OpenMP REQUIRED)
28 list(APPEND Caffe_LINKER_LIBS PRIVATE ${OpenMP_CXX_FLAGS})
29 list(APPEND Caffe_COMPILE_OPTIONS PRIVATE ${OpenMP_CXX_FLAGS})
33 include("cmake/External/glog.cmake")
34 list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${GLOG_INCLUDE_DIRS})
35 list(APPEND Caffe_LINKER_LIBS PUBLIC ${GLOG_LIBRARIES})
38 include("cmake/External/gflags.cmake")
39 list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${GFLAGS_INCLUDE_DIRS})
40 list(APPEND Caffe_LINKER_LIBS PUBLIC ${GFLAGS_LIBRARIES})
42 # ---[ Google-protobuf
43 include(cmake/ProtoBuf.cmake)
46 find_package(HDF5 COMPONENTS HL REQUIRED)
47 list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${HDF5_INCLUDE_DIRS})
48 list(APPEND Caffe_LINKER_LIBS PUBLIC ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES})
52 find_package(LMDB REQUIRED)
53 list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${LMDB_INCLUDE_DIR})
54 list(APPEND Caffe_LINKER_LIBS PUBLIC ${LMDB_LIBRARIES})
55 list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_LMDB)
57 list(APPEND Caffe_DEFINITIONS PRIVATE -DALLOW_LMDB_NOLOCK)
63 find_package(LevelDB REQUIRED)
64 list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${LevelDB_INCLUDES})
65 list(APPEND Caffe_LINKER_LIBS PUBLIC ${LevelDB_LIBRARIES})
66 list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_LEVELDB)
71 find_package(ACL REQUIRED)
72 list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${ACL_INCLUDE})
73 list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${ACL_INCLUDE}/include)
74 set(__list ${ACL_LIBRARIES})
75 separate_arguments(__list)
76 list(REMOVE_DUPLICATES __list)
78 list(APPEND Caffe_LINKER_LIBS PUBLIC ${i})
80 list(APPEND Caffe_COMPILE_OPTIONS PRIVATE -std=c++11)
81 list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_ACL)
86 find_package(Snappy REQUIRED)
87 list(APPEND Caffe_INCLUDE_DIRS PRIVATE ${Snappy_INCLUDE_DIR})
88 list(APPEND Caffe_LINKER_LIBS PRIVATE ${Snappy_LIBRARIES})
92 include(cmake/Cuda.cmake)
95 message(STATUS "-- CUDA is disabled. Building without it...")
97 message(WARNING "-- CUDA is not detected by cmake. Building without it...")
100 list(APPEND Caffe_DEFINITIONS PUBLIC -DCPU_ONLY)
104 find_package(NCCL REQUIRED)
105 include_directories(SYSTEM ${NCCL_INCLUDE_DIR})
106 list(APPEND Caffe_LINKER_LIBS ${NCCL_LIBRARIES})
107 add_definitions(-DUSE_NCCL)
112 find_package(OpenCV QUIET COMPONENTS core highgui imgproc imgcodecs)
113 if(NOT OpenCV_FOUND) # if not OpenCV 3.x, then imgcodecs are not found
114 find_package(OpenCV REQUIRED COMPONENTS core highgui imgproc)
116 list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${OpenCV_INCLUDE_DIRS})
117 list(APPEND Caffe_LINKER_LIBS PUBLIC ${OpenCV_LIBS})
118 message(STATUS "OpenCV found (${OpenCV_CONFIG_PATH})")
119 list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_OPENCV)
124 set(BLAS "Atlas" CACHE STRING "Selected BLAS library")
125 set_property(CACHE BLAS PROPERTY STRINGS "Atlas;Open;MKL")
127 if(BLAS STREQUAL "Atlas" OR BLAS STREQUAL "atlas")
128 find_package(Atlas REQUIRED)
129 list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${Atlas_INCLUDE_DIR})
130 list(APPEND Caffe_LINKER_LIBS PUBLIC ${Atlas_LIBRARIES})
131 elseif(BLAS STREQUAL "Open" OR BLAS STREQUAL "open")
132 find_package(OpenBLAS REQUIRED)
133 list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${OpenBLAS_INCLUDE_DIR})
134 list(APPEND Caffe_LINKER_LIBS PUBLIC ${OpenBLAS_LIB})
135 elseif(BLAS STREQUAL "MKL" OR BLAS STREQUAL "mkl")
136 find_package(MKL REQUIRED)
137 list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${MKL_INCLUDE_DIR})
138 list(APPEND Caffe_LINKER_LIBS PUBLIC ${MKL_LIBRARIES})
139 list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_MKL)
142 find_package(vecLib REQUIRED)
143 list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${vecLib_INCLUDE_DIR})
144 list(APPEND Caffe_LINKER_LIBS PUBLIC ${vecLib_LINKER_LIBS})
147 if(NOT vecLib_INCLUDE_DIR MATCHES "^/System/Library/Frameworks/vecLib.framework.*")
148 list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_ACCELERATE)
155 if(NOT "${python_version}" VERSION_LESS "3.0.0")
157 find_package(PythonInterp 3.0)
158 find_package(PythonLibs 3.0)
159 find_package(NumPy 1.7.1)
160 # Find the matching boost python implementation
161 set(version ${PYTHONLIBS_VERSION_STRING})
163 STRING( REGEX REPLACE "[^0-9]" "" boost_py_version ${version} )
164 find_package(Boost 1.46 COMPONENTS "python-py${boost_py_version}")
165 set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND})
167 while(NOT "${version}" STREQUAL "" AND NOT Boost_PYTHON_FOUND)
168 STRING( REGEX REPLACE "([0-9.]+).[0-9]+" "\\1" version ${version} )
170 STRING( REGEX REPLACE "[^0-9]" "" boost_py_version ${version} )
171 find_package(Boost 1.46 COMPONENTS "python-py${boost_py_version}")
172 set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND})
174 STRING( REGEX MATCHALL "([0-9.]+).[0-9]+" has_more_version ${version} )
175 if("${has_more_version}" STREQUAL "")
179 if(NOT Boost_PYTHON_FOUND)
180 find_package(Boost 1.46 COMPONENTS python)
183 # disable Python 3 search
184 find_package(PythonInterp 2.7)
185 find_package(PythonLibs 2.7)
186 find_package(NumPy 1.7.1)
187 find_package(Boost 1.46 COMPONENTS python)
189 if(PYTHONLIBS_FOUND AND NUMPY_FOUND AND Boost_PYTHON_FOUND)
190 set(HAVE_PYTHON TRUE)
191 if(BUILD_python_layer)
192 list(APPEND Caffe_DEFINITIONS PRIVATE -DWITH_PYTHON_LAYER)
193 list(APPEND Caffe_INCLUDE_DIRS PRIVATE ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR} PUBLIC ${Boost_INCLUDE_DIRS})
194 list(APPEND Caffe_LINKER_LIBS PRIVATE ${PYTHON_LIBRARIES} PUBLIC ${Boost_LIBRARIES})
201 find_package(MatlabMex)
203 set(HAVE_MATLAB TRUE)
206 # sudo apt-get install liboctave-dev
207 find_program(Octave_compiler NAMES mkoctfile DOC "Octave C++ compiler")
209 if(HAVE_MATLAB AND Octave_compiler)
210 set(Matlab_build_mex_using "Matlab" CACHE STRING "Select Matlab or Octave if both detected")
211 set_property(CACHE Matlab_build_mex_using PROPERTY STRINGS "Matlab;Octave")
217 find_package(Doxygen)