Cmake couldn't find a library path with error message - c++

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

Related

CMake finding package configuration files but not the requested components of SFML

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

CMake file cannot locate QT Charts module, but installed it

CMake file will not locate my QtCharts module, but QtCharts is, in theory, installed - here's a proof of it (that's what I get when I open the maintenance tool)
Now, I've been struggling for days to locate them with no success, I will show you my CMakeLists:
cmake_minimum_required(VERSION 3.17)
project(CPP)
set(CMAKE_CXX_STANDARD 14)
include_directories(Console)
include_directories(Domain)
include_directories(Exception)
include_directories(Repository)
include_directories(Service)
include_directories(StartingWidget)
include_directories(Tests)
include_directories(Validator)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_PREFIX_PATH "C:\\Qt\\5.15.2\\mingw81_64\\lib\\cmake")
set(QT_VERSION 5)
set(REQUIRED_LIBS Core Gui Widgets Charts)
set(REQUIRED_LIBS_QUALIFIED Qt5::Core Qt5::Charts Qt5::Gui Qt5::Widgets)
add_executable(CPP main.cpp Domain/Tutorial.cpp Domain/Tutorial.h Repository/Repository.h Service/Service.cpp Service/Service.h Console/Administrator_Console.cpp Console/Administrator_Console.h Validator/Validator.cpp Validator/Validator.h Exception/Exception.cpp Exception/Exception.h Console/User_Console.cpp Console/User_Console.h Tests/RunTests.cpp Tests/RunTests.h Repository/FileRepository.h Repository/CSVRepository.h Repository/CSVRepository.cpp Repository/HTMLRepository.h Repository/HTMLRepository.cpp Console/GUI_Console.cpp Console/GUI_Console.h Console/GUI_User_Console.cpp Console/GUI_User_Console.h StartingWidget/StartingWidget.cpp StartingWidget/StartingWidget.h)
if (NOT CMAKE_PREFIX_PATH)
message(WARNING "CMAKE_PREFIX_PATH is not defined, you may need to set it "
"(-DCMAKE_PREFIX_PATH=\"path/to/Qt/lib/cmake\" or -DCMAKE_PREFIX_PATH=/usr/include/{host}/qt{version}/ on Ubuntu)")
endif ()
find_package(Qt${QT_VERSION} COMPONENTS ${REQUIRED_LIBS} REQUIRED)
target_link_libraries(${PROJECT_NAME} ${REQUIRED_LIBS_QUALIFIED})
and the error I get is:
CMake Error at C:/Qt/5.15.2/mingw81_64/lib/cmake/Qt5/Qt5Config.cmake:28 (find_package):
Could not find a package configuration file provided by "Qt5Charts" with
any of the following names:
Qt5ChartsConfig.cmake
qt5charts-config.cmake
Add the installation prefix of "Qt5Charts" to CMAKE_PREFIX_PATH or set
"Qt5Charts_DIR" to a directory containing one of the above files. If
"Qt5Charts" provides a separate development package or SDK, be sure it has
been installed.
Call Stack (most recent call first):
CMakeLists.txt:33 (find_package)
This is not the first time I get this error, because I had before another CMakeLists which just had include_package(Qt5::Charts) and I would get the same error. I am using Qt 5.15.2, open source (community).
I needed to reinstall the QT and use a custom install instead of using the basic 5.12.5 one, because Maintenance tool might be bugged - if someone runs into this, take care and do a reinstall

vcpkg add new library but it cannot be found

