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.
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'm quite new to C++ and its ecosystem, still learning. Recently I'm trying to learn how to install a library and use it in my project.
I'm following the tutorial in the following link: https://vcpkg.readthedocs.io/en/latest/examples/installing-and-using-packages/
I'm ok with the basic usage of vcpkg and follow the tutorial install the sqlite3 library.
And also learned the basis stuff of cmake. As the tutorial goes: The best way to use installed libraries with cmake is via the toolchain file. So I prepared the following CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
set(CMAKE_TOOLCHAIN_FILE "C:/Develop/test/cpp/test-vcpkg/vcpkg/scripts/buildsystems/vcpkg.cmake")
project(test)
set(sqlite3_DIR "C:/Develop/test/cpp/test-vcpkg/vcpkg/installed/x64-windows/share/sqlite3")
find_package(sqlite3 CONFIG REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main sqlite3)
my CMakeLists.txt is a little different from the one in the tutorial, I set the sqlite3_DIR which is not mentioned in the tutorial (if I didn't add it, the build process will fail.)
And the source file is quite simple as following:
#include <sqlite3.h>
#include <stdio.h>
int main()
{
printf("%s\n", sqlite3_libversion());
return 0;
}
And I run the build command as the tutorial shows:
cmake ..
cmake --build .
these two command run through without errors.
I try to open the .sln file generated in the cmake .. process with visual studio, and try to build it, got the following error:
The application was unable to start correctly(0xc000007b)
If I try to the executable file of main.exe which I get during the cmake --build . process. I will get the same error message window.
Any help or ideas?
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.
i'm trying to use SFML's library with CLion for a school project. I'm still not confident with programming and i am new to Clion.
After having download the library from SFML official site i read some tutorials, but i am a bit confused:
https://www.sfml-dev.org/tutorials/2.4/
Infact in the Getting Started section there are two voice that concern me: "Compiling with Cmake" and "..Code::Blocks (MinGW).
Well i tryed both but with no results, then i landed here.
I saw a topic that helped a bit configure SFML for clion (windows)
so i tried to follow the steps suggested.
The library is in C:\SFML-2.4.2
I copied FindSFML.cmake in SFMLProjects, located in C:\Users\Ludovico\ (the same path of the folder ClionProjects)
Then i gave it a try
cmake_minimum_required(VERSION 3.6)
project(provaSfml)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp)
add_executable(provaSfml ${SOURCE_FILES})
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/SFMLProjects")
link_directories(C:/SFML-2.4.2/bin)
find_package(SFML REQUIRED system window graphics network audio)
if (SFML_FOUND)
include_directories(${SFML_INCLUDE_DIR})
target_link_libraries(provaSfml ${SFML_LIBRARIES})
endif ()
These are the error messages
"C:\Program Files (x86)\JetBrains\CLion 2016.3.2\bin\cmake\bin\cmake.exe" - DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Ludovico\CLionProjects\provaSfml
CMake Error at CMakeLists.txt:10 (find_package):
By not providing "FindSFML.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SFML", but
CMake did not find one.
Could not find a package configuration file provided by "SFML" with any of
the following names:
SFMLConfig.cmake
sfml-config.cmake
Add the installation prefix of "SFML" to CMAKE_PREFIX_PATH or set
"SFML_DIR" to a directory containing one of the above files. If "SFML"
provides a separate development package or SDK, be sure it has been
installed.
I'm thinking i did some mistakes even in the organization of folder...
can someone tell me some advice in order to clean the mess i have in my head?
What can i do to fix these problems?
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