I feel I don't understand how to set up an "include" directory in a C++ project for header files, and also how to include these headers in the .cpp files.
I'm talking about a project in the context of a ROS package, but I don't think ROS would make the structure of the project any different.
To be specific, this is the structure of the directory I'm talking about:
yuqiong#yuqiong-G7-7588:/media/yuqiong/DATA/sdd_vio$ tree
.
├── CMakeLists.txt
├── CMakeModules
│ └── FindEigen.cmake
├── config
│ ├── camchain-imucam-euroc.yaml
│ ├── camchain-imucam-fla1_11052016.yaml
│ ├── camchain-imucam-snapdragon.yaml
│ ├── custom_rosconsole.conf
│ ├── disp_vo_param.yaml
│ ├── ukf_params.yaml
│ └── vo_param.yaml
├── include
│ └── sdd_vio
│ ├── grid.h
│ ├── pinhole_camera_stereo.h
│ ├── sdd_vio_nodelet.h
│ ├── utils
│ │ ├── calib_utils.h
│ │ ├── math_utils.h
│ │ ├── ros_params_helper.h
│ │ └── timer.hpp
│ ├── visualization.h
│ └── vo_stereo.h
├── launch
│ ├── bag_reader.launch
│ ├── disp_nodelet.launch
│ ├── image_proc_rectify.launch
│ ├── imu.launch
│ ├── vins_node.launch
│ ├── vins_nodelet_euroc.launch
│ ├── vins_nodelet.launch
│ ├── vins_robot.launch
│ └── visualization.launch
├── LICENSE
├── nodelet_plugins.xml
├── package.xml
├── readme.md
├── rviz
│ ├── rviz_config_gs.rviz
│ └── rviz_config.rviz
├── src
│ ├── grid.cpp
│ ├── imu_integration_nodelet.cpp
│ ├── pinhole_camera_stereo.cpp
│ ├── sdd_vio_bag_reader.cpp
│ ├── sdd_vio_node.cpp
│ ├── sdd_vio_nodelet.cpp
│ ├── utils
│ │ ├── calib_utils.cpp
│ │ └── math_utils.cpp
│ ├── visualization.cpp
│ ├── vo_stereo_1.cpp
│ ├── vo_stereo_2.cpp
│ ├── vo_stereo_3.cpp
│ └── vo_stereo_4.cpp
└── statistics
9 directories, 47 files
So we see all the header files in the ./include/sdd_vio folder.
But in the ./src/vo_stereo_1.cpp file, it includes a header file like this:
#include "sdd_vio/vo_stereo.h"
I feel it should use this instead:
#include "../include/sdd_vio/vo_stereo.h"
Why does it omit the ../include part?
Also, it would be good if there are good resources to help me learn about build / CMake / how to figure out the correct include path in general. I've read the official CMake tutorial, some tutorials on how compile + link actually work, but still feel my knowledge is not systematic... Thanks!
Edit
Adding the CMakeLists.txt file below as mentioned in the answer.
cmake_minimum_required(VERSION 2.8.3)
project(sdd_vio)
IF(DEFINED ENV{ARM_ARCHITECTURE})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -march=native -mfpu=neon")
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Ofast -fno-signed-zeros -fno-math-errno -funroll-loops -fno-strict-aliasing")
ELSE()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -Wall -std=c++11")
ENDIF()
# set default build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
find_package(catkin REQUIRED COMPONENTS
roscpp
image_transport
sensor_msgs
cv_bridge
visualization_msgs
tf
nodelet
rosbag
)
FIND_PACKAGE(OpenCV 3 REQUIRED)
FIND_PACKAGE(Eigen3 REQUIRED)
find_package(Boost REQUIRED COMPONENTS thread)
#find_package(Ceres REQUIRED)
# Check if OpenCV package has been found
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
# Check if Eigen package has been found
message(STATUS "Eigen library status:")
message(STATUS " version: ${EIGEN3_VERSION}")
message(STATUS " libraries: ${EIGEN3_LIBS}")
message(STATUS " include path: ${EIGEN3_INCLUDE_DIRS}")
catkin_package(
LIBRARIES vo_nodelet imu_integration_nodelet
DEPENDS EIGEN3 OpenCV
CATKIN_DEPENDS roscpp image_transport sensor_msgs visualization_msgs tf nodelet
LIBRARIES sdd_vio_nodelet
)
INCLUDE_DIRECTORIES(
include
${EIGEN3_INCLUDE_DIR}
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
add_library(pinhole_camera src/pinhole_camera_stereo.cpp)
target_link_libraries(pinhole_camera ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${OpenCV_LIBS} utils)
add_library(utils src/utils/math_utils.cpp src/utils/calib_utils.cpp)
target_link_libraries(utils ${OpenCV_LIBS} ${catkin_LIBRARIES})
add_library(vo src/vo_stereo_1.cpp src/vo_stereo_2.cpp src/vo_stereo_3.cpp src/vo_stereo_4.cpp src/grid.cpp)
# add_library(vo src/disp_vo_stereo.cpp src/grid.cpp)
target_link_libraries(vo utils pinhole_camera ${catkin_LIBRARIES} ${Boost_LIBRARIES} ${OpenCV_LIBS}) # ${CERES_LIBRARIES}
# for nodelet
add_library(vo_nodelet src/sdd_vio_nodelet.cpp src/visualization.cpp)
add_dependencies(vo_nodelet ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(vo_nodelet vo ${catkin_LIBRARIES} ${Boost_LIBRARIES})
add_library(imu_integration_nodelet src/imu_integration_nodelet.cpp)
add_dependencies(imu_integration_nodelet ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(imu_integration_nodelet ${catkin_LIBRARIES})
# for node
ADD_EXECUTABLE(sdd_vio_node src/sdd_vio_node.cpp src/visualization.cpp)
TARGET_LINK_LIBRARIES(
sdd_vio_node
pinhole_camera
vo
${OpenCV_LIBS}
${catkin_LIBRARIES}
)
add_executable(sdd_vio_bag_reader src/sdd_vio_bag_reader.cpp)
target_link_libraries(sdd_vio_bag_reader vo_nodelet)
Why does it omit the ../include part?
Your CMakeLists.txt file contains the following lines in it:
INCLUDE_DIRECTORIES(
include
${EIGEN3_INCLUDE_DIR}
${catkin_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
INCLUDE_DIRECTORIES tells the compiler where to look for header files. In this case one of the places is the include directory in your project, hence allows you to omit the ../include part. This is also the better form to use because using an absolute path and then moving the .cpp file that contains the include statement to some sub-folder in the future might break your code.
it would be good if there are good resources to help me learn about build / CMake
There are a couple of good books about Cmake, like Cmake CookBook. But in this case since you are dealing with ROS, I would suggest you start with ROS tutorials, they cover some of the basics of what you wish to know.
Related
I'm trying to use my own library in a different project using CMake and FetchContent. My library is a static one that's built with CMake in a separate git repo, and it works fine when built with a demo in the same repo. When I use FetchContent to use it in a separate project it can't find the header files and I don't know how to include them.
dynamic-shadow-lib tree:
.
├── CMakeLists.txt
├── demo
│ ├── CMakeLists.txt
│ └── main.cpp
├── include
│ ├── line2D.hpp
│ ├── math.hpp
│ ├── mathplotUtil.hpp
│ ├── shape2D.hpp
│ ├── square2D.hpp
│ ├── triangle2D.hpp
│ └── vec2f.hpp
├── LICENSE
├── README.md
├── src
│ ├── line2D.cpp
│ ├── math.cpp
│ ├── square2D.cpp
│ ├── triangle2D.cpp
│ └── vec2f.cpp
└── tests
├── CMakeLists.txt
├── unit_tests
│ ├── CMakeLists.txt
│ ├── line2DTests.cpp
│ ├── main.cpp
│ ├── mathTests.cpp
│ ├── square2DTests.cpp
│ └── vec2fTests.cpp
└── visual_tests
├── CMakeLists.txt
├── main.cpp
└── visualTests.hpp
dynamic-shadow-lib root CmakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(
dynamic-shadows
VERSION 1.0
LANGUAGES CXX
)
# Build config variables
set(BUILD_DEMO FALSE)
set(BUILD_TESTS FALSE)
# Set C++ to version 14
set(CMAKE_CXX_STANDARD 14)
# Set binary destinations
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Set header dir
set(HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${HEADERS_DIR})
# Set source dir
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
# Set a name for the target
set(TARGET_LIB ${CMAKE_PROJECT_NAME}-lib)
# Make library ${TARGET_LIB}
add_library(
${TARGET_LIB} STATIC
${SOURCE_DIR}/math.cpp
${SOURCE_DIR}/vec2f.cpp
${SOURCE_DIR}/line2D.cpp
${SOURCE_DIR}/square2D.cpp
${SOURCE_DIR}/triangle2D.cpp
)
if (${BUILD_TESTS})
# Enable testing (GoogleTests)
include(CTest)
enable_testing()
add_subdirectory(tests)
endif()
if (${BUILD_DEMO})
# Demo
add_subdirectory(demo)
endif()
Project that I'm trying to include my lib in (tree):
.
├── CMakeLists.txt
├── include
│ ├── Game.hpp
│ └── Primitive.hpp
├── LICENSE
├── README.md
├── src
│ ├── Game.cpp
│ └── main.cpp
└── tests
├── CMakeLists.txt
└── main.cpp
Projects root CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(realtime-light-shadow-2D
LANGUAGES CXX
VERSION 1.0
)
# Set extra compiler flags
set(CMAKE_CXX_FLAGS "-W -Wall -std=c++14 -fopenmp")
# Set binary destinations
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Dependencies
include(FetchContent)
set (FETCHCONTENT_QUIET FALSE)
# SFML
message (STATUS "Adding SFML..")
FetchContent_Declare(
sfml
GIT_REPOSITORY "https://github.com/SFML/SFML"
GIT_TAG 218154cf0098de3f495e31ced489da24b7318638 # Latest
GIT_PROGRESS TRUE
)
# No need to build audio and network modules
set(SFML_BUILD_AUDIO FALSE)
set(SFML_BUILD_NETWORK FALSE)
FetchContent_MakeAvailable(sfml)
# ImGui
message (STATUS "Adding ImGui")
FetchContent_Declare(
imgui
GIT_REPOSITORY https://github.com/ocornut/imgui
GIT_TAG 5c8f8d031166765d2f1e2ac2de27df6d3691c05a # Latest
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(imgui)
# ImGui-SFML
message (STATUS "Adding ImGui-SFML")
FetchContent_Declare(
imgui-sfml
GIT_REPOSITORY https://github.com/eliasdaler/imgui-sfml
GIT_TAG 4129d276d45845581b6ba99ede50db6f761e5089 # Latest
GIT_PROGRESS TRUE
)
set(IMGUI_DIR ${imgui_SOURCE_DIR})
set(IMGUI_SFML_FIND_SFML OFF)
set(IMGUI_SFML_IMGUI_DEMO ON)
FetchContent_MakeAvailable(imgui-sfml)
# dynamic-shadows-lib
message( STATUS "Adding dynamic-shadow-lib")
FetchContent_Declare(
dynamic-shadows-lib
GIT_REPOSITORY https://github.com/JesperGlas/dynamic-shadows-lib/
GIT_TAG 59c7884caac7cc98f902fd880ccb1c9b0f50cca0 # Latest
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(dynamic-shadows-lib)
# Set header dir
set(HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${HEADERS_DIR})
# Set source dir
set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
set(TARGET_BIN ${CMAKE_PROJECT_NAME})
add_executable(
${TARGET_BIN}
${SOURCE_DIR}/main.cpp
${SOURCE_DIR}/Game.cpp
)
target_link_libraries(
${TARGET_BIN}
PUBLIC
sfml-system
sfml-graphics
ImGui-SFML::ImGui-SFML
dynamic-shadows-lib
)
When I try to build the project (sfml-dynamic-light-demo) I get the following error:
[build] /home/jesper/dev/cpp/sfml-dynamic-light-demo/include/Primitive.hpp:4:10: fatal error: vec2f.hpp: No such file or directory
[build] 4 | #include "vec2f.hpp"
Which tells me that the libraries include folder might not be available to the project. I've tried to include it as an install(DIRECTORY ${HEADER_DIR}) in the libs root CMakeLists, but it has no effect. I suspect I'm using it wrong since when I build the project I still get "No install step for 'dynamic-shadows-lib-populate'".
What am I doing wrong? If it's a concept that I'm missing, what should I read up on to make it work?
Thanks to the comments I was able to solve this. In my library (Built with CMake) I used the variable CMAKE_PROJECT_NAME when creating my library (CMAKE_PROJECT_NAME-lib). This variable references the top root CMakeLists.txt which resultet in my library getting the wrong name when I used it in another project. By changing all of those variables to PROJECT_NAME, and other similar ones, everything worked as it should.
TLDR: Make sure to use local variables when you want to use a CMake project as a subproject. (In this case PROJECT_NAME, instead of CMAKE_PROJECT_NAME etc...).
I have a project
├── CMakeLists.txt
│ ├── log
│ │ ├── CMakeLists.txt
│ │ ├── include
│ │ │ ├── log.h
│ │ └── src
│ │ ├── log.cpp
│ └── main.cpp
In log.cpp I am usng #include "../include/log.h" and in main.cpp I amd using #include "include/log.h"
I want to use #include "log.h"
I read that target_include_directories can help me.
How can I apply it to my CMakeLists.txt
cmake_minimum_required(VERSION 3.18)
project(Logger)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
#include_directories(log/include/) -- I used this, but I want to use target_include_directories
add_library(log_lib log/src/log.cpp)
add_executable(demo main.cpp)
target_link_libraries(demo log_lib)
define the target and then use the name as the first argument for target_include_directories
add_library(log_lib log/src/log.cpp)
target_include_directories(log_lib PUBLIC log/include)
worry about INTERFACE vs PUBLIC vs PRIVATE after you've got it all working and you want to understand it better. (This option transitively affects targets that depend on your library).
The line below helped
target_include_directories(log_lib PUBLIC log/include)
RT~ ps: cmake version 3.9.2
My codebase just like this.
suzanwen#n224-004-133:~/repos/C++/ttt:)$ tree -L 2
.
├── build
│ ├── bin
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── lib
│ ├── Makefile
│ ├── test
│ └── thirdparty
├── build.sh
├── CMakeLists.txt
├── Makefile
├── test
│ ├── CMakeLists.txt
│ └── main.cc
└── thirdparty
├── CMakeLists.txt
├── gflags
└── hellolib
10 directories, 9 files
my thirdparty/hellolib/CMakeLists.txt is
PROJECT(hello)
SET(LIBHELLO_SRC hello.cc)
MESSAGE(STATUS "LIBRARY PATH=" ${LIBRARY_OUTPUT_PATH})
ADD_LIBRARY(hello_static STATIC ${LIBHELLO_SRC})
SET_TARGET_PROPERTIES(hello_static PROPERTIES ARCHIVE_OUTPUT_NAME "hello")
my test/CMakeLists.txt is
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/thirdparty/hellolib
${PROJECT_SOURCE_DIR}/thirdparty/gflags/include)
IF(LIBRARY_OUTPUT_PATH)
LINK_DIRECTORIES(${LIBRARY_OUTPUT_PATH})
ENDIF(LIBRARY_OUTPUT_PATH)
ADD_EXECUTABLE(main main.cc)
TARGET_LINK_LIBRARIES(main hello)
# TARGET_LINK_LIBRARIES(main hello_static)
when I build my top-level project, an error occurs like this.
/usr/bin/c++ -rdynamic CMakeFiles/main.dir/main.cc.o -o ../bin/main -L/home/suzanwen/repos/C++/ttt/build/lib -Wl,-rpath,/home/suzanwen/repos/C++/ttt/build/lib -lhello
/usr/bin/ld: cannot find -lhello
But when I comment the line # SET_TARGET_PROPERTIES(hello_static PROPERTIES ARCHIVE_OUTPUT_NAME "hello") and TARGET_LINK_LIBRARIES with hello_static, everything goes fine.
It seems that TARGET_LINK_LIBRARIES cannot find renamed lib target. Could anyone explain it? thanks in advance.
It seems that TARGET_LINK_LIBRARIES cannot find renamed lib target.
Setting ARCHIVE_OUTPUT_NAME property renames not a target, but an output file. So linking with a target still works:
TARGET_LINK_LIBRARIES(main hello_static)
One cannot rename the target once it is created, but it is possible to create ALIAS for a target:
ADD_LIBRARY(hello ALIAS hello_static)
After that it is possible to link with the alias:
TARGET_LINK_LIBRARIES(main hello)
I have re-organized a CMake Qt5 project in multiple subdirectory, the final folder structure looks like this:
├── CMakeLists.txt
├── headers
│ ├── a.h
│ ├── b.h
├── LICENSE
├── README.md
├── resources
│ ├── images
│ │ ├── img.png
│ └── res.qrc
├── sources
│ ├── main.cpp
│ ├── a.cpp
│ ├── b.cpp
└── ui
├── a.ui
└── b.ui
The problems comes when i try to compile the whole project: in fact the compiler say that it cannot find headers ui files(e.g. ui_main.h and ui_sub.h), this is the error:
In file included from /home/vbm/test/headers/a.h:13,
from /home/vbm/test/headers/b.h:14,
from /home/vbm/test/sources/main.cpp:6:
/home/vbm/test/headers/a.h:12:10: fatal error: ui_a.h: No such file or directory
#include "ui_a.h"
^~~~~~~~
This is my CMakeLists.txt file:
cmake_minimum_required(VERSION 3.9)
project(test VERSION 0.1)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
# Declaring files
set( SOURCES
sources/main.cpp
source/a.cpp
source/b.cpp
)
set( HEADERS
headers/a.h
headers/b.h
)
set( UIS
ui/a.ui
ui/b.ui
)
set( RES
resources/res.qrc
)
add_executable(test ${SOURCES} ${HEADERS} ${UIS} ${RES})
target_link_libraries(test Qt5::Widgets Qt5::Core)
How can i specify the output directory of those header UI files?
--EDIT--
I have already added the CMAKE_AUTOUIC_SEARCH_PATHS property without any success, the compiler still gave me the same error.
This is what i've added to the CMakeLists.txt:
set(CMAKE_AUTOUIC_SEARCH_PATHS "${PROJECT_SOURCE_DIR}/ui")
I want to include caffe in my project. This is the folder structure of the project:
.
├── 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
Here is the 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)
The file 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})
The error is:
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!
I have setup Caffe_DIR and other required variables. But it still gives the same errors. I removed the previous [cmake] cache so thats not the problem. I cant figure out how to resolve this problem and I need to use Caffe in the project. Please help.
You want to set your CMAKE_MODULE_PATH to location where cmake module files are located for Caffe project, which would be directory pointed to below:
.
├── AUTHORS
├── ChangeLog
├── cmake <---------Set Caffe_DIR it to this directory
│ ├── FindCaffe.cmake
│ └── FindCUDA.cmake
If that doesn't work then you should set your Caffe_DIR to the above directory and make sure your rename the files under that directory to one of the names mentioned in the following error:
Could not find a package configuration file provided by "Caffe" with any of
the following names:
CaffeConfig.cmake
caffe-config.cmake