summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorIvan Shapovalov <intelfx@intelfx.name>2016-08-14 04:57:22 +0300
committerIvan Shapovalov <intelfx@intelfx.name>2016-08-31 15:20:49 +0300
commitf1b9da54598923c531e1a98c4f1546169165e441 (patch)
treec112f9175eedf6b25aa0abcb36a0ffc651ac1031 /cmake
parent6200b915601e1f7b2ec6d4746dc143114722ec38 (diff)
downloadcaffe-f1b9da54598923c531e1a98c4f1546169165e441.tar.gz
caffe-f1b9da54598923c531e1a98c4f1546169165e441.tar.bz2
caffe-f1b9da54598923c531e1a98c4f1546169165e441.zip
cmake: add option to link with OpenMP
Despite Caffe itself does not use OpenMP, explicitly linking to OpenMP should be done when one statically links to a BLAS library which uses OpenMP internally and does not provide proper CMake imported targets with proper dependencies (nobody this so far).
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Dependencies.cmake17
1 files changed, 13 insertions, 4 deletions
diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
index 6a127592..290c161b 100644
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -1,7 +1,8 @@
-# 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)
@@ -14,10 +15,18 @@ list(APPEND Caffe_LINKER_LIBS PRIVATE ${CMAKE_THREAD_LIBS_INIT})
# ---[ OpenMP
if(USE_OPENMP)
- # TODO: use something exportable here
+ # 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)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
+ list(APPEND Caffe_LINKER_LIBS PRIVATE ${OpenMP_CXX_FLAGS})
+ list(APPEND Caffe_COMPILE_OPTIONS PRIVATE ${OpenMP_CXX_FLAGS})
endif()
# ---[ Google-glog