diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d33e55f6190df70c4d6ad794377e696a2405a56..d9f97267282ac319d56612b5aa8c8061459f787e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -183,7 +183,14 @@ if (UNIX AND NOT APPLE) endif () find_package(GFlags) find_package(Glog) - find_package(OpenCV) + if (OpenCV_CONFIG_FILE) + include (${OpenCV_CONFIG_FILE}) + elseif (OpenCV_INCLUDE_DIRS AND OpenCV_LIBS_DIR) + file(GLOB_RECURSE OpenCV_LIBS "${OpenCV_LIBS_DIR}*.so") + set(OpenCV_FOUND 1) + else () + find_package(OpenCV) + endif (OpenCV_CONFIG_FILE) # 3D if (BUILD_MODULE_3D) @@ -307,12 +314,6 @@ if (UNIX AND NOT APPLE) set(Caffe_FOUND 1) endif (Caffe_INCLUDE_DIRS AND Caffe_LIBS AND NOT BUILD_CAFFE) - # Check if caffe is installed in known paths - if (NOT Caffe_FOUND AND NOT BUILD_CAFFE) - message(STATUS "Looking for caffe around in expected paths.") - find_package(Caffe) - endif (NOT Caffe_FOUND AND NOT BUILD_CAFFE) - # Else build from scratch if (BUILD_CAFFE) diff --git a/cmake/Modules/FindCaffe.cmake b/cmake/Modules/FindCaffe.cmake index 5d47a39c933ea86d23d12ccb9617b95c518ce723..c7992bb7cb29e6911a6c6078c9f804254ec82799 100644 --- a/cmake/Modules/FindCaffe.cmake +++ b/cmake/Modules/FindCaffe.cmake @@ -12,14 +12,15 @@ find_path(Caffe_INCLUDE_DIRS NAMES caffe/proto/caffe.pb.h caffe/util/io.hpp HINTS - /usr/local/include - ${CMAKE_BINARY_DIR}/caffe/include) + ${CMAKE_BINARY_DIR}/caffe/include + NO_DEFAULT_PATH) + find_library(Caffe_LIBS NAMES caffe HINTS - /usr/local/lib ${CMAKE_BINARY_DIR}/caffe/lib - ${CMAKE_BINARY_DIR}/caffe/lib/x86_64-linux-gnu) + ${CMAKE_BINARY_DIR}/caffe/lib/x86_64-linux-gnu + NO_DEFAULT_PATH) if (Caffe_LIBS AND Caffe_INCLUDE_DIRS) set(Caffe_FOUND 1) diff --git a/doc/installation.md b/doc/installation.md index f7453c8b1fe097a87704ccbd05d22945f2475783..d06ad82f829ee128cf8cf6f72af6c10bd5f2ade7 100644 --- a/doc/installation.md +++ b/doc/installation.md @@ -269,9 +269,16 @@ cmake .. ``` ##### SCENARIO 2 -- Caffe installed and OpenCV build from source -In this example, we assume that Caffe and OpenCV are already present. The user needs to supply the paths of the library to CMake. For OpenCV, specify the `OpenCV_DIR` which is where the user build OpenCV. For Caffe, specify the include directory and library using the `Caffe_INCLUDE_DIRS` and `Caffe_LIBS` variables. This will be where you installed Caffe. Below is an example of the same. +In this example, we assume that Caffe and OpenCV are already present. The user needs to supply the paths of the libraries and the include directories to CMake. For OpenCV, specify the include directories and the libraries directory using `OpenCV_INCLUDE_DIRS` and `OpenCV_LIBS_DIR` variables respectively. Alternatively, the user can also specify the path to the `OpenCVConfig.cmake` file by setting the `OpenCV_CONFIG_FILE` variable. For Caffe, specify the include directory and library using the `Caffe_INCLUDE_DIRS` and `Caffe_LIBS` variables. This will be where you installed Caffe. Below is an example of the same. ```bash -cmake -DOpenCV_DIR=/home/"${USER}"/softwares/opencv/build \ +cmake -DOpenCV_INCLUDE_DIRS=/home/"${USER}"/softwares/opencv/build/install/include \ + -DOpenCV_LIBS_DIR=/home/"${USER}"/softwares/opencv/build/install/lib \ + -DCaffe_INCLUDE_DIRS=/home/"${USER}"/softwares/caffe/build/install/include \ + -DCaffe_LIBS=/home/"${USER}"/softwares/caffe/build/install/lib/libcaffe.so -DBUILD_CAFFE=OFF .. +``` + +```bash +cmake -DOpenCV_CONFIG_FILE=/home/"${USER}"/softwares/opencv/build/install/share/OpenCV/OpenCVConfig.cmake \ -DCaffe_INCLUDE_DIRS=/home/"${USER}"/softwares/caffe/build/install/include \ -DCaffe_LIBS=/home/"${USER}"/softwares/caffe/build/install/lib/libcaffe.so -DBUILD_CAFFE=OFF .. ``` @@ -279,5 +286,10 @@ cmake -DOpenCV_DIR=/home/"${USER}"/softwares/opencv/build \ ##### SCENARIO 3 -- OpenCV already installed If Caffe is not already present but OpenCV is, then use the below command. ```bash -cmake -DOpenCV_DIR=/home/"${USER}"/softwares/opencv/build +cmake -DOpenCV_INCLUDE_DIRS=/home/"${USER}"/softwares/opencv/build/install/include \ + -DOpenCV_LIBS_DIR=/home/"${USER}"/softwares/opencv/build/install/lib .. +``` + +```bash +cmake -DOpenCV_CONFIG_FILE=/home/"${USER}"/softwares/opencv/build/install/share/OpenCV/OpenCVConfig.cmake .. ```