I am using cmake to build my project. I have a library, mylibrary, which is a dependency of my project. mylibrary is packaged with conan. I use the conan CMakeDeps and CMakeToolchain Generators when packaging mylibrary. This is the package_info function of mylibrary's conanfile:
def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "config")
self.cpp_info.set_property("cmake_file_name", "Mylibrary")
self.cpp_info.components["libmylibrary"].set_property("cmake_target_name", "Mylibrary::Mylibrary")
self.cpp_info.components["libmylibrary"].libs = ["mylibrary.a"]
self.cpp_info.components["libmylibrary"].requires = ["gtest::gtest"]
My library is a shared library with the file name libmylibrary.a.I can package the library without having any problems. The find_package call in my projects CMakeLists.txt file looks like this:
find_package(Mylibrary REQUIRED HINTS ${LLIB_DIR})
When I build my project, CMake does declare my library's target, which is mylibrary::mylibrary. But right I run cmake, I get this error:
CMake Error at MyProject/cmakedeps_macros.cmake:4 (message):
Library 'mylibrary.a' not found in package. If 'mylibrary.a' is a system library,
declare it with 'cpp_info.system_libs' property
Call Stack (most recent call first):
MyProjectLibs/cmakedeps_macros.cmake:48 (conan_message)
MyProjectLibs/Mylibrary-Target-release.cmake:21 (conan_package_library_targets)
MyProjectLibs/MylibraryTargets.cmake:28 (include)
MyProjectLibs/MylibraryConfig.cmake:11 (include)
CMakeLists.txt:196 (find_package)
I am new to cmake's targets and I don't know what to do. I tried using uppercases or lowercases names when calling find_library, but it is not working. I suspect that I wrote something wrong in the package_info method.
So, I did it. I don't understand why or how, but to solve my problem, I had to change this line:
self.cpp_info.components["libmylibrary"].libs = ["mylibrary.a"]
to this:
self.cpp_info.components["libmylibrary"].libs = ["mylibrary"]
Related
I'm running into a CMake issue that I am a little stumped by. It involves a CMake project that builds dependencies for an application I develop at work. I now have to add a new dependency, libnest2d, which itself also has three dependencies, of which some are also new.
To get libnest2d to build I have this ExternalProject_Add call:
ExternalProject_Add(libnest2d
GIT_REPOSITORY https://github.com/tamasmeszaros/libnest2d.git
GIT_TAG da4782500da4eb8cb6e38e5e3f10164ec5a59778
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
DEPENDS BoostHeaders nlopt Clipper
)
This project depends on the Boost Headers, NLopt and Clipper. Those Boost headers and Clipper are fine, but it somehow complains about NLopt with the following errors:
CMake Error at /usr/share/cmake-3.16/Modules/ExternalProject.cmake:2962 (get_property):
get_property could not find TARGET nlopt. Perhaps it has not yet been
created.
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/ExternalProject.cmake:3239 (_ep_add_configure_command)
projects/libnest2d.cmake:5 (ExternalProject_Add)
CMakeLists.txt:61 (include)
CMake Error at /usr/share/cmake-3.16/Modules/ExternalProject.cmake:2964 (get_property):
get_property could not find TARGET nlopt. Perhaps it has not yet been
created.
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/ExternalProject.cmake:3239 (_ep_add_configure_command)
projects/libnest2d.cmake:5 (ExternalProject_Add)
CMakeLists.txt:61 (include)
CMake Error at /usr/share/cmake-3.16/Modules/ExternalProject.cmake:1783 (get_property):
get_property could not find TARGET nlopt. Perhaps it has not yet been
created.
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/ExternalProject.cmake:2064 (ExternalProject_Get_Property)
/usr/share/cmake-3.16/Modules/ExternalProject.cmake:2966 (_ep_get_step_stampfile)
/usr/share/cmake-3.16/Modules/ExternalProject.cmake:3239 (_ep_add_configure_command)
projects/libnest2d.cmake:5 (ExternalProject_Add)
CMakeLists.txt:61 (include)
CMake Error at /usr/share/cmake-3.16/Modules/ExternalProject.cmake:1785 (message):
External project "nlopt" has no stamp_dir
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/ExternalProject.cmake:2064 (ExternalProject_Get_Property)
/usr/share/cmake-3.16/Modules/ExternalProject.cmake:2966 (_ep_get_step_stampfile)
/usr/share/cmake-3.16/Modules/ExternalProject.cmake:3239 (_ep_add_configure_command)
projects/libnest2d.cmake:5 (ExternalProject_Add)
CMakeLists.txt:61 (include)
So it states that the nlopt target is not defined. However that target is defined using another ExternalProject_Add call, the same as the other two dependencies:
ExternalProject_Add(nlopt
GIT_REPOSITORY https://github.com/stevengj/nlopt.git
GIT_TAG v2.6.2
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)
ExternalProject_Add(BoostHeaders
URL http://sourceforge.net/projects/boost/files/boost/1.67.0/boost_1_67_0.tar.bz2
URL_HASH SHA1=694ae3f4f899d1a80eb7a3b31b33be73c423c1ae
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_BINARY_DIR}/BoostHeaders-prefix/src/BoostHeaders/boost" "${CMAKE_INSTALL_PREFIX}/include/boost"
)
ExternalProject_Add(Clipper
URL https://sourceforge.net/projects/polyclipping/files/clipper_ver6.4.2.zip
URL_HASH SHA1=b05c1f454c22576f867fc633b11337d053e9ea33
SOURCE_SUBDIR cpp
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
)
Without the NLopt dependency, libnest2d builds fine (since I still have the dependency installed on my local system), but there is no guarantee that NLopt is built and installed before starting on libnest2d, and indeed this goes wrong if I execute this build in a VM with multiple threads.
If I temporarily remove the nlopt dependency and call cmake .. && make help then I see that nlopt is one of the available targets. I can also call make nlopt and it starts building NLopt as expected.
You can view my entire source code here: https://github.com/Ultimaker/cura-build-environment/tree/CURA-7259_pynest2d . As of this writing I'm on commit 39298d203d115b60d7093f0a801be1bad0ba7842.
Other problems I've found have not been the same and don't provide a solution for me:
This related question has the same error but it seems to be caused by a tool that OP was using, which I'm not using.
This question and this bug report were a problem with a target that was disabled by a build option, which is not the case for me. The target clearly exists and I made no option to disable it.
There was an old bug that caused this but it was fixed in CMake 2.8. I'm using CMake 3.16.3.
So to summarize, how can I cause the libnest2d external project to depend on NLopt? Why are two dependencies accepted, but one isn't?
Let take /SLAM/vox_ws as package A,
take kimera_semantic_ws as package B,
they are all ROS projects.
If I use CLion to load CMakeLists.txt of the package A in /home/lzw/resplendent_code/SLAM/vox_ws/src/voxgraph/voxgraph/CMakeLists.txt
it will output the error at package B like
CMake Error at /home/lzw/resplendent_code/kimera_semantic_ws/devel/share/catkin_simple/cmake/catkin_simple-extras.cmake:38 (find_package):
By not providing "Findcblox.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "cblox", but
CMake did not find one.
Could not find a package configuration file provided by "cblox" with any of
the following names:
cbloxConfig.cmake
cblox-config.cmake
Add the installation prefix of "cblox" to CMAKE_PREFIX_PATH or set
"cblox_DIR" to a directory containing one of the above files. If "cblox"
provides a separate development package or SDK, be sure it has been
installed.
Call Stack (most recent call first):
CMakeLists.txt:7 (catkin_simple)
-- Configuring incomplete, errors occurred!
See also "/home/lzw/resplendent_code/SLAM/vox_ws/src/voxgraph/voxgraph/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "/home/lzw/resplendent_code/SLAM/vox_ws/src/voxgraph/voxgraph/cmake-build-debug/CMakeFiles/CMakeError.log".
I think it is very weird.
I was able to compile perfectly a code using HDF5 in my computer but now I would like to compile it in a server.
In the server, HDF5 is well installed in the following path:
/usr/local/HDF_Group/HDF5/1.8.17/lib/
But I got this error during the compilation using CMake:
CMake Error at
/usr/local/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:148
(message): Could NOT find HDF5 (missing: HDF5_LIBRARIES
HDF5_INCLUDE_DIRS HDF5_HL_LIBRARIES) Call Stack (most recent call
first):
/usr/local/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:388
(_FPHSA_FAILURE_MESSAGE)
/usr/local/share/cmake-3.6/Modules/FindHDF5.cmake:690
(find_package_handle_standard_args) CMakeLists.txt:4 (FIND_PACKAGE)
-- Configuring incomplete, errors occurred!
The beginning of my CMakeList.txt
FIND_PACKAGE(HDF5 REQUIRED)
find_package (HDF5 NAMES hdf5 COMPONENTS C static)
INCLUDE_DIRECTORIES
(${HDF5_INCLUDE_DIR}) message(STATUS ${HDF5_INCLUDE_DIR})
set (LINK_LIBS ${LINK_LIBS} ${HDF5_C_STATIC_LIBRARY})
include_directories(/usr/local/HDF_Group/)
link_directories(/usr/local/HDF_Group/HDF5/1.8.17/lib/)
link_directories(/usr/local/lib)
Could you please help me ?As I'm not well familiar with CMake, Maybe I did not link it properly...
Thank in advance,
EDIT: SOLVED
I solved my issue by doing this:
export HDF5_DIR=/usr/local/HDF_Group/HDF5/1.8.17/share/cmake
And I added it into my /home/user/.bashrc so that I don't have to do this command line each time.
I'm using LLVM/Clang in my C++ project. I can build and run everything fine with a Makefile.
I'm now trying to move to Cmake and I can't get things to work. Let me explain what I've done.
I'm following this tutorial:
http://llvm.org/docs/CMake.html#embedding
A relevant snippet from that webpage is:
From LLVM 3.5 onwards both the CMake and autoconf/Makefile build
systems export LLVM libraries as importable CMake targets.
Great! I'll go download LLVM 3.5 and I should be good to go. I went to the download page:
http://llvm.org/releases/download.html
and downloaded the pre-built binaries for Clang for Ubuntu 14.04 Linux.
Then, I added the following to my CMakeLists.txt file:
find_path (LLVM_DIR LLVM-Config.cmake
/home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake
)
message(STATUS "LLVM_DIR = ${LLVM_DIR}")
find_package(LLVM REQUIRED CONFIG)
(This is the same as the tutorial, except I set LLVM_DIR since it is currently in a non-standard location.)
When I run cmake, I get the following error:
[dev#beauty:/path/to/project/build (develop)] $ cmake ..
-- LLVM_DIR = /home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake
CMake Error at /home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake/LLVMConfig.cmake:50 (include):
include could not find load file:
/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/share/llvm/cmake/LLVMExports.cmake
Call Stack (most recent call first):
CMakeLists.txt:14 (find_package)
CMake Error at /home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake/LLVMConfig.cmake:53 (include):
include could not find load file:
/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/share/llvm/cmake/LLVM-Config.cmake
Call Stack (most recent call first):
CMakeLists.txt:14 (find_package)
So Cmake seems to be finding LLVM's Cmake file, but Cmake is complaining about some path starting with /home/ben/.
Indeed, it appears that LLVM's LLVMConfig.cmake file has some absolute paths in it that are not relevant for my machine. For example:
[dev#beauty:~/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu ] $ head ./share/llvm/cmake/LLVMConfig.cmake
# This file provides information and services to the final user.
set(LLVM_INSTALL_PREFIX "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install")
set(LLVM_VERSION_MAJOR 3)
set(LLVM_VERSION_MINOR 5)
set(LLVM_VERSION_PATCH 0)
set(LLVM_PACKAGE_VERSION 3.5.0)
set(LLVM_COMMON_DEPENDS )
Who's ben and what's he doing in this file? He shows up in a few more places:
[dev#beauty:~/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu ] $ grep ben ./share/llvm/cmake/LLVMConfig.cmake
set(LLVM_INSTALL_PREFIX "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install")
set(LLVM_INCLUDE_DIRS "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/include")
set(LLVM_LIBRARY_DIRS "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/lib")
set(LLVM_CMAKE_DIR "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/share/llvm/cmake")
set(LLVM_TOOLS_BINARY_DIR "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/bin")
Needless to say, those paths do not exist on my machine. I'm confused as to why these files have these paths in them? Am I supposed to run a tool or something to change these paths for my machine? Or do I need to change them all manually?
EDIT: Out of curiosity, I manually changed all those paths to point to paths on my machine:
[dev#beauty:~/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake ] $ sed -i -e's/.home.ben.development.llvm.3.5.final.Phase3.Release.llvmCore-3.5.0-final.install/\/home\/dev\/Downloads\/clang+llvm-3.5.0-x86_64-linux-gnu/g' *
After that, Cmake no longer complained and my build proceeded.
I'd still like to know why I needed to do that.
Sounds like a LLVM bug. Feel free to enter it: http://llvm.org/bugs
We just have to build with 'Ninja' instead of 'Unix Makefiles' and that's all
I get the following error:
CMake Error at cmake/OpenCVModule.cmake:232 (add_subdirectory):
add_subdirectory given source "C:/dev/opencv/modules/ascend" which is not
an existing directory.
Call Stack (most recent call first):
modules/CMakeLists.txt:7 (ocv_glob_modules)
where i created teh module as a symbolic link
C:\WINDOWS\system32>mklink /D "C:\dev\opencv\modules\ascend" "C:\dev\AscendProje
cts\AscendPipeline\opencv_ascend"
symbolic link created for C:\dev\opencv\modules\ascend <<===>> C:\dev\AscendProj
ects\AscendPipeline\opencv_ascend
is it not possible to work around this in some way?
OpenCV CMake script has OPENCV_EXTRA_MODULES_PATH option, which allows to set path to optinal modules. You don't have to create sumbolic links:
cd <opencv_build_directory>
cmake -DOPENCV_EXTRA_MODULES_PATH=C:\dev\AscendProjects\AscendPipeline .