2016-09-29 57 views
0

我想在我的項目中包含caffe。這是該項目的文件夾結構:使用cmake在C++項目中包含Caffe時出錯

. 
├── AUTHORS 
├── ChangeLog 
├── cmake 
│   ├── FindCaffe.cmake 
│   └── FindCUDA.cmake 
├── CMakeLists.txt 
├── CMakeLists.txt.user 
├── data 
│   └── info.plist 
├── deep-app.pro.user 
├── LICENSE.txt 
├── README.md 
├── [reference] 
│   ├── deep-app.pro 
│   ├── deep-app.pro.user 
│   ├── deployment.pri 
│   ├── main.cpp 
│   ├── main.qml 
│   ├── Page1Form.ui.qml 
│   ├── Page1.qml 
│   └── qml.qrc 
└── src 
    ├── CMakeLists.txt 
    ├── code 
    │   └── main.cpp 
    ├── icons.yml 
    └── res 
     ├── assets 
     │   ├── assets.qrc 
     │   ├── book-open-page.svg 
     │   └── book-open.svg 
     ├── icons 
     │   ├── action_home.svg 
     │   ├── action_list.svg 
     │   ├── action_search.svg 
     │   ├── action_settings.svg 
     │   ├── file_cloud_done.svg 
     │   ├── icons.qrc 
     │   ├── maps_place.svg 
     │   ├── navigation_check.svg 
     │   └── social_school.svg 
     └── qml 
      ├── main.qml 
      ├── Page1Form.ui.qml 
      ├── Page1.qml 
      └── qml.qrc 

這裏是root/CMakeLists.txt

project(generic-object-detection) 

cmake_minimum_required(VERSION 3.0.0 FATAL_ERROR) 
cmake_policy(VERSION 3.4.1) 

ENABLE_LANGUAGE(C) 

# Find includes in corresponding build directories 
set(CMAKE_INCLUDE_CURRENT_DIR ON) 

# Instruct CMake to run moc and rrc automatically when needed 
set(CMAKE_AUTOMOC ON) 
set(CMAKE_AUTORCC ON) 

# Apple-specific configuration 
set(APPLE_SUPPRESS_X11_WARNING ON) 

# Build flags 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden -Werror -Wall -Wextra -Wno-unused-parameter -pedantic -std=c++11") 

### Set libraries' locations 
# Set Caffe 
set(Caffe_DIR "/home/ubuntu/Libraries/caffe") 
set(Caffe_INCLUDE_DIRS "/home/cortana/Libraries/caffe/include") 
set(Caffe_LIBRARIES "/usr/lib/x86_64-linux-gnu/libcaffe.so") 


# Disable debug output for release builds 
if(CMAKE_BUILD_TYPE MATCHES "^[Rr]elease$") 
    add_definitions(-DQT_NO_DEBUG_OUTPUT) 
endif() 

# Minimum version requirements 
set(QT_MIN_VERSION "5.4.0") 

# Find Qt5 
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS 
      Core 
      Qml 
      Quick 
      Concurrent) 

# Find OpenCV 3.1 
find_package(OpenCV 3.1.0 REQUIRED) 
include_directories(${OpenCV_INCLUDE_DIRS}) 

# Find Boost 
FIND_PACKAGE(Boost COMPONENTS program_options REQUIRED) 
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR}) 

# Find CUDA 
FIND_PACKAGE(CUDA REQUIRED) 

# Find Caffe 
FIND_PACKAGE(Caffe REQUIRED) 

if(UNIX) 
    if(APPLE) 
     set(MACOSX_BUNDLE_INFO_STRING "generic-object-detection") 
     set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.mybitchinapp.generic-object-detection") 
     set(MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_NAME}-${PROJECT_VERSION}") 
     set(MACOSX_BUNDLE_BUNDLE_NAME "generic-object-detection") 
     set(MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION}) 
     set(MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}) 
    else() 
     # Assume linux 
     # TODO: Install desktop and appdata files 
    endif() 
elseif(WIN32) 
# Nothing to do here 
endif() 

add_subdirectory(src) 

文件root/src/CMakeLists.txt

file(GLOB_RECURSE SOURCES 
      *.cpp *.h 
      code/*.cpp code/*.h) 

set(SOURCES ${SOURCES} 
      res/assets/assets.qrc 
      res/icons/icons.qrc 
      res/qml/qml.qrc) 

add_executable(deep-app ${SOURCES}) 

target_link_libraries(deep-app 
         Qt5::Core 
         Qt5::Qml 
         Qt5::Quick 
         Qt5::Concurrent 
         ${OpenCV_LIBS} 
         ${Boost_LIBRARIES} 
         ${CUDA_LIBRARIES}) 

set_target_properties(deep-app PROPERTIES MACOSX_BUNDLE_INFO_PLIST ${CMAKE_SOURCE_DIR}/data/Info.plist) 

install(TARGETS deep-app 
     RUNTIME DESTINATION bin 
     DESTINATION ${CMAKE_INSTALL_BINDIR}) 

的錯誤是:

CMake Error at CMakeLists.txt:55 (FIND_PACKAGE): 
    By not providing "FindCaffe.cmake" in CMAKE_MODULE_PATH this project has 
    asked CMake to find a package configuration file provided by "Caffe", but 
    CMake did not find one. 

    Could not find a package configuration file provided by "Caffe" with any of 
    the following names: 

    CaffeConfig.cmake 
    caffe-config.cmake 

    Add the installation prefix of "Caffe" to CMAKE_PREFIX_PATH or set 
    "Caffe_DIR" to a directory containing one of the above files. If "Caffe" 
    provides a separate development package or SDK, be sure it has been 
    installed. 


-- Configuring incomplete, errors occurred! 

我有set註冊Caffe_DIR和其他所需的變量。但它仍然會給出同樣的錯誤。我刪除了以前的[cmake]緩存,所以這不是問題。我無法弄清楚如何解決這個問題,我需要在項目中使用Caffe。請幫忙。

回答

1

你要設置你的CMAKE_MODULE_PATH到位置,其中的cmake module文件所在的Caffe項目,這將是指向的目錄下面:

. 
├── AUTHORS 
├── ChangeLog 
├── cmake   <---------Set Caffe_DIR it to this directory 
│ ├── FindCaffe.cmake 
│ └── FindCUDA.cmake 

如果不工作,那麼你應該設置你的Caffe_DIR到上面的目錄,並確保您重新命名目錄下的文件,以下面的錯誤中提到的名稱之一:

Could not find a package configuration file provided by "Caffe" with any of 
    the following names: 

    CaffeConfig.cmake 
    caffe-config.cmake 
+0

感謝,多數民衆贊成在一兩件事,我錯過了。使用這個後:set(CMAKE_MODULE_PATH $ {CMAKE_MODULE_PATH}「$ {CMAKE_SOURCE_DIR}/cmake」)',它開始工作。 –