I tries to add a new library at vcpkg, so I have wrote a CONTROL file and portfile.cmake file. When I run the installation, it's successful:
./vcpkg.exe install gf:x64-windows
Computing installation plan...
The following packages will be built and installed:
gf[core]:x64-windows
Starting package 1/1: gf:x64-windows
Building package gf[core]:x64-windows...
-- SOURCE_PATH: C:/path/to/vcpkg/buildtrees/gf/src/v0.15.0
-- Dynamic build
-- Configuring x64-windows
-- Building x64-windows-dbg
-- Building x64-windows-rel
-- Installing: C:/path/to/vcpkg/packages/gf_x64-windows/share/gf/copyright
-- Performing post-build validation
-- Performing post-build validation done
Building package gf[core]:x64-windows... done
Installing package gf[core]:x64-windows...
Installing package gf[core]:x64-windows... done
Elapsed time for package gf:x64-windows: 52.05 s
Total elapsed time: 52.1 s
The package gf:x64-windows provides CMake targets:
find_package(gf CONFIG REQUIRED)
target_link_libraries(main PRIVATE gf::gf0)
find_package(gfcore CONFIG REQUIRED)
target_link_libraries(main PRIVATE gf::gfcore0)
find_package(gfnet CONFIG REQUIRED)
target_link_libraries(main PRIVATE gf::gfnet0)
But when I want use this library into another project, I have this error:
cmake -A x64 -DCMAKE_TOOLCHAIN_FILE=C:/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake ..
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19041.
-- CMAKE_MODULE_PATH: C:/path/to/project/pax_et_mors/modules
CMake Error at C:/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake:405 (_find_package):
By not providing "Findgf.cmake" in CMAKE_MODULE_PATH this project has asked
CMake to find a package configuration file provided by "gf", but CMake did
not find one.
Could not find a package configuration file provided by "gf" with any of
the following names:
gfConfig.cmake
gf-config.cmake
Add the installation prefix of "gf" to CMAKE_PREFIX_PATH or set "gf_DIR" to
a directory containing one of the above files. If "gf" provides a separate
development package or SDK, be sure it has been installed.
Call Stack (most recent call first):
CMakeLists.txt:12 (find_package)
-- Configuring incomplete, errors occurred!
See also "C:/path/to/project/pax_et_mors/build/CMakeFiles/CMakeOutput.log".
Where is my error?
The library can be found here: https://github.com/GamedevFramework/gf
The project here: https://github.com/Hatunruna/ggj2020
This is the CONTROL file for gf:
Source: gf
Version: 0.15
Description: Gamedev Framework (gf) is a framework to build 2D games in C++14.
And the portfile.cmake:
find_program(GIT git)
set(GIT_URL "https://github.com/GamedevFramework/gf")
set(GIT_TAG "loading_thread")
set(SOURCE_PATH ${CURRENT_BUILDTREES_DIR}/src/${GIT_TAG})
message(STATUS "SOURCE_PATH: ${SOURCE_PATH}")
if(NOT EXISTS "${SOURCE_PATH}/.git")
message(STATUS "Cloning and fetching submodules")
vcpkg_execute_required_process(
COMMAND ${GIT} clone -b ${GIT_TAG} --recurse-submodules ${GIT_URL} ${SOURCE_PATH}
WORKING_DIRECTORY ${SOURCE_PATH}
LOGNAME clone
)
message(STATUS "Checkout tag ${GIT_TAG}")
vcpkg_execute_required_process(
COMMAND ${GIT} checkout ${GIT_TAG}
WORKING_DIRECTORY ${SOURCE_PATH}
LOGNAME checkout
)
endif()
string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" BUILD_SHARED)
if(${BUILD_SHARED})
message(STATUS "Dynamic build")
set(BUILD_SHARED_OPTION "ON")
else()
message(STATUS "Static build")
set(BUILD_SHARED_OPTION "OFF")
endif()
vcpkg_configure_cmake(
SOURCE_PATH ${SOURCE_PATH}
PREFER_NINJA
OPTIONS -DGF_BUILD_GAMES=OFF -DGF_BUILD_TOOLS=OFF -DGF_BUILD_EXAMPLES=OFF -DGF_BUILD_TESTS=OFF -DGF_BUILD_DOCUMENTATION=OFF -DGF_SINGLE_COMPILTATION_UNIT=ON -DGF_SHARED=${BUILD_SHARED_OPTION}
OPTIONS_RELEASE -DGF_DEBUG=OFF
OPTIONS_DEBUG -DGF_DEBUG=ON
)
vcpkg_install_cmake()
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake)
vcpkg_copy_pdbs()
file(REMOVE_RECURSE
"${CURRENT_PACKAGES_DIR}/debug/share"
"${CURRENT_PACKAGES_DIR}/debug/include"
"${CURRENT_PACKAGES_DIR}/share/doc"
)
file(INSTALL ${SOURCE_PATH}/LICENSE.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/gf RENAME copyright)
Finally, I found the problem. vcpkg needs to have a separated folder for each targets.
So I have change the portfile.cmake:
find_program(GIT git)
# Same as previous...
vcpkg_fixup_cmake_targets(CONFIG_PATH lib/cmake TARGET_PATH "share/gf_tmp")
vcpkg_copy_pdbs()
file(RENAME "${CURRENT_PACKAGES_DIR}/share/gf_tmp/gfcore" "${CURRENT_PACKAGES_DIR}/share/gfcore")
file(RENAME "${CURRENT_PACKAGES_DIR}/share/gf_tmp/gf" "${CURRENT_PACKAGES_DIR}/share/gf")
file(RENAME "${CURRENT_PACKAGES_DIR}/share/gf_tmp/gfnet" "${CURRENT_PACKAGES_DIR}/share/gfnet")
file(REMOVE_RECURSE
"${CURRENT_PACKAGES_DIR}/debug/share"
"${CURRENT_PACKAGES_DIR}/debug/include"
"${CURRENT_PACKAGES_DIR}/share/doc"
"${CURRENT_PACKAGES_DIR}/share/gf_tmp"
)
file(INSTALL ${SOURCE_PATH}/LICENSE.txt DESTINATION ${CURRENT_PACKAGES_DIR}/share/gf RENAME copyright)

