When I am creating custom libraries using OpenCV4 in the libs directory I am getting the following error:
/Documents/opencv-palisade/libs/image.cpp:2:10: fatal error: opencv2/opencv.hpp: No such file or directory
2 | #include <opencv2/opencv.hpp>
| ^~~~~~~~~~~~~~~~~~~~
Directory Structure:
.
├── build
│ ├── CMakeCache.txt
│ ├── CMakeFiles
│ ├── cmake_install.cmake
│ ├── image.jpg
│ ├── include
│ ├── libs
│ ├── Makefile
│ ├── opencv-palisade
│ ├── test.jpg
│ └── transformed_image.jpg
├── CMakeLists.txt
├── libs
│ ├── CMakeLists.txt
│ ├── image.cpp
│ └── image.hpp
└── main.cpp
5 directories, 12 files
libs/CMakeLists.txt:
project(libs)
include_directories(${OpenCV_INCLUDE_DIRS})
add_library(
image_compute
SHARED
image.hpp
image.cpp
)
root CMakeLists.txt:
cmake_minimum_required(VERSION 3.16.3)
project(opencv-palisade VERSION 1.0)
#Include header files
add_subdirectory(libs)
include_directories(libs)
# Import OpenCV library
find_package(OpenCV 4 REQUIRED)
if(OpenCV_FOUND)
message(STATUS "Found OpenCV version ${OpenCV_VERSION}")
message(STATUS "OpenCV directories: ${OpenCV_INCLUDE_DIRS}")
message(STATUS "OpenCV libraries: ${OpenCV_LIBS}")
include_directories(${OpenCV_INCLUDE_DIRS})
else()
message(FATAL_ERROR "OpenCV not found, please read the README.md")
endif(OpenCV_FOUND)
#build main.cpp
add_executable(${PROJECT_NAME} main.cpp)
target_link_directories(${PROJECT_NAME} PUBLIC libs)
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS} image_compute)
How can I fix this issue to be able to create libraries using opencv api?
Related
Installing nested libraries brings compilation errors.
I try to have a project called CROSP that contains multiple internal libraries, namely : StrainParameterisation, RodProperties, PolynomialRepresentation. These libraries are then linked to one base library : CROSP.
This one is the library that is then installed in my usr/local/...
The problem is that when I try to include the library from one external package, I get some errors saying that the compiler did not found the .so file for the internal libraries.
In the following I detail the topology of my project.
The layout of the project is the following:
.
├── cmake
│ ├── cmake_uninstall.cmake.in
│ ├── Config.cmake.in
│ └── installation_module.cmake
├── CMakeLists.txt
└── src
├── CMakeLists.txt
├── CROSP
│ └── cosserat_rod.cpp
├── include
│ └── CROSP
│ ├── CROSP
│ │ └── cosserat_rod.hpp
│ ├── polynomial_representation
│ │ └── polynomial_representation.hpp
│ ├── rod_properties
│ │ └── rod_properties.hpp
│ └── strain_parameterisation
│ └── strain_parameterisation.hpp
├── polynomial_representation
│ └── polynomial_representation.cpp
├── rod_properties
│ └── rod_properties.cpp
└── strain_parameterisation
└── strain_parameterisation.cpp
The CMakeLists are :
Top level CMakeLists
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
project(CROSP LANGUAGES CXX VERSION 2.0)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
find_package(Eigen3 3.4 NO_MODULE REQUIRED)
# External utilities to configure the package
include(GNUInstallDirs)
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR})
set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR})
# Give different names for debug and Release
set(CMAKE_RELEASE_POSTFIX "")
set(CMAKE_DEBUG_POSTFIX "-debug")
add_subdirectory(src)
# Install the library using the default routine
include(cmake/installation_module.cmake)
The installation_module.cmake
# Generates ${PROJECT_NAME}Config.cmake file to use our package in other projects
include(CMakePackageConfigHelpers)
configure_package_config_file(
cmake/Config.cmake.in # input template
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake # output config file
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake # where to put the config file during install
PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR # paths to be used
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
# Generates a config file to ensure that URL's version is checked when importing it
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
# When running make install, config files should be copied as well
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
)
# Add the possibility tu run 'make uninstall' to remove files added via 'make install'
configure_file(
cmake/cmake_uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
IMMEDIATE #ONLY
)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
The Config.cmake.in module :
#PACKAGE_INIT#
set(#PROJECT_NAME#_VERSION #PROJECT_VERSION#)
set_and_check(#PROJECT_NAME#_INCLUDE_DIRS #PACKAGE_INCLUDE_INSTALL_DIR#/#PROJECT_NAME#)
set_and_check(#PROJECT_NAME#_LIBRARY_DIR #PACKAGE_LIB_INSTALL_DIR#)
find_library(#PROJECT_NAME#_LIBRARIES NAMES #PROJECT_NAME# PATHS ${#PROJECT_NAME#_LIBRARY_DIR} NO_DEFAULT_PATH)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(#PROJECT_NAME# DEFAULT_MSG #PROJECT_NAME#_INCLUDE_DIRS #PROJECT_NAME#_LIBRARIES)
Then We have the CMakeLists in src
include_directories(include)
add_library(PolynomialRepresentation SHARED
include/${PROJECT_NAME}/polynomial_representation/polynomial_representation.hpp
polynomial_representation/polynomial_representation.cpp
)
target_link_libraries(PolynomialRepresentation
PRIVATE
Eigen3::Eigen
)
target_compile_options(PolynomialRepresentation
PRIVATE
-Wall
-Wextra
)
add_library(RodProperties SHARED
include/${PROJECT_NAME}/rod_properties/rod_properties.hpp
rod_properties/rod_properties.cpp
)
target_link_libraries(RodProperties
PRIVATE
Eigen3::Eigen
PolynomialRepresentation
)
target_compile_options(RodProperties
PRIVATE
-Wall
-Wextra
)
add_library(StrainParameterisation SHARED
include/${PROJECT_NAME}/strain_parameterisation/strain_parameterisation.hpp
strain_parameterisation/strain_parameterisation.cpp
)
target_link_libraries(StrainParameterisation
PRIVATE
Eigen3::Eigen
PolynomialRepresentation
)
target_compile_options(RodProperties
PRIVATE
-Wall
-Wextra
)
add_library(${PROJECT_NAME} SHARED
include/${PROJECT_NAME}/${PROJECT_NAME}/cosserat_rod.hpp
${PROJECT_NAME}/cosserat_rod.cpp
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
Eigen3::Eigen
PUBLIC
StrainParameterisation
RodProperties
PolynomialRepresentation
)
target_compile_options(RodProperties
PRIVATE
-Werror
-Wall
-Wextra
)
add_executable(main main.cpp)
target_link_libraries(main ${PROJECT_NAME} Eigen3::Eigen)
install(
TARGETS
${PROJECT_NAME}
DESTINATION
${CMAKE_INSTALL_LIBDIR}
)
install(DIRECTORY include/${PROJECT_NAME}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
I can run and install this library.
The following code compiles and runs fine.
#include "CROSP/CROSP/cosserat_rod.hpp"
int main(int argc, char *argv[])
{
::CROSP::polynomial_representation::PolynomialRepresentation poly(5);
::CROSP::rod_properties::MaterialProperties material(200, 100, 10);
::CROSP::CosseratRod rod(poly, material);
::CROSP::CosseratRod rod2(15);
::CROSP::CosseratRod rod3;
return 0;
}
The installation in my usr folder has the following layout
usr
└── local
├── include
│ └── CROSP
│ ├── CROSP
│ │ └── cosserat_rod.hpp
│ ├── polynomial_representation
│ │ └── polynomial_representation.hpp
│ ├── rod_properties
│ │ └── rod_properties.hpp
│ └── strain_parameterisation
│ └── strain_parameterisation.hpp
├── lib
│ ├── libCROSP-debug.so
│ └── libCROSP.so
└── share
└── CROSP
└── cmake
├── CROSPConfig.cmake
└── CROSPConfigVersion.cmake
From another project, I can include the library without problem.
Here there is an example
cmake_minimum_required(VERSION 3.5)
project(test_crosp_library LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(CROSP REQUIRED)
find_package(Eigen3 3.4 NO_MODULE REQUIRED)
add_executable(test_crosp_library main.cpp)
target_link_libraries(test_crosp_library
PUBLIC
CROSP
Eigen3::Eigen
)
And the main.cpp looks like this
#include "CROSP/CROSP/cosserat_rod.hpp"
int main()
{
::CROSP::CosseratRod rod; // errors
return 0;
}
I get the following errors
[ 50%] Linking CXX executable test_crosp_library
/usr/bin/ld: warning: libStrainParameterisation.so, needed by /usr/local/lib/libCROSP.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: warning: libRodProperties.so, needed by /usr/local/lib/libCROSP.so, not found (try using -rpath or -rpath-link)
/usr/bin/ld: /usr/local/lib/libCROSP.so: undefined reference to `LieAlgebra::SE3Pose::getRotationMatrix() const'
/usr/bin/ld: /usr/local/lib/libCROSP.so: undefined reference to `CROSP::strain_parameterisation::StrainParameterisation::StrainParameterisation(CROSP::polynomial_representation::PolynomialRepresentation, unsigned int)'
/usr/bin/ld: /usr/local/lib/libCROSP.so: undefined reference to `CROSP::strain_parameterisation::StrainParameterisation::StrainParameterisation(CROSP::polynomial_representation::PolynomialRepresentation, Eigen::Matrix<double, -1, 1, 0, -1, 1> const&, unsigned int)'
/usr/bin/ld: /usr/local/lib/libCROSP.so: undefined reference to `CROSP::rod_properties::RodProperties::RodProperties(CROSP::polynomial_representation::PolynomialRepresentation)'
/usr/bin/ld: /usr/local/lib/libCROSP.so: undefined reference to `CROSP::strain_parameterisation::StrainParameterisation::updateStacks(Eigen::Matrix<double, -1, 1, 0, -1, 1> const&, Eigen::Matrix<double, -1, 1, 0, -1, 1> const&, Eigen::Matrix<double, -1, 1, 0, -1, 1> const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/test_crosp_library.dir/build.make:97: test_crosp_library] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/test_crosp_library.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
Can you tell what is wrong ?
Moreover, I would like to know if I can use the INTERFACE functionality in order to install the internal libraries in my usr/local with namespaces.
So the CMakeLists.txt of a package using CROSP will be:
find_package(CROSP REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main
CROSP::MaterialProperties
CROSP::StrainParameterisation
)
I'm quite new to C++ and trying to get to grips with CMake and referencing files elsewhere in the project. My references within my test file currently looks like this:
#include "catch.hpp"
#include "../../src/containers/containers.h"
How can I tidy this up using CMake to have the following?
#include "catch.hpp"
#include "src/containers/containers.h"
My folder structure is as follows:
Project
├── lib
│ └── Catch2
│ └── catch.hpp
├── src
│ ├── containers
│ │ ├── containers.cpp
│ │ └── containers.h
│ └── CMakeLists.cpp
├── tests
│ ├── bin
│ ├── containers
│ │ └── test_containers.html
│ ├── CMakeLists.cpp
│ └── tests_main.cpp
├── CMakeLists.cpp
└── main.cpp
And my current CMakeLists.txt in ./tests/ is as follows:
set(CATCH_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/lib/Catch2")
add_library(Catch INTERFACE)
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/tests/bin)
add_executable(test_containers tests_main.cpp containers/test_containers.cpp)
target_link_libraries(test_containers Catch containers)
add_test(NAME test_containers COMMAND test_containers)
enable_testing()
I include the following directories in my base CMakeLists.txt:
add_subdirectory(src)
add_subdirectory(tests)
And in src, I make containers a library:
add_library(containers STATIC
containers/containers.cpp
containers/containers.h)
Adding the line target_include_directories(containers PUBLIC "${CMAKE_SOURCE_DIR}/src") solved the issue and allowed my references to be reduced as desired.
following my comments, supposing you want to use #include "containers.h"
target_include_directories(containers
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/containers>
$<INSTALL_INTERFACE:include/containers>)
set_target_properties(containers PROPERTIES
PUBLIC_HEADER containers/containers.h)
# Install
include(GNUInstallDirs)
install(TARGETS containers
EXPORT ${PROJECT_NAME}Targets
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/containers
# ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
# LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
# RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
ref:
https://cmake.org/cmake/help/latest/command/target_include_directories.html
https://cmake.org/cmake/help/latest/variable/CMAKE_CURRENT_SOURCE_DIR.html
https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
https://cmake.org/cmake/help/latest/command/install.html#targets
I am new to cmake. I have a project which uses dlib and opencv. They are defined as submodules which are in third_party folder. I want to link them to my main project which is 'node' with cmake but I could not achieved. I am sharing my project tree. I did with find_package(OpenCV) and target_link_libraries(recognition-node ${OPENCV_LIBS}) way but I need to compile from source without installing anything. At last, I just want to write 'cmake . && make'
.
├── CMakeLists.txt
├── node
│ ├── build.sh
│ ├── CMakeLists.txt
│ ├── configure.sh
│ ├── findfacestask.cpp
│ ├── findfacestask.h
│ ├── main.cpp
│ ├── matrixwrapper.h
│ ├── poolcontext.cpp
│ ├── poolcontext.h
│ ├── recognition.dat
│ ├── recognizefacetask.cpp
│ ├── recognizefacetask.h
│ ├── runscript
│ ├── sp.dat
│ ├── task.cpp
│ ├── task.h
│ ├── unhandledexception.cpp
│ ├── unhandledexception.h
│ ├── webcamfeed.cpp
│ ├── webcamfeed.h
│ ├── wrapper.cpp
│ └── wrapper.h
└── third_party
├── dlib
│ ├── appveyor.yml
│ ├── CMakeLists.txt
│ ├── dlib
│ ├── docs
│ ├── examples
│ ├── MANIFEST.in
│ ├── python_examples
│ ├── README.md
│ ├── setup.py
│ └── tools
└── opencv
├── 3rdparty
├── apps
├── cmake
├── CMakeLists.txt
├── CONTRIBUTING.md
├── data
├── doc
├── include
├── LICENSE
├── modules
├── platforms
├── README.md
└── samples
Content of my top CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12)
set (CMAKE_CXX_STANDARD 11)
add_subdirectory(node)
add_subdirectory(third_party/dlib)
add_subdirectory(third_party/opencv)
Content of node/CMakeLists.txt
cmake_minimum_required(VERSION 2.8.12)
project(recognition-node)
set(CMAKE_AUTOMOC ON)
find_package(Qt5Widgets REQUIRED)
add_executable(recognition-node main.cpp
webcamfeed.cpp
poolcontext.cpp
unhandledexception.cpp
task.cpp
findfacestask.cpp
wrapper.cpp
recognizefacetask.cpp)
target_link_libraries(recognition-node Qt5::Widgets)
target_link_libraries(recognition-node dlib::dlib)
target_link_libraries(recognition-node opencv::core)
It gives error in 'make' stage which is :
/home/arnes/workspace/recognition-node/node/poolcontext.h:10:28: fatal error:
opencv2/core.hpp: No such file or directory
Since you insist on keeping the opencv in your project tree
It is easier way but I just want it to do in this way.
Here is the solution that for sure works fine with your project tree that you posted in the question and with opencv-3.4.1. For simplicity I will neglect dlib library and Qt dependency, since you didn't have any problem with it.
Root CMakeLists.txt should have the following content:
cmake_minimum_required(VERSION 2.8.11) # or anything higher, if you wish
project(recognition-node CXX)
add_subdirectory(node)
The CMakeLists.txt under the node directory should have the following content:
add_subdirectory(third_party)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g") # or any other additional flags
# at this point you can add find_package(Qt5Widgets REQUIRED) and later link your binary against Qt5::widgets as well
add_executable(myExec main.cpp
# and put here all the other source files of your project ...
)
# for linking libs I have put additionally highgui and imgproc to check the solution against OpenCV official sample
target_link_libraries(myExec opencv_core opencv_highgui opencv_imgproc)
target_include_directories(myExec PUBLIC
third_party/opencv/modules/calib3d/include
third_party/opencv/modules/core/include
third_party/opencv/modules/cudaarithm/include
third_party/opencv/modules/cudabgsegm/include
third_party/opencv/modules/cudacodec/include
third_party/opencv/modules/cudafeatures2d/include
third_party/opencv/modules/cudafilters/include
third_party/opencv/modules/cudaimgproc/include
third_party/opencv/modules/cudalegacy/include
third_party/opencv/modules/cudaobjdetect/include
third_party/opencv/modules/cudaoptflow/include
third_party/opencv/modules/cudastereo/include
third_party/opencv/modules/cudawarping/include
third_party/opencv/modules/cudev/include
third_party/opencv/modules/dnn/include
third_party/opencv/modules/features2d/include
third_party/opencv/modules/flann/include
third_party/opencv/modules/highgui/include
third_party/opencv/modules/imgcodecs/include
third_party/opencv/modules/imgproc/include
third_party/opencv/modules/ml/include
third_party/opencv/modules/objdetect/include
third_party/opencv/modules/photo/include
third_party/opencv/modules/shape/include
third_party/opencv/modules/stitching/include
third_party/opencv/modules/superres/include
third_party/opencv/modules/ts/include
third_party/opencv/modules/video/include
third_party/opencv/modules/videoio/include
third_party/opencv/modules/videostab/include
third_party/opencv/modules/viz/include
third_party/opencv/modules/world/include
)
The CMakeLists.txt under third_party should contain only:
add_subdirectory(opencv)
# add_subdirectory(dlib) # if you will use dlib, of course also add dlib
The sample I used to verify the build is contours2.cpp (just copy pasted the content into main.cpp).
However, I still think that it is a terrible idea to use this solution.
OpenCv takes really a lot of time to compile
you have to manually add include dirs (you can use some macro generators, but usually it looks even more ugly)
in your build system you have a lot of targets (over 300) that you don't really need, including install target
So, my recommendation is: if you want, use this solution for scientific purpose, but just compile and install OpenCv system-wise (or locally, if you are not the admin) when you really need to use it.
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
I'm trying to learn CMake, but I can't get to grips with the tutorials that are available.
Let's say my project has the structure below, and I want to make my_lib available through its CMakeLists file and use it in my main.cpp, what would my CMakeLists files look like?
├── CMakeLists.txt
├── externals
│ └── my_lib
│ └── src
│ ├── CMakeLists.txt
│ ├── MyClass.h
│ └── MyClass.cpp
└── main.cpp
Should I use include_directories or add_subdirectory?
To match the directory structure you indicated, your CMakeLists.txt files could look like this:
/CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
project(Main)
add_subdirectory(externals/my_lib/src)
add_executable(my_main main.cpp)
target_link_libraries(my_main my_lib)
/externals/my_lib/src/CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
project(MyLib)
add_library(my_lib MyClass.cpp MyClass.h)
target_include_directories(my_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
Using PUBLIC in the target_include_directories call means that not only does your library have this as an "include path", but so does any target linking to it.
The downside with this setup however is that you're also going to expose any internal headers of my_lib to consuming targets too. Say you also have an "Internal.h" as part of my_lib which you don't want to expose. You can do this by moving the intentionally-public headers into a separate folder, e.g. "include":
├── CMakeLists.txt
├── externals
│ └── my_lib
│ ├── CMakeLists.txt
│ ├── include
│ │ └── MyClass.h
│ └── src
│ ├── Internal.h
│ └── MyClass.cpp
└── main.cpp
Your top-level CMakeLists.txt wouldn't change, but /externals/my_lib/CMakeLists.txt (which has moved up a level) now reads:
cmake_minimum_required(VERSION 3.0)
project(MyLib)
add_library(my_lib src/MyClass.cpp src/Internal.h include/MyClass.h)
target_include_directories(my_lib
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
)
Now, since your library's "src" folder is PRIVATE to my_lib, main.cpp won't be able to #include "Internal.h".