I have tried for a day to try and resolve issues with the cmake when trying to build a project using the zeromq library. I appreciate that there have been several threads on this question in the past, but none seem to explain the fix in any detail. I've exhausted my knowledge regarding how to solve this one and would appreciate an explanation as to what I need to do.
Below is the following error message from the project cmake command issued inside CLion.
The cmake Error occurs at line 1 of vcpkg-cmake-wrapper.cmake proving that it was found.
Could not find a package configuration file provided by "zeromq" with
any of the following names:
zeromqConfig.cmake
zeromq-config.cmake
Add the installation prefix of "zeromq" to CMAKE_PREFIX_PATH or set
"zeromq_DIR" to a directory containing one of the above files. If "zeromq"
provides a separate development package or SDK, be sure it has been
installed.
Where does this package config file go and what is in it? What is meant by adding the installation prefix to CMAKE_PREFIX_PATH?
I installed zeromq using vcpkg. The output from vcpkg list is
cppzmq:x64-linux 4.8.1#1 Header-only C++ binding for ZeroMQ
zeromq:x64-linux 4.3.4#6 The ZeroMQ lightweight messaging kernel is a lib...
So to me this looks like the library downloaded, built and installed correctly.
My cmake toolchain options are:
-DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake
/vcpkg/installed/x64-linux/share/zeromq/vcpkg-cmake-wrapper.cmake:1
CMakeLists.txt is:
cmake_minimum_required(VERSION 3.24.0)
project(Template VERSION 1.0.0)
add_executable(template src/main.cpp)
find_package(zeromq CONFIG REQUIRED)
find_package(cppzmq CONFIG REQUIRED)
target_compile_features(Template PRIVATE cxx_std_17)
target_link_libraries(main
PRIVATE
zeromq::zeromq
cppzmq::cppzmq)
This is currently an empty project until I get cmake process to resolve the library
I have tried to understand by following the example on: https://vcpkg.readthedocs.io/en/latest/examples/manifest-mode-cmake/ From this I can successfully build and create an executable.
Thanks Tsyvarev. I achieved an error free CMake by changing my CMakeLists.txt to:
cmake_minimum_required(VERSION 3.24.0)
project(Template VERSION 1.0.0)
#set(zeromq_DIR "~/usr/local/lib/cmake/ZeroMQ")
add_executable(Template src/main.cpp)
find_package(ZeroMQ CONFIG REQUIRED)
target_compile_features(Template PRIVATE cxx_std_17)
target_link_libraries(Template
PRIVATE
ZeroMQ)
Related
I have to do a project using CMake and the CGAL geometry library but, regardless having tried everything I can find online, I still can't figure out how to configure my project in CMake. I have installed all the libraries CGAL depends on and qt5 but CMake keeps giving me errors when I try to configure and generate. I am almost a beginner so any kind of help would be very useful. I am using windows 10 and visual studio 2019. Following are the errors it's giving me.
CMake Warning at CMakeLists.txt:5 (find_package): By not providing "FindCGAL.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "CGAL", but CMake did not find one.
Could not find a package configuration file provided by "CGAL" with any of the following names:
CGALConfig.cmake
cgal-config.cmake
Add the installation prefix of "CGAL" to CMAKE_PREFIX_PATH or set "CGAL_DIR" to a directory containing one of the above files. If "CGAL" provides a separate development package or SDK, be sure it has been installed.
CMakeLists.txt
cmake_minimum_required(VERSION "3.22.0-rc2")
project("TesiLaurea")
find_package(CGAL)
add_executable("${PROJECT_NAME}" "Main.cpp")
target_link_libraries("${PROJECT_NAME}" CGAL::CGAL)
I have git cloned, built (with MSVC for both Debug and Release) and then installed wxWidgets:
cmake -B build wxWidgets
cmake --build build --config <CONFIG>
cmake --install build --prefix my_install --config <CONFIG>
with <CONFIG> = Debug and <CONFIG> = Release.
Then I used the following CMake script to link against it, as suggested by the wiki:
cmake_minimum_required(VERSION 3.16)
project(Test)
add_executable(Test WIN32 Main.cpp)
# wxWidgets
SET(wxWidgets_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../thirdparty/my_install)
find_package(wxWidgets COMPONENTS core base REQUIRED)
include(${wxWidgets_USE_FILE})
target_link_libraries(Test PRIVATE ${wxWidgets_LIBRARIES})
# Copy runtime DLLs to the directory of the executable.
add_custom_command(TARGET Test POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Runtime Dlls: $<TARGET_RUNTIME_DLLS:Test>"
)
My goal is to automatically copy the DLLs into the directory of the built executable, so that they can be found at runtime. For that I'm using the TARGET_RUNTIME_DLLS generator expression (follwing the sample code in the docs). In the code above, I only print out the expression at build time for testing purposes. The problem is that it is empty.
The approach worked for me before when installing and linking SDL, but SDL provides package configuration files which create imported targets, defining the DLL location(s) via IMPORTED_LOCATION_RELEASE or IMPORTED_LOCATION_DEBUG. For wxWidgets one is apparently supposed to use the FindwxWidgets.cmake script shipped with CMake, which sadly doesn't define the produced binaries. Maybe that's why TARGET_RUNTIME_DLLS isn't populated.
Does anyone know, either how to get TARGET_RUNTIME_DLLS filled or how to obtain the list of built wxWidgets DLLs for the current configuration (Release/Debug) post build copying?
Thanks a lot in advance!
I am dealing with a similar problem.
First sanity checks:
You have to work on windows platform otherwise this feature does not
work.
Your Cmake is 3.21 or above
Next comes fuzzy part. I think the library that you are trying to include have to be a Shared Imported library and you have to set a set_target_properties for IMPORTED_IMPLIB which is a path to a .lib file of sort (dll import library, I think it is called) So you have to make sure that it is all set in the package library that you trying to link with your executable.
If you have those dll avaiable and you just want to use them and not actually build them then you can write your own cmake script that will do just what I said above. Then you can include that cmake file in your project and then link against your app.
Note: I also work on similar issue right now and what I just said have not been working very reliably. I got some dlls to be copied and some do not.
Edit:
Cmake docs give a more detailed explanation on how this library setting should look like if you use find_package feature.
Found here: https://cmake.org/cmake/help/latest/command/add_library.html#imported-libraries
An UNKNOWN library type is typically only used in the implementation
of Find Modules. It allows the path to an imported library (often
found using the find_library() command) to be used without having to
know what type of library it is. This is especially useful on Windows
where a static library and a DLL's import library both have the same
file extension.
I am struggling with the following issue and I really wish someone could provide me with helpful tips.
When building my C++ application based on Qt5.8 using CMake 3.8.2, I got the following error during the "generate" step:
CMake Error at ntActions/ntActionsITK/CMakeLists.txt:81 (ADD_LIBRARY):
Target "ntActionsITK" links to target "Qt5::X11Extras" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
These are the two lines of my CMakeLists, where the issue is arising:
80 - ADD_DEFINITIONS(-DQT_GUI_LIBS -DQT_CORE_LIB -DQT3_SUPPORT)
81 - ADD_LIBRARY(ntActions ${ntActionsGUI_SRCS} ${ntActions_GUI}
My PATH variable includes QT5.8 install path (lib, lib/CMake, bin, include).
CMake is able to automatically find all Qt5 packages I am using, including Qt5X11Extras.
Am I missing something?
My dev env. is the following: Debian 8, Qt(5.8), CMake(3.8.2)
Any help will be appreciated
Thanks
Bouba
ADD: qt5Setup.cmake file
Hi Tsyvarev, thanks for your feedback. I have a qt5Setup.cmake file to setup Qt5, as follows:
find_package(Qt5 COMPONENTS Core Widgets Gui Network Concurrent OpenGL
Svg PrintSupport Sql SerialPort MultimediaWidgets X11Extras)
IF(QT_USE_FILE)
INCLUDE(${QT_USE_FILE})
ENDIF(QT_USE_FILE)
include_directories(
${Qt5Core_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Network_INCLUDE_DIRS}
${Qt5OpenGL_INCLUDE_DIRS}
${Qt5Svg_INCLUDE_DIRS}
${Qt5Concurrent_INCLUDE_DIRS}
${Qt5PrintSupport_INCLUDE_DIRS}
${Qt5Sql_INCLUDE_DIRS}
${QtSerialPort_INCLUDE_DIRS}
${Qt5MultimediaWidgets_INCLUDE_DIRS}
${Qt5X11Extras_INCLUDE_DIRS})
LINK_LIBRARIES(
${Qt5Svg_LIBRARIES}
${Qt5Network_LIBRARIES}
${Qt5Widget_LIBRARIES}
${Qt5Sql_LIBRARIES}
${QtSerialPort_LIBRARIES}
${Qt5MultimediaWidgets_LIBRARIES}
${Qt5PrintSupport_LIBRARIES}
${Qt5X11Extras_LIBRARIES})
I am working on a larger C++ library that is using CMake and depends on Qt.
We moved from Qt4 to Qt5 and now I encounter a problem when using our lib
in an upstream project. As a minimal working example demonstrating the problem please have a look at this repo:
https://github.com/philthiel/cmake_qt5_upstream
It contains two separate CMake projects:
MyLIB: a tiny library that uses QString from Qt5::Core.
It generates and installs package configuration files
MyLIBConfig.cmake, MyLIBConfigVersion.cmake, and MyLIBTargets.cmake
in order to be searchable by CMake find_package()
MyAPP: a tiny executable depending on MyLIB
The project uses find_package(MyLIB) and creates an executable that uses MyLIB
The problem is that CMake gives me the following error message when configuring the MyAPP project:
CMake Error at CMakeLists.txt:11 (add_executable):
Target "MyAPP" links to target "Qt5::Core" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?
The reason for this behaviour is that in the automatically generated MyLIBTargets.cmake file the INTERFACE_LINK_LIBRARIES entry for Qt5 Core is the Qt5::Core symbol. Using Qt4, the absolute path to the Qt core lib was specified here.
Now, I simply can resolve this by using
find_package(Qt5Core 5.X REQUIRED)
in the MyAPP project.
However, I would like to know if this is the intended/generic way to go, i.e. requesting upstream projects of our lib to search for the required transitive Qt5 dependencies themselves, or if I probably misuse CMake here and need to change my configuration procedure?
The CMake docu on package file generation
https://cmake.org/cmake/help/v3.0/manual/cmake-packages.7.html
mentions that macros can be provided by the package configuration files to upstream. Maybe this would be the correct place to search for imported targets like Qt5 and break upstream configuration runs when these dependencies are not found?
Best,
Philipp
[edit of the edit] Full Source Example
You need to deliver a CMake config file for your project, and probably the ConfigFile should be generated via CMake itself (because you cannot know for shure where the user will install your software).
Tip, use the ECM cmake modules to ease the creation of that:
find_package(ECM REQUIRED NO_MODULE)
include(CMakePackageConfigHelpers)
ecm_setup_version(${PROJECT_VERSION}
VARIABLE_PREFIX ATCORE
VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/atcore_version.h"
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5AtCoreConfigVersion.cmake"
SOVERSION 1
)
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/KF5AtCoreConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/KF5AtCoreConfig.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)
and the KF5AtCoreConfig.cmake.in:
#PACKAGE_INIT#
find_dependency(Qt5Widgets "#REQUIRED_QT_VERSION#")
find_dependency(Qt5SerialPort "#REQUIRED_QT_VERSION#")
find_dependency(KF5Solid "#KF5_DEP_VERSION#")
include("${CMAKE_CURRENT_LIST_DIR}/KF5AtCoreTargets.cmake")
This will generate the correct FindYourSortware.cmake with all your dependencies.
[edit] Better explanation on what's going on.
If you are providing a library that will use Qt, and that would also need to find the Qt5 library before compilling the user's source, you need to provide yourself a FindYourLibrary.cmake code, that would call
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Whatever)
Now, if it's your executable that needs to be linked, use the Components instead of the way you are doing it now.
find_package(Qt5 REQUIRED COMPONENTS Core)
then you link your library with
target_link_libraries(YourTarget Qt5::Core)
I installed Ogre3D 1.8.1 (the source package) on Ubuntu 12.04 and everything went fine (I managed to run some samples on the Ogre interface). However, I hit a problem while I was compiling an external project (that one) that needed the OpenCV, ArUco and Ogre librarys. When I run the CMake of the project, I receive the following:
CMake Error at CMakeLists.txt:46 (find_package):
By not providing "FindOGRE.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "OGRE", but
CMake did not find one.
Could not find a package configuration file provided by "OGRE" with any of
the following names:
OGREConfig.cmake
ogre-config.cmake
Add the installation prefix of "OGRE" to CMAKE_PREFIX_PATH or set
"OGRE_DIR" to a directory containing one of the above files. If "OGRE"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
I know where the FindOGRE.cmake is, it's in the /usr/local/lib/OGRE/cmake, but I don't know how to say to CMake to look for that folder and fix this problem.
You just need to use the -D command line option along with the CMAKE_MODULE_PATH variable:
cmake . -DCMAKE_MODULE_PATH=/usr/local/lib/OGRE/cmake
Just for the record, an alternative solution would be to add the module path directly in the CMakeLists.txt. For example (tested on Debian 9):
set(CMAKE_MODULE_PATH "/usr/share/OGRE/cmake/modules/;${CMAKE_MODULE_PATH}")
Just make sure to add the line before find_package is called.
For me, it only works to set the following in CMakeLists.txt before find_package:
set(OGRE_DIR /usr/share/OGRE/build/sdk/CMake)
Note that the CMake directory is the one containing OGREConfig.cmake. For some reason, my CMake ignores CMAKE_MODULE_PATH.
Maybe, of some help for someone
For me, this solution work on manjaro:
set(CMAKE_MODULE_PATH "/usr/lib/OGRE/cmake;${CMAKE_MODULE_PATH}")
find_package(OGRE QUIET)
if (OGRE_FOUND)
include_directories( ${ogre_INCLUDE_DIR})
link_directories(${OGRE_LIBRARIES})
message(STATUS "OGRE: FOUND")
else()
message(STATUS "OGRE: NOT FOUND")
endif()