CMake file cannot locate QT Charts module, but installed it - c++

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

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

How to import package in cmake from vcpkg?

When I vcpkg install simdjson , it returns :
The package simdjson:x64-linux provides CMake targets:
find_package(simdjson CONFIG REQUIRED)
target_link_libraries(main PRIVATE simdjson::simdjson simdjson::simdjson-flags simdjson::simdjson-headers)
So I add
find_package(simdjson CONFIG REQUIRED)
target_link_libraries(main PRIVATE simdjson::simdjson simdjson::simdjson-flags simdjson::simdjson-headers)
to CMakeLists.txt to use the package simdjson
But when I vcpkg install redis-plus-plus[cxx17] , it returns nothing . What should I do to let cmake use this package ?
Unfortunately, redis-plus-plus doesn't supply CMake config files. Someone should open an issue with upstream. It's honestly pretty unacceptable to not support find_package for your library. Thus, thanks to the authors' negligence, you will have to create an imported target for their library yourself. Here's an example CMakeLists.txt, step by step. We'll start with the standard boilerplate:
cmake_minimum_required(VERSION 3.19)
project(test-redis)
Then we need to find hiredis, which is one of Redis++'s dependencies:
find_package(hiredis REQUIRED)
This will create a target called hiredis::hiredis we'll link to later. Now we'll create a target to hold the Redis++ usage information.
add_library(redis++::redis++ UNKNOWN IMPORTED)
Now we need to actually find the header path and redis++ libraries:
find_path(REDIS_PP_HEADER sw REQUIRED)
find_library(REDIS_PP_LIB redis++ REQUIRED)
And now we can tell CMake that the target we just created manages the library we just found:
set_target_properties(redis++::redis++ PROPERTIES IMPORTED_LOCATION "${REDIS_PP_LIB}")
And finally we can set up the include paths and dependency on Hiredis.
target_include_directories(redis++::redis++ INTERFACE "${REDIS_PP_HEADER}")
target_link_libraries(redis++::redis++ INTERFACE hiredis::hiredis)
We're now ready to use the library like we ought to be able to expect to.
add_executable(main main.cpp)
target_link_libraries(main PRIVATE redis++::redis++)

Cmake couldn't find a library path with error message

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

CMake qt input library postfix for custom debug build

I'm stuck with writing a cmake file for multiconfiguration IDE (Visual Studio).
My goal is to add a custom configuration and tell Visual Studio that I want to use debug libs of Qt (qtcored.lib) as it is done when I pick Debug configuration. With code below, I have release libraries in a linker input when I pick CustomDebug configuration
Does anyone know how to achieve that?
Thanks
cmake_minimum_required(VERSION 3.12.0)
project(custom-conf)
find_package(Qt5Core CONFIG REQUIRED)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(SRC main.cpp)
set(QT_LIBS Qt5::Core)
add_executable(custom-conf WIN32 ${SRC})
target_link_libraries(custom-conf ${QT_LIBS})
#
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(isMultiConfig)
set(CMAKE_CONFIGURATION_TYPES "CustomDebug;Debug;Release" CACHE STRING "" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_CUSTOMDEBUG "/debug")
endif()
I want to use debug libs of Qt (qtcored.lib) as it is done when I pick Debug configuration.
With the IMPORTED target this can be easiliy achieved by using MAP_IMPORTED_CONFIG<CONFIG> target property:
# For CustomDebug configuration of the main project
# use Debug configuration of the IMPORTED target
set_target_properties(Qt5::Core PROPERTIES
MAP_IMPORTED_CONFIG_CUSTOMDEBUG DEBUG)
With setting CMAKE_MAP_IMPORTED_CONFIG<CONFIG> variable you may automatically set the property for all IMPORTED targets:
set(CMAKE_MAP_IMPORTED_CONFIG_CUSTOMDEBUG DEBUG)
#...
# This call will create IMPORTED target Qt5::Core which
# MAP_IMPORTED_CONFIG_CUSTOMDEBUG property is already set.
find_package(Qt5Core CONFIG REQUIRED)
(The variable assignment should come before any call like find_package which creates IMPORTED target.)

Using SDL2 with CMake in CLion

After hours of scouring the web and SO for a solution I'm at a standstill. Nothing has worked so far for me...
I'm on Windows, using CLion IDE which uses CMake. My goal is to correctly link SDL2 to my project and use it through #include "SDL.h" which is the correct way.
The format of my CMakeLists.txt file
Specifics regarding the directory where I should have put the MingW development library of SDL2
Any requirements regarding windows ENV variables that I might have to set.
My CMakeLists.txt looks like this:
cmake_minimum_required(VERSION 3.6)
project(sdl2Project)
set(CMAKE_CXX_STANDARD 11)
#This is where sdl2-config.cmake is located
set(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} "C:/Users/MyUserName/CLibraries/SDL2-2.0.5/x86_64-w64-mingw32/lib/cmake/SDL2")
set(SOURCE_FILES main.cpp)
add_executable(sdl2Project ${SOURCE_FILES})
find_package(sdl2 REQUIRED)
target_include_directories(sdl2Project PUBLIC ${SDL2_INCLUDE_DIRS})
target_link_libraries(sdl2Project ${SDL2_LIBRARIES})
There is no FindSDL2.cmake file used.
The SDL2 library I downloaded from libsdl.org is located in:
C:/Users/MyUserName/CLibraries/SDL2-2.0.5/x86_64-w64-mingw32
I have no experience with CMake so I'm unable to truly understand where the problem stems from. What are the steps I need to take in order for it to find the library and link it correctly??
EDIT:
My Project structure is the following:
sdl2Project
cmake-build-debug
CMakeLists.txt
main.cpp
Looking in your FindSDL2.cmake, you need to provide an hint to CMake about where the library is installed. You could do this by setting an environment variable SDLDIR, but you shouldn't. General advice: you shouldn't use a CMake package that wasn't provided with the sources you're using.
Looking in sources of SDL2, root directory contains a file sdl2-config.cmake.in that should have been configured and installed in your install directory as sdl2-config.cmake: that's the package file you should use.
Am I right guessing the file C:/Users/MyUserName/CLibraries/SDL2-2.0.5/sdl2-config.cmake exists?
If yes, to allow CMake to find it, add your install directory to CMAKE_PREFIX_PATH, before calling find_package:
set(CMAKE_PREFIX_PATH
${CMAKE_PREFIX_PATH}
"C:/Users/MyUserName/CLibraries/SDL2-2.0.5"
)
find_package(sdl2 REQUIRED)
Note the use of "/" in the path instead of "\" which could be interpreted as escaping character. Quotes around the path are only necessary if the path contains whitespaces.
EDIT:
Moreover, you misused target_link_libraries with a wrong target: SDL2 which you don't build in your project, instead of sdl2Project.
You also used a wrong variable: SDL2_LIBRARY instead of SDL2_LIBRARIES; you can see the good variable name by looking in sdl2-config.cmake.
You may consider target_include_directories instead of include_directories, but again the variable name you used is wrong: SDL2_INCLUDE_DIR instead of SDL2_INCLUDE_DIRS.
Try:
target_include_directories(sdl2Project PUBLIC ${SDL2_INCLUDE_DIRS})
target_link_libraries(sdl2Project ${SDL2_LIBRARIES})