Update release_notes.md
[platform/upstream/caffeonacl.git] / cmake / Dependencies.cmake
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 "")
6
7 # ---[ Boost
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})
11
12 # ---[ Threads
13 find_package(Threads REQUIRED)
14 list(APPEND Caffe_LINKER_LIBS PRIVATE ${CMAKE_THREAD_LIBS_INIT})
15
16 # ---[ OpenMP
17 if(USE_OPENMP)
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.
21   #
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})
30 endif()
31
32 # ---[ Google-glog
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})
36
37 # ---[ Google-gflags
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})
41
42 # ---[ Google-protobuf
43 include(cmake/ProtoBuf.cmake)
44
45 # ---[ HDF5
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})
49
50 # ---[ LMDB
51 if(USE_LMDB)
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)
56   if(ALLOW_LMDB_NOLOCK)
57     list(APPEND Caffe_DEFINITIONS PRIVATE -DALLOW_LMDB_NOLOCK)
58   endif()
59 endif()
60
61 # ---[ LevelDB
62 if(USE_LEVELDB)
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)
67 endif()
68
69 # ---[ ACL
70 if(USE_ACL)
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)
77     foreach(i ${__list})
78         list(APPEND Caffe_LINKER_LIBS PUBLIC ${i})
79     endforeach()
80   list(APPEND Caffe_COMPILE_OPTIONS PRIVATE -std=c++11)
81   list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_ACL)
82 endif()
83
84 # ---[ Snappy
85 if(USE_LEVELDB)
86   find_package(Snappy REQUIRED)
87   list(APPEND Caffe_INCLUDE_DIRS PRIVATE ${Snappy_INCLUDE_DIR})
88   list(APPEND Caffe_LINKER_LIBS PRIVATE ${Snappy_LIBRARIES})
89 endif()
90
91 # ---[ CUDA
92 include(cmake/Cuda.cmake)
93 if(NOT HAVE_CUDA)
94   if(CPU_ONLY)
95     message(STATUS "-- CUDA is disabled. Building without it...")
96   else()
97     message(WARNING "-- CUDA is not detected by cmake. Building without it...")
98   endif()
99
100   list(APPEND Caffe_DEFINITIONS PUBLIC -DCPU_ONLY)
101 endif()
102
103 if(USE_NCCL)
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)
108 endif()
109
110 # ---[ OpenCV
111 if(USE_OPENCV)
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)
115   endif()
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)
120 endif()
121
122 # ---[ BLAS
123 if(NOT APPLE)
124   set(BLAS "Atlas" CACHE STRING "Selected BLAS library")
125   set_property(CACHE BLAS PROPERTY STRINGS "Atlas;Open;MKL")
126
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)
140   endif()
141 elseif(APPLE)
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})
145
146   if(VECLIB_FOUND)
147     if(NOT vecLib_INCLUDE_DIR MATCHES "^/System/Library/Frameworks/vecLib.framework.*")
148       list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_ACCELERATE)
149     endif()
150   endif()
151 endif()
152
153 # ---[ Python
154 if(BUILD_python)
155   if(NOT "${python_version}" VERSION_LESS "3.0.0")
156     # use python3
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})
162
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})
166
167     while(NOT "${version}" STREQUAL "" AND NOT Boost_PYTHON_FOUND)
168       STRING( REGEX REPLACE "([0-9.]+).[0-9]+" "\\1" version ${version} )
169
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})
173
174       STRING( REGEX MATCHALL "([0-9.]+).[0-9]+" has_more_version ${version} )
175       if("${has_more_version}" STREQUAL "")
176         break()
177       endif()
178     endwhile()
179     if(NOT Boost_PYTHON_FOUND)
180       find_package(Boost 1.46 COMPONENTS python)
181     endif()
182   else()
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)
188   endif()
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})
195     endif()
196   endif()
197 endif()
198
199 # ---[ Matlab
200 if(BUILD_matlab)
201   find_package(MatlabMex)
202   if(MATLABMEX_FOUND)
203     set(HAVE_MATLAB TRUE)
204   endif()
205
206   # sudo apt-get install liboctave-dev
207   find_program(Octave_compiler NAMES mkoctfile DOC "Octave C++ compiler")
208
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")
212   endif()
213 endif()
214
215 # ---[ Doxygen
216 if(BUILD_docs)
217   find_package(Doxygen)
218 endif()