I have been trying to build, and correctly set up Cmake with SFML using find_package + SFMLConfig.cmake.
Cmake correctly finds a configuration file (along with ConfigDependencies, ConfigVersion, ConfigSharedTargets) at default linux install location per the SFML compilation instructions:
/usr/local/lib/cmake/sfml
However at that path there is no shared library files (.so).
all of them (audio, graphics, network, system and window) are all the way up at:
/usr/local/lib
So i believe i have correctly built and "installed" SFML with make.
I get this error message (for all four components):
CMake Error at /usr/local/lib/cmake/SFML/SFMLConfig.cmake:150 (message):
Found SFML but requested component 'audio' is missing in the config defined in /usr/local/lib/cmake/SFML.
Call Stack (most recent call first):
CMakeLists.txt:17 (find_package)
CMake Error at CMakeLists.txt:17 (find_package): Found package configuration file:
/usr/local/lib/cmake/SFML/SFMLConfig.cmake
but it set SFML_FOUND to FALSE so package "SFML" is considered to be NOT FOUND.
I have tried to set the SFML_DIR variable in my CMakeLists.txt to many different places, both where i store SFML source (where i git cloned), where i built in to SFML-build. and where it is installed.
Why are the components missing? Should i copy the .so files into where the SFMLConfig.cmake file is? Should i move the SFMLConfig.cmake and update CMAKE_MODULE_PATH to a new path?
Looking into the SFMLConfig.cmake i see that the last if and elseif Statements in the code below is the one that fails. Meaning
TARGET SFML::${component} evaluates false. But I'm not sure what that means.
#SFMLConfig.cmake
foreach(component ${SFML_FIND_COMPONENTS})
string(TOUPPER "${component}" UPPER_COMPONENT)
list(APPEND FIND_SFML_ADDITIONAL_COMPONENTS ${FIND_SFML_${UPPER_COMPONENT}_DEPENDENCIES})
endforeach()
list(APPEND SFML_FIND_COMPONENTS ${FIND_SFML_ADDITIONAL_COMPONENTS})
list(REMOVE_DUPLICATES SFML_FIND_COMPONENTS)
[...]
foreach (component ${SFML_FIND_COMPONENTS})
string(TOUPPER "${component}" UPPER_COMPONENT)
set(SFML_${UPPER_COMPONENT}_FOUND FALSE)
if (TARGET SFML::${component})
set(SFML_${UPPER_COMPONENT}_FOUND TRUE)
elseif(SFML_FIND_REQUIRED_${component})
set(FIND_SFML_ERROR "Found SFML but requested component '${component}' is missing in the config defined in ${SFML_DIR}.")
set(SFML_FOUND FALSE)
endif()
endforeach()
This is my top CMakeLists.txt file:
set(CMAKE_MODULE_PATH "/usr/local/lib/cmake/SFML") # tell cmake where to find find.cmake and config.cmake files
set(SFML_DIR "/usr/local/lib")
find_package(SFML COMPONENTS graphics window system audio REQUIRED) # Look for SFML
Related
I try to create an automated build of Scram (CI yaml file, CMakeLists.txt) for Windows. The project uses CMake to create the build files. Building of the project worked already, but the runtime libraries of libxml and boost get not bundled into the package.
As compiler mingw64 is used.
Libxml2 will be installed by the CI in a previous step and the install prefix is passed to the scram cmake.
In the CMakeLists.txt libxml is included as:
find_package(LibXml2 REQUIRED)
1
I tried then to install the libxmllibraries as:
install(FILES ${LIBXML2_LIBRARIES} DESTINATION bin)
The problem is that LIBXML2_LIBRARIES points to the .dll.a files in the libxml2_install_prefix/lib and not to the .dll files in the libxml2_install_prefix/bin folder. So only the .dll.a files are bundled into the exe and therefore the application does not work.
2
get_target_property(LIB_XML2_RUNTIME_OUTPUT_DIRECTORY LibXml2::LibXml2 RUNTIME_OUTPUT_DIRECTORY)
get_target_property(LIB_XML2_RUNTIME_OUTPUT_NAME LibXml2::LibXml2 RUNTIME_OUTPUT_NAME)
message(STATUS "XX LIB_XML2_RUNTIME_OUTPUT_DIRECTORY: ${LIB_XML2_RUNTIME_OUTPUT_DIRECTORY}")
message(STATUS "XX LIB_XML2_RUNTIME_OUTPUT_NAME: ${LIB_XML2_RUNTIME_OUTPUT_NAME}")
install (FILES
${LIBXML2_LIBRARIES}
"${LIB_XML2_RUNTIME_OUTPUT_DIRECTORY}/${LIB_XML2_RUNTIME_OUTPUT_NAME}"
DESTINATION bin
COMPONENT libraries)
In this case LIB_XML2_RUNTIME_OUTPUT_NAME and LIB_XML2_RUNTIME_OUTPUT_DIRECTORY are "-NOT_FOUND"
This seems to be a problem because cmake does not know the runtime directory for imported targets (
3
I tried than also install(IMPORTED_RUNTIME_ARTIFACTS LibXml2::LibXml2) which failed with: install IMPORTED_RUNTIME_ARTIFACTS given target "LibXml2::LibXml2" which is not an executable, library, or module.
Also described here: CMake Gitlab repository
4
install(TARGETS LibXml2::LibXml2 RUNTIME_DEPENDENCIES)
failed with the following message: install TARGETS given target "LibXml2::LibXml2" which does not exist.
From CMake Docu:
Note: Imported Targets are supported only if they know the location of their .dll files. An imported SHARED or MODULE library must have IMPORTED_LOCATION set to its .dll file. See the add_library imported libraries section for details. Many Find Modules produce imported targets with the UNKNOWN type and therefore will be ignored.
Probably LibXml2 is imported as unknown and therefore there is no DLL path specified. How to come around this issue and installing the dlls?
5
I tried
install(FILES $<TARGET_RUNTIME_DLLS:LibXml2::LibXml2> DESTINATION bin COMPONENT libraries)
but here I get the error message:
Objects of target "LibXml2::LibXml2" referenced but is not one of the allowed target types (EXECUTABLE, SHARED, MODULE).. Probably because the target is imported and not created by this cmake
6
get_target_property(libxml2_imported_location LibXml2::LibXml2 IMPORTED_LOCATION) points also to the .dll.a file
7 Working Hack (Ugly)
Find out where the .dll is located. For libXml2 it is in the bin folder, for boost it is in the same folder as the .dll.a
Use the imported location and replace the path to match the path to the .dll
get_target_property(libxml2_imported_location LibXml2::LibXml2 IMPORTED_LOCATION)
string(REPLACE "/lib/" "/bin/" libxml2_imported_location ${libxml2_imported_location})
string(REPLACE ".dll.a" ".dll" libxml2_imported_location ${libxml2_imported_location})
message(STATUS "XX libxml2_imported_location3 ${libxml2_imported_location}")
install(FILES ${libxml2_imported_location} DESTINATION bin COMPONENT libraries)
I try to add a library ( PCL ) to my cmake, but it throws following error when trying to build:
C/C++ debug|armeabi-v7a : CMake Error at C:\Users\xxx\ndktest\app\src\main\cpp\CMakeLists.txt:48 (find_package):
By not providing "FindPCL.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "PCL", but
CMake did not find one.
Could not find a package configuration file provided by "PCL" (requested
version 1.3) with any of the following names:
PCLConfig.cmake
pcl-config.cmake
Add the installation prefix of "PCL" to CMAKE_PREFIX_PATH or set "PCL_DIR"
to a directory containing one of the above files. If "PCL" provides a
separate development package or SDK, be sure it has been installed.
Here is how my cmake looks like (I tried setting PLC_DIR already and still have same error message):
cmake_minimum_required(VERSION 3.4.1)
add_library( native-lib SHARED native-lib.cpp )
find_library(log-lib log )
target_link_libraries(native-lib ${log-lib} )
set(PCL_DIR "C:\\Program Files\\PCL 1.6.0\\cmake\\PCLConfig.cmake")
find_package(PCL 1.3 REQUIRED COMPONENTS common io)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(pcd_write_test pcd_write.cpp)
target_link_libraries(pcd_write_test ${PCL_LIBRARIES})
Im running windows 10, and trying to include PCL into a Android project
Any suggestions why its not finding pcl library?
EDIT: I used vcpkg to install the library PCL, and I noticed i was pointing to wrong PCL library. Now I am pointing to the PCL library installed with vcpkg and my CMAKE looks like this now:
cmake_minimum_required(VERSION 3.4.1)
add_library( native-lib SHARED native-lib.cpp )
find_library(log-lib log )
target_link_libraries(native-lib ${log-lib} )
set(PCL_DIR "C:\\Users\\xxx\\Desktop\\pclndk\\vcpkg\\packages\\pcl_x86-windows\\share\\pcl")
find_package(PCL 1.3 REQUIRED COMPONENTS)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(pcd_write_test pcd_write.cpp)
target_link_libraries(pcd_write_test ${PCL_LIBRARIES})
When I run this, the error message changes (guess it found PCL but not being able to find a required library (Eigen) for pcl):
C:\Users\xxx\ndktest\app\src\main\cpp\CMakeLists.txt : C/C++ debug|armeabi-v7a : CMake Error at C:/Users/xxx/Desktop/pclndk/vcpkg/packages/pcl_x86-windows/share/pcl/PCLConfig.cmake:56 (message):
common is required but eigen was not found
Call Stack (most recent call first):
C:/Users/xxx/Desktop/pclndk/vcpkg/packages/pcl_x86-windows/share/pcl/PCLConfig.cmake:356 (pcl_report_not_found)
C:/Users/xxx/Desktop/pclndk/vcpkg/packages/pcl_x86-windows/share/pcl/PCLConfig.cmake:524 (find_external_library)
CMakeLists.txt:10 (find_package)
I've tried adding set(EIGEN_DIR "C:\\Users\\xxx\\Desktop\\pclndk\\vcpkg\\installed\\x86-windows\\share\\eigen3")
or set(EIGEN_DIR "C:\\Users\\xxx\\Desktop\\pclndk\\vcpkg\\installed\\x86-windows\\share\\eigen3"), but it will still show same error message common is required but eigen was not found. Any ideas?
EDIT2: setting PCL_DIR to set(PCL_DIR "C:\\Users\\xxx\\Desktop\\pclndk\\vcpkg\\installed\\x86-windows\\share\\pcl") also wields same result
I went over the grpc installation and finished building and installation.
Now when I try to:
find_package(gRPC CONFIG REQUIRED)
I get
CMake Error at CMakeLists.txt:15 (find_package):
Found package configuration file:
/usr/lib64/cmake/grpc/gRPCConfig.cmake
but it set gRPC_FOUND to FALSE so package "gRPC" is considered to be NOT
FOUND. Reason given by package:
The following imported targets are referenced, but are missing:
protobuf::libprotobuf protobuf::libprotoc
Event though
find_package(Protobuf REQUIRED)
Works just fine.
I read I'm supposed to run cmake ../.. -DBUILD_DEPS=ON -DBUILD_SHARED_LIBS=ON to solve this. However that results in:
CMake Error at cmake/abseil-cpp.cmake:38 (find_package):
Could not find a package configuration file provided by "absl" with any of
the following names:
abslConfig.cmake
absl-config.cmake
Add the installation prefix of "absl" to CMAKE_PREFIX_PATH or set
"absl_DIR" to a directory containing one of the above files. If "absl"
provides a separate development package or SDK, be sure it has been
installed.
Call Stack (most recent call first):
CMakeLists.txt:191 (include)
-- Configuring incomplete, errors occurred!
See also "/home/ray/CLionProjects/grpc/grpc/CMakeFiles/CMakeOutput.log".
See also "/home/ray/CLionProjects/grpc/grpc/CMakeFiles/CMakeError.log".
Content of /usr/lib64/cmake/grpc/gRPCConfig.cmake
# Module path
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/modules)
# Depend packages
# Targets
include(${CMAKE_CURRENT_LIST_DIR}/gRPCTargets.cmake)
The problem is actually with the project you use via find_package() and with its package file (/usr/lib64/cmake/grpc/gRPCConfig.cmake in your case). The error message
The following imported targets are referenced, but are missing:
means, that the package file references IMPORTED targets but they are never defined.
The usual reason for that problem is following:
During its own build, the project uses find_package() for some other packages. This find_package() call defines IMPORTED targets, which are used in the project for link.
Its package file includes the script(s), which is created by install(EXPORT) command and filled according to install(TARGETS ... EXPORT ...) command. This included script uses IMPORTED targets, but doesn't define them.
The project's package file forgets to use find_package, or, better, find_dependency for define the IMPORTED target for the included scripts.
If you don't want to fix the (other) project's package file, then the most direct solution is to add missed find_package into your own project:
# Hack: This will define IMPORTED targets, needed for gRPC project, but not defined by it.
find_package(Protobuf REQUIRED)
# Now perform the original 'find_package' call.
find_package(gRPC CONFIG REQUIRED)
Actually, gRPCConfig.cmake package file was intended to contain the call find_package(Protobuf). Its template cmake/gRPCConfig.cmake.in is following:
# Module path
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/modules)
# Depend packages
#_gRPC_FIND_ZLIB#
#_gRPC_FIND_PROTOBUF#
#_gRPC_FIND_SSL#
#_gRPC_FIND_CARES#
#_gRPC_FIND_ABSL#
# Targets
include(${CMAKE_CURRENT_LIST_DIR}/gRPCTargets.cmake)
and on substitution the variable _gRPC_FIND_PROTOBUF should emit the following code:
if(NOT Protobuf_FOUND AND NOT PROTOBUF_FOUND)
find_package(Protobuf ${gRPC_PROTOBUF_PACKAGE_TYPE})
endif()
(the variable should be set in cmake/protobuf.cmake).
But something goes wrong, and the resulted /usr/lib64/cmake/grpc/gRPCConfig.cmake contains the empty variable's substitution:
# Module path
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/modules)
# Depend packages
# Targets
include(${CMAKE_CURRENT_LIST_DIR}/gRPCTargets.cmake)
I'm trying to link SDL2_net (SDL_net 2.0) to my project via CMake, but after searching around I've yet to find a solution. My CMakeLists.txt currently looks like this:
1 cmake_minimum_required (VERSION 3.7)
2 project (SDL_net_test)
3 include (FindPkgConfig)
4 include (FindSDL_net)
5
6 pkg_search_module (SDL2 REQUIRED sdl2)
7 pkg_search_module (SDL_NET REQUIRED sdl2_net)
8
9 include_directories (${SDL2_INCLUDE_DIRS} ${SDL_NET_INCLUDE_DIRS})
10
11 add_executable (SDL_net_test main.cpp)
12 target_link_libraries (SDL_net_test ${SDL2_LIBRARIES} ${SDL_NET_LIBRARIES})
However, when I attempt to run CMake it gives me the following error(s):
-- Could NOT find SDL_net (missing: SDL_NET_LIBRARIES SDL_NET_INCLUDE_DIRS)
-- Checking for one of the modules 'sdl2_net'
CMake Error at /usr/share/cmake/Modules/FindPkgConfig.cmake:659 (message):
None of the required 'sdl2_net' found
Call Stack (most recent call first):
CMakeLists.txt:7 (pkg_search_module)
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:
SDL_NET_INCLUDE_DIR (ADVANCED)
used as include directory in directory /home/neboula/Programming/sandbox/sdl2_net
used as include directory in directory /home/neboula/Programming/sandbox/sdl2_net
used as include directory in directory /home/neboula/Programming/sandbox/sdl2_net
SDL_NET_LIBRARY (ADVANCED)
linked by target "SDL_net_test" in directory /home/neboula/Programming/sandbox/sdl2_net
-- Configuring incomplete, errors occurred!
See also "/home/neboula/Programming/sandbox/sdl2_net/build/CMakeFiles/CMakeOutput.log".
I have installed the SDL2_net-devel package from my package manager (dnf on Fedora 29), and I've successfully linked SDL2 and SDL2_image previously basing it on this answer, which worked brilliantly. I also found this, but I'm not entirely sure how to use it. How should I go about this?
Since the person who provided an answer only posted a comment about it, I'll put it down here myself.
The solution was seemingly very simple: I had written pkg_search_module (SDL_NET REQUIRED sdl2_net), while it was supposed to be pkg_search_module (SDL_NET REQUIRED SDL2_net).
To easily integrate the SDL2 library and other related libraries (SDL2_net, SDL2_mixer, ...), I developed modern cross-platform CMake modules that can be used as follows:
Clone SDL2 CMake modules inside our project:
git clone https://github.com/aminosbh/sdl2-cmake-modules cmake/sdl2
Add the following lines in your main CMakeLists.txt
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2)
find_package(SDL2 REQUIRED)
find_package(SDL2_net REQUIRED)
target_link_libraries(${PROJECT_NAME} SDL2::Main SDL2:Net)
You can even specify a custom path to find the SDL2, SDL2_net, ... useful specially on Windows.
cmake .. -DSDL2_PATH="/path/to/sdl2" -DSDL2_NET_PATH="/path/to/sdl2-net"
For sure, you should not forgot to install the specific packages:
# Fedora/RPM
sudo yum install SDL2-devel SDL2_net-devel
# Debian/Ubuntu
sudo apt install libsdl2-dev libsdl2-net-dev
I tried everything like:
Configure environment variable
Make fresh build
Re-install BOOST from source
sudo apt-get install libboost-all-dev
But still getting following Errors:
CMake Error at /usr/share/cmake-2.8/Modules/FindBoost.cmake:1131 (message):
Unable to find the requested Boost libraries.
Unable to find the Boost header files. Please set BOOST_ROOT to the root
directory containing Boost or BOOST_INCLUDEDIR to the directory containing
Boost's headers.
Call Stack (most recent call first):
CMakeLists.txt:147 (find_package)
CMake Error at /usr/share/cmake-2.8/Modules/FindBoost.cmake:1131 (message):
Unable to find the requested Boost libraries.
Unable to find the Boost header files. Please set BOOST_ROOT to the root
directory containing Boost or BOOST_INCLUDEDIR to the directory containing
Boost's headers.
Source code directory for boost: /usr/local/src/boost_1_45_0
Boost Library path: /usr/local/lib
Boost Header file: /usr/local/include/boost
Here is bashrc file:
BOOST_ROOT="/usr/local/src/boost_1_45_0"
Boost_LIBRARY_DIRS="/usr/local/lib"
BOOST_INCLUDEDIR="/usr/local/src/boost_1_45_0"
How to solve these Errors? Am i missing something?
Edit:
cmake -DCMAKE_TOOLCHAIN_FILE=$ANDTOOLCHAIN -DBOOST_ROOT=/usr/local/src/boost_1_45_0 -DBOOST_INCLUDEDIR=/usr/local/include/boost -DBOOST_LIBRARYDIR=/usr/local/lib -DPYTHON_LIBRARIES=/usr/local/lib/python2.7 -DPYTHON_INCLUDE_DIRS=/usr/include/python2.7 -DCMA-DRDK_BUILD_PYTHON_WRAPPERS=
Try to complete cmake process with following libs:
sudo apt-get install cmake libblkid-dev e2fslibs-dev libboost-all-dev libaudit-dev
I'm using this to set up boost from cmake in my CMakeLists.txt. Try something similar (make sure to update paths to your installation of boost).
SET (BOOST_ROOT "/opt/boost/boost_1_57_0")
SET (BOOST_INCLUDEDIR "/opt/boost/boost-1.57.0/include")
SET (BOOST_LIBRARYDIR "/opt/boost/boost-1.57.0/lib")
SET (BOOST_MIN_VERSION "1.55.0")
set (Boost_NO_BOOST_CMAKE ON)
FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} REQUIRED)
if (NOT Boost_FOUND)
message(FATAL_ERROR "Fatal error: Boost (version >= 1.55) required.")
else()
message(STATUS "Setting up BOOST")
message(STATUS " Includes - ${Boost_INCLUDE_DIRS}")
message(STATUS " Library - ${Boost_LIBRARY_DIRS}")
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
endif (NOT Boost_FOUND)
This will either search default paths (/usr, /usr/local) or the path provided through the cmake variables (BOOST_ROOT, BOOST_INCLUDEDIR, BOOST_LIBRARYDIR). It works for me on cmake > 2.6.
I got the same error the first time I wanted to install LightGBM on python (GPU version).
You can simply fix it with this command line :
sudo apt-get install cmake libblkid-dev e2fslibs-dev libboost-all-dev libaudit-dev
the boost libraries will be installed and you'll be fine to continue your installation process.
seems the answer is in the comments and as an edit but to clarify this should work for you:
export BUILDDIR='your path to build directory here'
export SRCDIR='your path to source dir here'
export BOOST_ROOT="/opt/boost/boost_1_57_0"
export BOOST_INCLUDE="/opt/boost/boost-1.57.0/include"
export BOOST_LIBDIR="/opt/boost/boost-1.57.0/lib"
export BOOST_OPTS="-DBOOST_ROOT=${BOOST_ROOT} -DBOOST_INCLUDEDIR=${BOOST_INCLUDE} -DBOOST_LIBRARYDIR=${BOOST_LIBDIR}"
(cd ${BUILDDIR} && cmake ${BOOST_OPTS} ${SRCDIR})
you need to specify the arguments as command line arguments or you can use a toolchain file for that, but cmake will not touch your environment variables.
I just want to point out that the FindBoost macro might be looking for an earlier version, for instance, 1.58.0 when you might have 1.60.0 installed. I suggest popping open the FindBoost macro from whatever it is you are attempting to build, and checking if that's the case. You can simply edit it to include your particular version. (This was my problem.)
Thanks Paul-g for your advise. For my part it was a bit different.
I installed Boost by following the Step 5 of : https://www.boost.org/doc/libs/1_59_0/more/getting_started/unix-variants.html
And then I add PATH directory in the "FindBoos.cmake", located in /usr/local/share/cmake-3.5/Modules :
SET (BOOST_ROOT "../boost_1_60_0")
SET (BOOST_INCLUDEDIR "../boost_1_60_0/boost")
SET (BOOST_LIBRARYDIR "../boost_1_60_0/libs")
SET (BOOST_MIN_VERSION "1.55.0")
set (Boost_NO_BOOST_CMAKE ON)
Long answer to short, if you install boost in custom path, all header files must in ${path}/boost/.
if you want to konw why cmake can't find the requested Boost libraries after you have set BOOST_ROOT/BOOST_INCLUDEDIR, you can check cmake install location path_to_cmake/share/cmake-xxx/Modules/FindBoost.
cmake which will find Boost_INCLUDE_DIR in boost/config.hpp in BOOST_ROOT. That means your boost header file must in ${path}/boost/, any other format (such as ${path}/boost-x.y.z) will not be suitable for find_package in CMakeLists.txt.
I had the same issue inside an alpine docker container, my solution was to add the boost-dev apk library because libboost-dev was not available.