I have a HelloWorld project in JetBrains CLion and set up boost so I can build it fine.
I've managed to build soci using cmake and make with mingw outside the HelloWorld project.
For boost I used:
include(FindBoost)
find_package(Boost 1.55.0 COMPONENTS system filesystem)
How do I include the soci library in my cmake? Is there a similar method for including soci? I don't know where to start?
UPDATE
A bit further I think.
I added the following to my cmake options:
-D CMAKE_MODULE_PATH=D:\Development\Tools\lib\soci-3.2.2\cmake\modules
and this to my CMakeLists.txt:
find_package(Soci)
if(${SOCI_FOUND})
target_link_libraries(HelloWorld ${SOCI_LIBRARY} ${SOCI_sqlite3_PLUGIN})
else()
message(WARNING "SOCI NOT FOUND")
endif()
I still get SOCI NOT FOUND though but at least the soci variables turns up in the cmake cache.
This is obviously very late, but it worked for me:
target_link_libraries(HelloWorld soci_core soci_mysql)
I must admit I shame for my country mates because they provide so crapy CMakeLists.txt for SOCI lib. In order to mitigate they bad works, I wrote following intsturctions how to use SOCI in CMake based projects. I do it on Linux KDE Neon 5.16.5 (based on: Ubuntu 18.04 LTS), but on Windows probably you have only fix paths. This probalby will work. I am not 100% sure because I just start my project within I want to use SOCI.
This is obviously very late, but it probably works:
I build and install soci like this:
cmake "/home/szyk/!-EnergoKod/!-Libs/3rdparty/soci" -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu -DCMAKE_BUILD_TYPE=Release
cmake "/home/szyk/!-EnergoKod/!-Libs/3rdparty/soci" -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu -DCMAKE_BUILD_TYPE=Debug
make -j$(nproc)
sudo make install
I add to my project CMakeLists.txt:
set(SOCI_SOURCE_DIR "$ENV{HOME}/!-EnergoKod/!-Libs/3rdparty/soci")
set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH ${SOCI_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
find_package(Soci)
list(APPEND LIBS ${SOCI_LIBRARY} ${SOCI_sqlite3_PLUGIN})
# Link libraries
target_link_libraries(${PROJECT_NAME} PRIVATE ${LIBS})
That is generates good looking output:
Soci found: Looking for plugins
* Plugin mysql not found.
* Plugin odbc not found.
* Plugin postgresql not found.
* Plugin sqlite3 found /usr/local/lib/x86_64-linux-gnu/libsoci_sqlite3.so.
Found Soci: /usr/local/include/soci
Related
I'm at the very first day of Qt + Cmake and Conan, trying to make things work. I'm not using qmake because I'll integrate everything into a bigger project using cmake.
By following QT's tutorial, I figured out that I need to compile QT macros, and for that there's a useful AUTOMOC CMake property, as suggested here.
The point is that it's making me fail cmake builds.
My conanfile.txt:
[requires]
qt/5.15.2
[generators]
cmake
My CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
project(qttest)
set(CMAKE_CXX_STANDARD 20)
set_target_properties(${PROJECT_NAME} PROPERTIES AUTOMOC TRUE)
set (PROJECT_SOURCE_DIR ${PROJECT_SOURCE_DIR}/src)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
with the following output:
CMake Warning (dev) in CMakeLists.txt:
AUTOGEN: No valid Qt version found for target qttest. AUTOMOC disabled.
Consider adding:
find_package(Qt<QTVERSION> COMPONENTS Core)
to your CMakeLists.txt file.
This warning is for project developers. Use -Wno-dev to suppress it.
ouch, but adding the find doesn't make things better:
CMake Warning at CMakeLists.txt:6 (find_package):
By not providing "FindQt5.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Qt5", but
CMake did not find one.
Could not find a package configuration file provided by "Qt5" with any of
the following names:
Qt5Config.cmake
qt5-config.cmake
Actually the project compiles, Qt is there in its conan dir:
matteo#MacBook-Pro-de-matteo 96a68a791abfc7a246f2bc28aa2f6fc210be0f9f % cd ~/.conan/data/qt
matteo#MacBook-Pro-de-matteo qt % ls
5.15.2 6.2.2
matteo#MacBook-Pro-de-matteo qt %
how could I enable it, or make things easier to compile it along with cmake?
You need to tell CMake, where to find Qt.
So, as CMake suggests by itself:
find_package(Qt5 COMPONENTS Core)
for the most basic stuff, you might want to add some of the other components later.
Depending on the system you are working on and your Qt installation, you need to tell CMake where to search for the package configuration files (second error message). CMake has some default directories, where it looks for these files, but obviously, there is none. On Linux, this can be solved by installing Qt with a package manager (this will install the CMake config files to one of the Qt default locations). If you are on Windows or if you installed Qt to a different location, this can be solved by providing the path with the PREFIX_PATH-variable.
cmake -B $BUILD_DIR -S $SOURCE_DIR -DCMAKE_PREFIX_PATH=$QT_INSTALL_PATH/5.15.2/$ARCHITECTURE $OTHER_OPTIONS
(You can have different versions installed in the same installation path, that's why Qt adds an other folder with the version number. And you can have different compilers/architectures. On Windows for example, you might have a mingw73_32 and a msvc2017 folder to choose.)
As already mentioned in the comments, a project is no CMake target. CMake targets are either libraries (add_library), executables (add_executable) or custom targets (add_custom_target); the project is not. If you want to set the AUTOMOC property target wise, that's ok and even suggested by CMake, but you can also set it globally by using:
set(CMAKE_AUTOMOC ON)
I am setting up a C++ CLion project to learn OpenGL, I started by adding the GLFW dependency with Conan on a WSL system on Windows, and I can't manage to include the GLFW headers after successfully configuring my CMake project.
I am using :
CLion 2020.3 with a configured WSL toolchain
CMake 3.10.2
Conan 1.32.1
GLFW 3.3.2, from the conan-center remote
I can manage to run the Getting started example of conan without any issues, but installing GLFW seems to be a bit more involved than poco.
I can locate the desired header in the .conan directory, but for some reason it is not visible at link time, a piece is missing here.
Code
CMakeLists.txt :
cmake_minimum_required(VERSION 3.10)
project(learn_opengl)
set(CMAKE_CXX_STANDARD 14)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
add_executable(learn_opengl main.cpp)
message("CONAN LIBS: ${CONAN_LIBS}")
conan_target_link_libraries(learn_opengl ${CONAN_LIBS})
conanfile.txt
[requires]
glfw/3.3.2
[generators]
cmake
The error at compile-time :
main.cpp:2:10: fatal error: GLFW\glfw3.h: No such file or directory
#include <GLFW\glfw3.h>
I have to dive deeper to understand the compilation process here and the way Conan and CMake interact, any help or shortcut would be great as I find myself a bit clueless here, many thanks.
I am using Cmake to build my C++ project and I am using conan to maintain my boost libraries.
My conanfile.txt is very simple,
[requires]
boost/1.71.0#conan/stable
[generators]
cmake
When I install boost from conan, I can use following commands,
conan install ..
Or,
conan install .. -s build_type=Debug
Both command install bost libraries in two different folders in my C:/.conan foler.
In CMakeLists.txt I have following lines to find boost
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_DEBUG_LIBS ON)
set(Boost_USE_RELEASE_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost REQUIRED COMPONENTS program_options)
However, When I configure cmake,
cmake .. -DBoost_DEBUG=ON
it doesn't find the debug version of boost library. It always shows that it it pointing to release version. So naturally, the following command works,
cmake --build . --config Release
However, following command failed,
cmake --build . --config Debug
as it is still trying to link ot release version.
How can I reconfigure my cmake and conan setup so that I can easily switch between debug and release version? Any suggestion?
Cheers,
M
If you want to consume the libraries with find_package(Boost) you need to generate the corresponding files. Use the cmake_find_package generator (you need different folders for Debug and Release) or the cmake_find_package_multi one (both Debug and Release can live in the same folder). Just add them to your conanfile.txt:
[requires]
boost/1.71.0
[generators]
cmake_find_package_multi
Now, you can call CMake from the command line, but you need to tell where to find the generated FindBoost.cmake files (or the BoostConfig.cmake if you are using the multi generator):
cmake .. -DCMAKE_MODULE_PATH=<path/to/dir/with/findcmake> [...more arguments]
Take into account that, if you are not using the cmake generator and the call to conan_basic_setup, you need to be sure that the configuration used to build the Boost binaries you are getting from Conan matches the one you are using to build your project (otherwise you might get linker errors).
If you aren't already I'd recommend using https://github.com/conan-io/cmake-conan it makes life easier in some areas.
Unless you want to be able to build your project without conan there is no real need to use find_package with conan. See https://docs.conan.io/en/latest/integrations/build_system/cmake/cmake_generator.html. You can either use:
conan_basic_setup()
target_link_libraries(<target> ${CONAN_LIBS})
Or:
conan_basic_setup(TARGETS)
target_link_libraries(<target> CONAN_PKG::boost)
If you want to use find_package you need to use the cmake_find_package generator and add the following to your conanfile.txt:
[generators]
cmake_find_package
cmake_paths
I'm trying to start writing my Qt project inside JetBrains' Clion but I need to link some libraries in my Cmake file first. There's no problem when trying to find packages like Qt5Core, Qt5Widgets, Qt5Gui but when it come to finding Qt5Charts an error is thrown:
By not providing "FindQt5Charts.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file
provided by "Qt5Charts", but CMake did not find one.
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.
This is my CMake file right now.
All packages are installed via the Qt's Linux(ubuntu) maintanence tool.
Any ideas how to help Cmake find the Charts module ?
Using the following and see if it helps:
sudo apt install libqt5charts5-dev
Src: https://stackoverflow.com/a/46765025
Typically when including Qt5 in a project I use the follow basic script for CMake, though I should note I haven't tested this on Linux.
cmake_minimum_required(VERSION 3.10.0 FATAL_ERROR)
project(<YOUR_PROJECT_NAME>)
find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets Charts)
# set your project sources and headers
set(project_sources src/blah.cpp)
set(project_headers include/headers/blah.h)
# wrap your qt based classes with qmoc
qt5_wrap_cpp(project_source_moc ${project_headers})
# add your build target
add_executable(${PROJECT_NAME} ${project_sources} ${project_headers} ${project_source_moc})
# link to Qt5
target_link_libraries(${PROJECT_NAME}
PUBLIC
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::Charts)
# require C++ 14
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_14)
When configuring your project via cmake, you just need to pass in the path to you qt5 installation directory (cmake variable name is Qt5_DIR) that contains the Qt5Config.cmake file and then cmake should be able to find the rest of the components that you request.
Also double check that Qt5Charts was installed, not sure if it's installed by default.
Maybe try this?
sudo apt install libqt5charts5-dev
I'm very new to CLion, CMake and macOS at all so I need a little bit of help while trying to include cppnetlib into my CLion project.
I started out with creating an new CLion project which gave me a new CMakeLists.txt which I edited so that it would include boost as well:
CMAKE_MINIMUM_REQUIRED(VERSION 3.7)
PROJECT(myapp)
SET(CMAKE_CXX_STANDARD 11)
SET(SOURCE_FILES main.cpp)
ADD_EXECUTABLE(myapp ${SOURCE_FILES})
FIND_PACKAGE(Boost 1.63.0 REQUIRED)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(dxcheck ${Boost_LIBRARIES})
I've installed boost through homebrew, but I did not find a package for cppnetlib with homebrew so I downloaded cppnetlib and placed it in /usr/local/Cellar/cpp-netlib. Now, when I follow the tutorial on their page and put
set (CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} /usr/local/Cellar/cpp-netlib)
find_package (cppnetlib 0.12.0 REQUIRED)
include_directories (${CPPNETLIB_INCLUDE_DIRS})
target_link_libraries (myapp ${CPPNETLIB_LIBRARIES})
into the CMakeLists.txt, I get the following output:
-- Boost version: 1.63.0
CMake Error at CMakeLists.txt:14 (find_package):
By not providing "Findcppnetlib.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"cppnetlib", but CMake did not find one.
Could not find a package configuration file provided by "cppnetlib"
(requested version 0.11.0) with any of the following names:
cppnetlibConfig.cmake
cppnetlib-config.cmake
Add the installation prefix of "cppnetlib" to CMAKE_PREFIX_PATH or set
"cppnetlib_DIR" to a directory containing one of the above files. If
"cppnetlib" provides a separate development package or SDK, be sure it has
been installed.
I've already done some research about finding packages but all I could achieve was that I was able to include cppnetlib by manually adding the include path to the CMakeLists.txt but then I got an error saying that the compiler could not find the headers which are located inside the "deps" folder in cpp-netlib.
I know want to know how to include a package like cppnetlib properly into my CLion project using CMake. I am using CLion 2017.1, macOS Sierra and I think CLion is using CMake 3.7.