I'm trying to build and use a local version of Eigen that I've downloaded directly from the CMake file of my project. I have those line to build it:
include(FetchContent)
FetchContent_Declare(
eigen
URL ${CMAKE_CURRENT_SOURCE_DIR}/external/eigen-3.3.8.tar.gz
)
FetchContent_MakeAvailable(eigen)
set(EIGEN3_INCLUDE_DIR ${eigen_SOURCE_DIR})
But then I got errors like
Target "XXX_LIBRARIES" links to target "Eigen3::Eigen" but the target was
not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
I'm linhking eigen as such
target_link_libraries(XXX_LIBRARIES EXTERNAL_LIBRARIES Eigen3::Eigen)
What is surprising to me is that with this code instead everything worked fine:
include(FetchContent)
FetchContent_Declare(
eigen
GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git
)
FetchContent_MakeAvailable(eigen)
set(EIGEN3_INCLUDE_DIR ${eigen_SOURCE_DIR})
But the only difference is that I'm downloading the library then. Why is the version with the local copy not working?
Related
I am trying to use python to interfacing my own c++ library. Actually I can do it manually copying pybind11_example.so to the target device. I hope to do this by using install(TARGETS...
I found this link. But it doesn't help in my Yocto build.
This is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.14.4)
project(pybind11_example)
set(CMAKE_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../lib/math/include")
find_package(PythonLibs REQUIRED)
set(PYTHON_MODULE_EXTENSION ".so" CACHE INTERNAL "Cross python lib extension")
find_package(pybind11 REQUIRED)
pybind11_add_module(${PROJECT_NAME} pybind11_wrapper.cpp)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_INCLUDE_PATH})
target_link_libraries(${PROJECT_NAME} PRIVATE simplemath)
include(GNUInstallDirs)
# without lines below, yocto build works fine
install(TARGETS ${PROJECT_NAME}
COMPONENT python
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
This is the error from devtool build:
ERROR: pybind11-example-1.0+git999-r0 do_package: QA Issue: pybind11-example: Files/directories were installed but not shipped in any package:
/usr/lib/pybind11_example.so
Please set FILES such that these items are packaged. Alternatively if they are unneeded, avoid installing them or delete them within do_install.
pybind11-example: 1 installed and not shipped files. [installed-vs-shipped]
ERROR: pybind11-example-1.0+git999-r0 do_package: Fatal QA errors found, failing task.
Oops, I found the reason. The problem was not in cmake but in .bb file.
After I add FILES_${PN} += "/usr/lib" in the .bb, it works fine.
For more detail, please see this link.
I have troubles finding out the right "library target name" to be used in a cmake file, for packages installed using vcpkg.
In example, I installed the gtest package using vcpkg install gtest. My sample cmake file looks like:
#CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(example)
add_executable(main main.cpp)
find_package(gtest REQUIRED)
target_link_libraries(main gtest) # here, "gtest" is not the right name!
Running cmake, a solution for Visual Studio is generated, but after running cmake --build ., I get the error:
../use-cmake-vcpkg\main.cpp(1): fatal error C1083: Cannot open include file: 'gtest/gtest.h': No such file or directory ..
Turns out the line: target_link_libraries(main gtest) isn't correct, and I need to use another "name" to include/link the gtest package.
Is there a way (using cmake or vcpkg) to find out what is the correct target name to be used? (for gtest in this case, but also for any other pacakage?)
When use find_package(XXX), it can work in two modes: MODULE and CONFIG. And resulted variables and targets of this call depend on the mode.
If FindXXX.cmake file exists (and can be found), the MODULE mode is used and given file is processed. Otherwise, if the package is shipped with XXXConfig.cmake file, CONFIG mode is used and given file is processed. If none of this file exists, CMake emits an error (if called with REQUIRED keyword) or a warning (without REQUIRED keyword).
In case of gtest package, CMake is shipped with FindXXX.cmake script, so this script is processed in MODULE mode. You may find description of this script in the documentation, which tells that you need to use GTest::GTest target for link with gtest:
target_link_libraries(main GTest::GTest)
Not all packages provide a CMake library definition. If you're lucky, then vcpkg install will show you the name:
$ ./vcpkg install openssl
The package openssl is compatible with built-in CMake targets:
find_package(OpenSSL REQUIRED)
target_link_libraries(main PRIVATE OpenSSL::SSL OpenSSL::Crypto)
This will work even if you've already installed the package, so you can use it anytime to query the package name.
On the other hand, if vcpkg install <pkg> doesn't say anything about CMake, then you need to include it manually in your CMake file, by finding the include path and the library files.
Here is an example of such a case, here for the live555 library:
# Use one of the headers to locate the include location
find_path(LIVE555_INCLUDE_DIR liveMedia.hh)
# Find the libraries
find_library(LIVE555_LIBRARY1 liveMedia)
find_library(LIVE555_LIBRARY2 groupsock)
find_library(LIVE555_LIBRARY3 BasicUsageEnvironment)
find_library(LIVE555_LIBRARY4 UsageEnvironment)
add_executable(rtsp testRTSPClient.cpp)
target_include_directories(rtsp PRIVATE ${LIVE555_INCLUDE_DIR})
target_link_libraries(rtsp PRIVATE ${LIVE555_LIBRARY1} ${LIVE555_LIBRARY2} ${LIVE555_LIBRARY3} ${LIVE555_LIBRARY4})
I'm building a target that depends on some provided libraries. My src directory hierarchy looks like this:
I use the following CMakeLists.txt to build a target and install it within the build/install directory:
cmake_minimum_required(VERSION 2.8.3)
project(example)
include_directories(include)
link_directories(lib)
add_executable(${PROJECT_NAME}
src/example.cpp)
target_link_libraries(${PROJECT_NAME}
curlpp)
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/install)
install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)
install(FILES lib/libcurlpp.a lib/libcurlpp.so lib/libcurlpp.so.1 lib/libcurlpp.so.1.0.0 DESTINATION deps)
When I do a simple build, everything is fine and the target is properly linked to the provided libraries. But when I do make install, the target is generated but fails to link to the libraries:
I understand the linkage failure of the installed target: the install/deps directory is not in the LD_LIBRARY_PATH of my environment. But what has cmake done to make the directly built target link correctly? Can I do something similar to make the installed target work properly?
Here is a minimal replication of the problem
When trying to compile my project using cmake ., variable CMAKE_INSTALL_LIBDIR is empty and I have no idea why.
I'm trying to issue the following (on line 40):
install(TARGETS fpthread
EXPORT fpthread_config
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
I get the following error message:
CMake Error at CMakeLists.txt:40 (install):
install TARGETS given no LIBRARY DESTINATION for shared library target
"fpthread".
Issuing the following results in an empty string:
MESSAGE(STATUS ${CMAKE_INSTALL_LIBDIR})
I've tried both Cmake 3.5 (installed through package manager) and Cmake 3.11 (latest release, compiled from source).
Reformulating my previous comment as answer:
To access variables from the GNUInstallDirs module you need to add
include(GNUInstallDirs)
to your CMakeLists.txt file. The module is not included by default.
I am trying to compile the source code of Tesseract Open Source OCR Engine (https://github.com/tesseract-ocr/tesseract).
But when running cmake, I always get the following error:
CMake Error: The following variables are used in this project, but
they are set to NOTFOUND. Please set them or make sure they are set
and tested correctly in the CMake files: leptonica_OUTPUT_NAME
linked by target "libtesseract" in directory /home/test/github/tesseract
I have already downloaded the source code of leptonica (http://www.leptonica.com/download.html) and installed it.
I am wondering which value should I set to leptonica_OUTPUT_NAME.
I ran into the same problem. It seems that
find_package(PkgConfig REQUIRED)
pkg_check_modules(Leptonica REQUIRED lept>=${MINIMUM_LEPTONICA_VERSION})
in CMakeLists.txt has problems finding leptonica whereas cmake's find_package just works fine:
if(NOT EXISTS ${PROJECT_SOURCE_DIR}/.cppan)
# if (NOT Leptonica_DIR AND NOT MSVC)
# find_package(PkgConfig REQUIRED)
# pkg_check_modules(Leptonica REQUIRED lept>=${MINIMUM_LEPTONICA_VERSION})
# else()
find_package(Leptonica ${MINIMUM_LEPTONICA_VERSION} REQUIRED CONFIG)
# endif()
else()
For completeness (both compiled from sources):
tesseract 4.00.00alpha
leptonica-1.74.4