|
|
@@ -1,57 +1,76 @@ |
|
|
-# This list is required for static linking and exported to CaffeConfig.cmake
|
|
|
+# These lists are later turned into target properties on main caffe library target
|
|
|
set(Caffe_LINKER_LIBS "")
|
|
|
+set(Caffe_INCLUDE_DIRS "")
|
|
|
+set(Caffe_DEFINITIONS "")
|
|
|
+set(Caffe_COMPILE_OPTIONS "")
|
|
|
|
|
|
# ---[ Boost
|
|
|
find_package(Boost 1.46 REQUIRED COMPONENTS system thread filesystem)
|
|
|
-include_directories(SYSTEM ${Boost_INCLUDE_DIR})
|
|
|
-list(APPEND Caffe_LINKER_LIBS ${Boost_LIBRARIES})
|
|
|
+list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${Boost_INCLUDE_DIRS})
|
|
|
+list(APPEND Caffe_LINKER_LIBS PUBLIC ${Boost_LIBRARIES})
|
|
|
|
|
|
# ---[ Threads
|
|
|
find_package(Threads REQUIRED)
|
|
|
-list(APPEND Caffe_LINKER_LIBS ${CMAKE_THREAD_LIBS_INIT})
|
|
|
+list(APPEND Caffe_LINKER_LIBS PRIVATE ${CMAKE_THREAD_LIBS_INIT})
|
|
|
+
|
|
|
+# ---[ OpenMP
|
|
|
+if(USE_OPENMP)
|
|
|
+ # Ideally, this should be provided by the BLAS library IMPORTED target. However,
|
|
|
+ # nobody does this, so we need to link to OpenMP explicitly and have the maintainer
|
|
|
+ # to flick the switch manually as needed.
|
|
|
+ #
|
|
|
+ # Moreover, OpenMP package does not provide an IMPORTED target as well, and the
|
|
|
+ # suggested way of linking to OpenMP is to append to CMAKE_{C,CXX}_FLAGS.
|
|
|
+ # However, this naïve method will force any user of Caffe to add the same kludge
|
|
|
+ # into their buildsystem again, so we put these options into per-target PUBLIC
|
|
|
+ # compile options and link flags, so that they will be exported properly.
|
|
|
+ find_package(OpenMP REQUIRED)
|
|
|
+ list(APPEND Caffe_LINKER_LIBS PRIVATE ${OpenMP_CXX_FLAGS})
|
|
|
+ list(APPEND Caffe_COMPILE_OPTIONS PRIVATE ${OpenMP_CXX_FLAGS})
|
|
|
+endif()
|
|
|
|
|
|
# ---[ Google-glog
|
|
|
include("cmake/External/glog.cmake")
|
|
|
-include_directories(SYSTEM ${GLOG_INCLUDE_DIRS})
|
|
|
-list(APPEND Caffe_LINKER_LIBS ${GLOG_LIBRARIES})
|
|
|
+list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${GLOG_INCLUDE_DIRS})
|
|
|
+list(APPEND Caffe_LINKER_LIBS PUBLIC ${GLOG_LIBRARIES})
|
|
|
|
|
|
# ---[ Google-gflags
|
|
|
include("cmake/External/gflags.cmake")
|
|
|
-include_directories(SYSTEM ${GFLAGS_INCLUDE_DIRS})
|
|
|
-list(APPEND Caffe_LINKER_LIBS ${GFLAGS_LIBRARIES})
|
|
|
+list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${GFLAGS_INCLUDE_DIRS})
|
|
|
+list(APPEND Caffe_LINKER_LIBS PUBLIC ${GFLAGS_LIBRARIES})
|
|
|
|
|
|
# ---[ Google-protobuf
|
|
|
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} ${HDF5_HL_LIBRARIES})
|
|
|
+list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${HDF5_INCLUDE_DIRS})
|
|
|
+list(APPEND Caffe_LINKER_LIBS PUBLIC ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES})
|
|
|
|
|
|
# ---[ LMDB
|
|
|
if(USE_LMDB)
|
|
|
find_package(LMDB REQUIRED)
|
|
|
- include_directories(SYSTEM ${LMDB_INCLUDE_DIR})
|
|
|
- list(APPEND Caffe_LINKER_LIBS ${LMDB_LIBRARIES})
|
|
|
- add_definitions(-DUSE_LMDB)
|
|
|
+ list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${LMDB_INCLUDE_DIR})
|
|
|
+ list(APPEND Caffe_LINKER_LIBS PUBLIC ${LMDB_LIBRARIES})
|
|
|
+ list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_LMDB)
|
|
|
if(ALLOW_LMDB_NOLOCK)
|
|
|
- add_definitions(-DALLOW_LMDB_NOLOCK)
|
|
|
+ list(APPEND Caffe_DEFINITIONS PRIVATE -DALLOW_LMDB_NOLOCK)
|
|
|
endif()
|
|
|
endif()
|
|
|
|
|
|
# ---[ LevelDB
|
|
|
if(USE_LEVELDB)
|
|
|
find_package(LevelDB REQUIRED)
|
|
|
- include_directories(SYSTEM ${LevelDB_INCLUDE})
|
|
|
- list(APPEND Caffe_LINKER_LIBS ${LevelDB_LIBRARIES})
|
|
|
- add_definitions(-DUSE_LEVELDB)
|
|
|
+ list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${LevelDB_INCLUDES})
|
|
|
+ list(APPEND Caffe_LINKER_LIBS PUBLIC ${LevelDB_LIBRARIES})
|
|
|
+ list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_LEVELDB)
|
|
|
endif()
|
|
|
|
|
|
# ---[ Snappy
|
|
|
if(USE_LEVELDB)
|
|
|
find_package(Snappy REQUIRED)
|
|
|
- include_directories(SYSTEM ${Snappy_INCLUDE_DIR})
|
|
|
- list(APPEND Caffe_LINKER_LIBS ${Snappy_LIBRARIES})
|
|
|
+ list(APPEND Caffe_INCLUDE_DIRS PRIVATE ${Snappy_INCLUDE_DIR})
|
|
|
+ list(APPEND Caffe_LINKER_LIBS PRIVATE ${Snappy_LIBRARIES})
|
|
|
endif()
|
|
|
|
|
|
# ---[ CUDA
|
|
|
@@ -63,8 +82,7 @@ if(NOT HAVE_CUDA) |
|
|
message(WARNING "-- CUDA is not detected by cmake. Building without it...")
|
|
|
endif()
|
|
|
|
|
|
- # TODO: remove this not cross platform define in future. Use caffe_config.h instead.
|
|
|
- add_definitions(-DCPU_ONLY)
|
|
|
+ list(APPEND Caffe_DEFINITIONS PUBLIC -DCPU_ONLY)
|
|
|
endif()
|
|
|
|
|
|
# ---[ OpenCV
|
|
|
@@ -73,10 +91,10 @@ if(USE_OPENCV) |
|
|
if(NOT OpenCV_FOUND) # if not OpenCV 3.x, then imgcodecs are not found
|
|
|
find_package(OpenCV REQUIRED COMPONENTS core highgui imgproc)
|
|
|
endif()
|
|
|
- include_directories(SYSTEM ${OpenCV_INCLUDE_DIRS})
|
|
|
- list(APPEND Caffe_LINKER_LIBS ${OpenCV_LIBS})
|
|
|
+ list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${OpenCV_INCLUDE_DIRS})
|
|
|
+ list(APPEND Caffe_LINKER_LIBS PUBLIC ${OpenCV_LIBS})
|
|
|
message(STATUS "OpenCV found (${OpenCV_CONFIG_PATH})")
|
|
|
- add_definitions(-DUSE_OPENCV)
|
|
|
+ list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_OPENCV)
|
|
|
endif()
|
|
|
|
|
|
# ---[ BLAS
|
|
|
@@ -86,26 +104,26 @@ if(NOT APPLE) |
|
|
|
|
|
if(BLAS STREQUAL "Atlas" OR BLAS STREQUAL "atlas")
|
|
|
find_package(Atlas REQUIRED)
|
|
|
- include_directories(SYSTEM ${Atlas_INCLUDE_DIR})
|
|
|
- list(APPEND Caffe_LINKER_LIBS ${Atlas_LIBRARIES})
|
|
|
+ list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${Atlas_INCLUDE_DIR})
|
|
|
+ list(APPEND Caffe_LINKER_LIBS PUBLIC ${Atlas_LIBRARIES})
|
|
|
elseif(BLAS STREQUAL "Open" OR BLAS STREQUAL "open")
|
|
|
find_package(OpenBLAS REQUIRED)
|
|
|
- include_directories(SYSTEM ${OpenBLAS_INCLUDE_DIR})
|
|
|
- list(APPEND Caffe_LINKER_LIBS ${OpenBLAS_LIB})
|
|
|
+ list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${OpenBLAS_INCLUDE_DIR})
|
|
|
+ list(APPEND Caffe_LINKER_LIBS PUBLIC ${OpenBLAS_LIB})
|
|
|
elseif(BLAS STREQUAL "MKL" OR BLAS STREQUAL "mkl")
|
|
|
find_package(MKL REQUIRED)
|
|
|
- include_directories(SYSTEM ${MKL_INCLUDE_DIR})
|
|
|
- list(APPEND Caffe_LINKER_LIBS ${MKL_LIBRARIES})
|
|
|
- add_definitions(-DUSE_MKL)
|
|
|
+ list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${MKL_INCLUDE_DIR})
|
|
|
+ list(APPEND Caffe_LINKER_LIBS PUBLIC ${MKL_LIBRARIES})
|
|
|
+ list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_MKL)
|
|
|
endif()
|
|
|
elseif(APPLE)
|
|
|
find_package(vecLib REQUIRED)
|
|
|
- include_directories(SYSTEM ${vecLib_INCLUDE_DIR})
|
|
|
- list(APPEND Caffe_LINKER_LIBS ${vecLib_LINKER_LIBS})
|
|
|
+ list(APPEND Caffe_INCLUDE_DIRS PUBLIC ${vecLib_INCLUDE_DIR})
|
|
|
+ list(APPEND Caffe_LINKER_LIBS PUBLIC ${vecLib_LINKER_LIBS})
|
|
|
|
|
|
if(VECLIB_FOUND)
|
|
|
if(NOT vecLib_INCLUDE_DIR MATCHES "^/System/Library/Frameworks/vecLib.framework.*")
|
|
|
- add_definitions(-DUSE_ACCELERATE)
|
|
|
+ list(APPEND Caffe_DEFINITIONS PUBLIC -DUSE_ACCELERATE)
|
|
|
endif()
|
|
|
endif()
|
|
|
endif()
|
|
|
@@ -149,9 +167,9 @@ if(BUILD_python) |
|
|
if(PYTHONLIBS_FOUND AND NUMPY_FOUND AND Boost_PYTHON_FOUND)
|
|
|
set(HAVE_PYTHON TRUE)
|
|
|
if(BUILD_python_layer)
|
|
|
- add_definitions(-DWITH_PYTHON_LAYER)
|
|
|
- include_directories(SYSTEM ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR} ${Boost_INCLUDE_DIRS})
|
|
|
- list(APPEND Caffe_LINKER_LIBS ${PYTHON_LIBRARIES} ${Boost_LIBRARIES})
|
|
|
+ list(APPEND Caffe_DEFINITIONS PRIVATE -DWITH_PYTHON_LAYER)
|
|
|
+ list(APPEND Caffe_INCLUDE_DIRS PRIVATE ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR} PUBLIC ${Boost_INCLUDE_DIRS})
|
|
|
+ list(APPEND Caffe_LINKER_LIBS PRIVATE ${PYTHON_LIBRARIES} PUBLIC ${Boost_LIBRARIES})
|
|
|
endif()
|
|
|
endif()
|
|
|
endif()
|
|
|
|