Specify Crypto++ library in a CMakeLists file

I am trying to specify the Crypto++ library in my CMakeLists file but I always get an error.
Here is my CMakeLists file:
cmake_minimum_required(VERSION 2.8)
project( Recognition )
find_package( OpenCV REQUIRED )
find_package ( CURL REQUIRED )
find_package ( CRYPTOPP REQUIRED )
add_executable( Recognition Recognition.cpp )
target_link_libraries( Recognition ${OpenCV_LIBS} ${CURL_LIBRARY} ${CRYPTOPP_LIBRARY})
And here is the errors I get:
By not providing "FindCRYPTOPP.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "CRYPTOPP",
but CMake did not find one.
Could not find a package configuration file provided by "CRYPTOPP" with any
of the following names:
CRYPTOPPConfig.cmake
cryptopp-config.cmake
Add the installation prefix of "CRYPTOPP" to CMAKE_PREFIX_PATH or set
"CRYPTOPP_DIR" to a directory containing one of the above files. If
"CRYPTOPP" provides a separate development package or SDK, be sure it has
been installed.
-- Configuring incomplete, errors occurred!
Thank you for your help!
CMake doesn't have a module for the Crypto++ library in the package so you have to provide your own. You can try the following(I've used it once) or google for the "Find CryptoPP cmake".
When you are done with the file, place it somewhere and point CMake to search for the file in that location. Suppose you have placed it under your sources directory in contrib/cmake subfolder, then CMake code will be:
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/contrib/cmake")
So you set the path for the modules search now you need to use find_package, note, however, that you should provide the package name in the same fashion your .cmake file is named. For example, if you have CryptoPP.cmake, then you should put the following:
find_package ( CryptoPP REQUIRED )

How to resolve error: "Missing required Boost components >= vX.XX, please install/upgrade Boost or configure your search paths"

I am trying to install gtsam and am running into some problems.
I installed boost to c:/program files/boost/boost_1_56_0 and added the following to my CMakeLists.text:
set(BOOST_ROOT "c:/Program Files/boost/boost_1_56_0")
set(BOOST_LIBRARYDIR "C:\Program Files\boost\boost_1_56_0\stage\lib")
However, I am getting the following error whenever I try to configure CMake:
-- GTSAM_SOURCE_ROOT_DIR: [C:/Program Files/gtsam-3.1.0]
-- Could NOT find Boost
-- CMake Error at CMakeLists.txt:106 (message):
Missing required Boost components >= v1.43, please install/upgrade Boost or
configure your search paths.
I am completely new to this and am at my wits end. Any suggestions?
First you need to add the boost directory:
include_directories(${BOOST_DIRECTORY})
then you need to use the boost header files for your executable:
set(HEADER_FILES ${BOOST_DIRECTORY}/file1.hpp ${BOOST_DIRECTORY}/file2.hpp)
add_executable(myexec execfile.cpp ${HEADER_FILES})