Compile sfml with conan and cmake - c++

I'm trying to compile sfml with cmake and conan package manager. Here is my conanfile.txt:
[requires]
sfml/2.5.0#bincrafters/stable
[options]
sfml:graphics=true
sfml:window=True
sfml:audio=True
sfml:network=True
sfml:system=True
[generators]
cmake
[imports]
And my cmake file:
cmake_minimum_required (VERSION 3.10)
project(projectx)
add_executable(
${PROJECT_NAME}
src/main.cpp
)
target_link_libraries(
${PROJECT_NAME}
${CONAN_LIBS}
)
rtype
And when i compile here is my error :
ERROR: Unable to find 'sfml/2.5.0#bincrafters/stable' in remotes

The bincrafters remote is deprecated IIRC. You should use the conancenter remote instead (this is already configured as one of your remotes in newer conan versions - check with conan remote list to be sure, it should list 'conancenter: https://center.conan.io [Verify SSL: True]').
In your conanfile.txt simply replace the bincrafters/stable part by _/_ (I'm not 100% sure but maybe you don't need that #_/_ part at all, i.e. sfml/2.5.0 could suffice, already). The conancenter remote should be used.

Related

How to use cmake and vcpkg to import GLAD/GLFW3/ImGUI libraries on MacOS?

My goal is to write a simple, portable application using ImGUI. I also want a platform-agnostic build experience using cmake, and vcpkg to install dependencies. I got the program built and running on my Windows machine, but it's failing on my Macbook (macOS Monterey 12.6).
This is my vcpkg.json:
{
"name": "imguitest",
"version": "1.0",
"dependencies": [
"glad",
"glfw3",
{
"name": "imgui",
"features": [ "glfw-binding", "opengl3-binding" ]
}
]
}
This is my CMakeLists.txt:
cmake_minimum_required (VERSION 3.23)
project(ImGui-Test)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)
add_executable(${PROJECT_NAME}
src/main.cpp
)
find_package(glad CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE glad::glad)
find_package(glfw3 CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE glfw)
find_package(imgui CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE imgui::imgui)
find_package(OpenGL REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenGL::GL)
After running this:
# export VCPKG_DIR=/path/to/vcpkg/repo/
cmake -B ./build -S . "-DCMAKE_TOOLCHAIN_FILE=$VCPKG_DIR/scripts/buildsystems/vcpkg.cmake"
I get this error:
CMake Error at CMakeLists.txt:14 (find_package):
Could not find a package configuration file provided by "glad" with any of
the following names:
gladConfig.cmake
glad-config.cmake
Add the installation prefix of "glad" to CMAKE_PREFIX_PATH or set
"glad_DIR" to a directory containing one of the above files. If "glad"
provides a separate development package or SDK, be sure it has been
installed.
Do I have to manually install GLAD package myself and set the path? I thought vcpkg would handle that for me. Please let me know if I'm misunderstanding something, as I'm new to modern cmake and vcpkg.
This fixed it: brew install pkg-config
I got more descriptive error messages after I deleted the build folder. This error message was hidden when configuring cmake with vscode, but was visible when doing it through zsh terminal.
Building glfw3[core]:arm64-osx...
warning: -- Using community triplet arm64-osx. This triplet configuration is not guaranteed to succeed.
-- [COMMUNITY] Loading triplet configuration from: /Users/munta/Dev/vcpkg/triplets/community/arm64-osx.cmake
-- Downloading https://github.com/glfw/glfw/archive/7482de6071d21db77a7236155da44c172a7f6c9e.tar.gz -> glfw-glfw-7482de6071d21db77a7236155da44c172a7f6c9e.tar.gz...
-- Extracting source /Users/munta/Dev/vcpkg/downloads/glfw-glfw-7482de6071d21db77a7236155da44c172a7f6c9e.tar.gz
-- Using source at /Users/munta/Dev/vcpkg/buildtrees/glfw3/src/172a7f6c9e-7678776297.clean
GLFW3 currently requires the following libraries from the system package manager:
xinerama
xcursor
xorg
libglu1-mesa
pkg-config
These can be installed via brew install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev pkg-config
-- Configuring arm64-osx
-- Building arm64-osx-dbg
-- Building arm64-osx-rel
-- Fixing pkgconfig file: /Users/munta/Dev/vcpkg/packages/glfw3_arm64-osx/lib/pkgconfig/glfw3.pc
CMake Error at scripts/cmake/vcpkg_find_acquire_program.cmake:619 (message):
Could not find pkg-config. Please install it via your package manager:
brew install pkg-config
Call Stack (most recent call first):
scripts/cmake/vcpkg_fixup_pkgconfig.cmake:151 (vcpkg_find_acquire_program)
ports/glfw3/portfile.cmake:43 (vcpkg_fixup_pkgconfig)
scripts/ports.cmake:147 (include)

Cmake error: Target "restinio::restinio" contains relative path in its INTERFACE_INCLUDE_DIRECTORIES:

Preface: I am using Clion with Cygwin. I have installed vcpkg following their instructions. Then I followed restinio instructions to install restinio using vcpkg. Since restinio required fmt and http-parser I installed both of those too.
I have installed both the x86-windows version and x64-windows version of all 3 packages.
I linked vcpkg cmake file as per their instructions in Clion and have regenerated the CMakeCache
Currently I am trying to build specifically the x64-windows version (I was having other errors with the x86 version and I got further with the x64 version).
I have looked at this, and my initial error is different along with there is stuff inside of the directory that is in the relative path.
cmake_minimum_required(VERSION 3.23)
project(testing2)
set(CMAKE_CXX_STANDARD 14)
# RESTinio dependencies:
# 1. ASIO or Boost::ASIO (goes as headers, vcpkg knows where)
# 2. HTTP parser
find_package(unofficial-http-parser CONFIG REQUIRED)
# 3. fmtlib
find_package(fmt CONFIG REQUIRED)
# RESTinio itself
find_package(restinio CONFIG REQUIRED)
# Make your project dependent on restinio,
# and let cmake deal with all the headers paths and linked libs.
add_executable(testing2 main.cpp)
target_link_libraries(testing2 PRIVATE restinio::restinio)
cmake Options: -DCMAKE_TOOLCHAIN_FILE=C:\dev\vcpkg\vcpkg-master\scripts/buildsystems/vcpkg.cmake -DVCPKG_TARGET_TRIPLET:STRING=x64-windows
Clion output in the cmake tab:
-- Configuring done
CMake Error in CMakeLists.txt:
Target "restinio::restinio" contains relative path in its
INTERFACE_INCLUDE_DIRECTORIES:
"C:/dev/vcpkg/vcpkg-master/installed/x64-windows/include"
CMake Error in CMakeLists.txt:
IMPORTED_LOCATION not set for imported target
"unofficial::http_parser::http_parser" configuration "Debug".
-- Generating done
CMake Error:
Running
'/cygdrive/c/Program Files/JetBrains/CLion 2021.2.3/bin/ninja/cygwin/ninja.exe' '-C' '/cygdrive/c/Users/Tally/Desktop/DevStuffs/Testing2/cmake-build-debug' '-t' 'recompact'
failed with:
ninja: error: build.ninja:35: loading 'CMakeFiles/rules.ninja': No such file or directory
include CMakeFiles/rules.ninja
^ near here
CMake Generate step failed. Build files cannot be regenerated correctly.
[Finished]
the path: "C:/dev/vcpkg/vcpkg-master/installed/x64-windows/include" exists and has asio, fmt, and restinio dirs along with asio.hpp and http_parser.h.
I have tried adding:
target_link_libraries(main PRIVATE unofficial::http_parser::http_parser) as vcpkg suggests when I install, but it gives me the same error just replaced restinio::restinio with unofficial::http_parser::http_parser.

Generate wasm file using emscripten

I want to compile SealPIR library using emscripten to generate a wasm file.
When using this command:
emcmake cmake .
I get this error:
CMake Error at CMakeLists.txt:19 (find_package):
By not providing "FindSEAL.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SEAL", but
CMake did not find one.
Could not find a package configuration file provided by "SEAL" (requested
version 3.2.0) with any of the following names:
SEALConfig.cmake
seal-config.cmake
Add the installation prefix of "SEAL" to CMAKE_PREFIX_PATH or set
"SEAL_DIR" to a directory containing one of the above files. If "SEAL"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/home/Zied/webassembly/SealPIR/CMakeFiles/CMakeOutput.log".
emcmake: error: 'cmake . -DCMAKE_TOOLCHAIN_FILE=/home/Zied/webassembly/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DCMAKE_CROSSCOMPILING_EMULATOR="/home/Zied/webassembly/emsdk/node/14.15.5_64bit/bin/node"' failed (1)
SEAL is correctly installed. when i run the same command without emcmake it works just fine.
This is my CMakeList
cmake_minimum_required(VERSION 3.10)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(SealPIR VERSION 2.1 LANGUAGES CXX)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
add_executable(main
main.cpp
)
add_library(sealpir STATIC
pir.cpp
pir_client.cpp
pir_server.cpp
)
find_package(SEAL 3.2.0 EXACT REQUIRED)
target_link_libraries(main sealpir SEAL::seal)
When using a toolchain file for cross compiling, CMake will by default disable system libraries. It won't search into any directory to avoid finding files that is not compatible with the target system.
You think you didn't used a toolchain file? Think again! emcmake hides that from you. Look carefully at the error output.
Here you compiled the SEAL library, but you installed it in the default path, which is /usr/local.
We can tell CMake to explicitly search there, but I wouldn't recommend, but you can try if it works:
emcmake cmake . -CMAKE_PREFIX_PATH=/usr/local
The proper solution would be to create a directory with all the emscripten libraries in it:
# In the SEAL build directory
emcmake cmake .. -DCMAKE_INSTALL_PREFIX=/home/anblic/webassembly/install
Then after installing the libraries in that directory, you can set the prefix path in the same directory as the install path:
# Assuming you're in a build/ subdirectory
emcmake cmake .. -DCMAKE_PREFIX_PATH=/home/anblic/webassembly/install

Configure and Install required packages for a project

Coming from other package managers I expect to be able to do the following on a project:
configure the required libraries (in a config file, e.g. CMakelists.txt or nuget's packages.config)
install/upgrade all the required libraries
This seems to not be possible with vcpkg and CMake:
I managed to set up vcpkg and CMakefile (linux):
# in ternimal
vcpkg install <package>
# CMakeLists.txt
find_package(nlohmann_json CONFIG REQUIRED)
target_link_libraries(<app> <package>)
This however requires to manually install all the required libraries (vcpkg install <package>).
How can I list the required packages and have vcpkg or CMake managed them as required (e.g. automatically install them if they are missing)?
I've recently spent some time working with CMake and vcpkg. I dislike the typical approach of managing vcpkg and its installed packages separately from my CMake projects, so I wrote some CMake scripts to handle vcpkg during the CMake build process.
The CMake script to install vcpkg is primarily a call to ExternalProject_Add.
# ./vcpkg_utilities.cmake (part 1)
include(ExternalProject)
function(get_vcpkg)
ExternalProject_Add(vcpkg
GIT_REPOSITORY https://github.com/microsoft/vcpkg.git
CONFIGURE_COMMAND ""
INSTALL_COMMAND ""
UPDATE_COMMAND ""
BUILD_COMMAND "<SOURCE_DIR>/bootstrap-vcpkg.sh"
)
ExternalProject_Get_Property(vcpkg SOURCE_DIR)
set(VCPKG_DIR ${SOURCE_DIR} PARENT_SCOPE)
set(VCPKG_DEPENDENCIES "vcpkg" PARENT_SCOPE)
endfunction()
The script to have vcpkg install a package requires a custom command and target.
# ./vcpkg_utilities.cmake (part 2)
function(vcpkg_install PACKAGE_NAME)
add_custom_command(
OUTPUT ${VCPKG_DIR}/packages/${PACKAGE_NAME}_x64-linux/BUILD_INFO
COMMAND ${VCPKG_DIR}/vcpkg install ${PACKAGE_NAME}:x64-linux
WORKING_DIRECTORY ${VCPKG_DIR}
DEPENDS vcpkg
)
add_custom_target(get${PACKAGE_NAME}
ALL
DEPENDS ${VCPKG_DIR}/packages/${PACKAGE_NAME}_x64-linux/BUILD_INFO
)
list(APPEND VCPKG_DEPENDENCIES "get${PACKAGE_NAME}")
set(VCPKG_DEPENDENCIES ${VCPKG_DEPENDENCIES} PARENT_SCOPE)
endfunction()
Getting the main project linked to vcpkg appropriately (via toolchain file) requires vcpkg to be available when the main project is configured, so the main project is configured as an ExternalProject.
# /CMakeLists.txt
cmake_minimum_required(VERSION 3.17)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
project(top LANGUAGES CXX)
include(vcpkg_utilities)
get_vcpkg()
vcpkg_install(nlohmann_json)
include(ExternalProject)
set_property(DIRECTORY PROPERTY EP_BASE main_projectname)
ExternalProject_Add(main_projectname
DEPENDS ${VCPKG_DEPENDENCIES}
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/src
INSTALL_COMMAND ""
CMAKE_ARGS --no-warn-unused-cli;
-DCMAKE_TOOLCHAIN_FILE=${VCPKG_DIR}/scripts/buildsystems/vcpkg.cmake
)
Using this structure, CMake will manage the installation of both vcpkg and packages maintained by it.
Note that this is a point solution. I have a more generalized template for this in my Github that covers Windows and Linux, and allows the use of a separately-maintained vcpkg instance.
I've done something similar in my projects using ExternalProject_Add.
Code will be similar to the below pattern (I've replaced my dependency with your)
find_package(nlohmann_json CONFIG) # make package not REQUIRED to avoid error...
if(NOT NLOHMANN_JSON_FOUND) # or whatever variable indicating _FOUND
...
# here ExternalProject_Add from https://github.com/nlohmann/json.git
# using specific tag...
...
ExternalProject_Get_Property(... INSTALL_DIR)
# create imported target here similar to nlohmann_json, as if we found it
...
else()
# We've found lib already installed... will use it...
...
endif()
Another option can be using FetchContent, but I haven't tried it yet.

cmake does not find qt 5.1.1

I just installed the Qt 5.1.1 for Windows 32-bit (MinGW 4.8, OpenGL) and tried to add it to my cmake. But CMake just does not want to find it and i dont know why. What am i missing? Do i need to set an environment variable or something?
Here is my cmake :
cmake_minimum_required( VERSION 2.8.11 )
PROJECT(Blemmer)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# Detect and add SFML
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules" ${CMAKE_MODULE_PATH})
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib )
find_package(SFML REQUIRED system window graphics network audio)
# The QUIET option disables messages if the package cannot be found.
FIND_PACKAGE(Qt5Widgets)
add_subdirectory(Entity)
add_subdirectory(Engine)
add_subdirectory(Game)
add_executable(Blemmer main.cpp)
include_directories(${SFML_INCLUDE_DIR} ${PROJECT_SOURCE_DIR})
target_link_libraries(Blemmer ${SFML_LIBRARIES} Game Engine Qt5::Widgets)
and this is the output of cmake-gui :
CMake Warning at CMakeLists.txt:14 (FIND_PACKAGE):
By not providing "FindQt5Widgets.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"Qt5Widgets", but CMake did not find one.
Could not find a package configuration file provided by "Qt5Widgets" with
any of the following names:
Qt5WidgetsConfig.cmake
qt5widgets-config.cmake
Add the installation prefix of "Qt5Widgets" to CMAKE_PREFIX_PATH or set
"Qt5Widgets_DIR" to a directory containing one of the above files. If
"Qt5Widgets" provides a separate development package or SDK, be sure it has
been installed.
I successly build my GUI on MacOSX 10.10 by exporting Linux environment variables
$ brew install qt5
$ ls /usr/local/opt/qt5/lib/cmake/Qt5Widgets/Qt5WidgetsConfig.cmake
$ /usr/local/opt/qt5/lib/cmake/Qt5Widgets/Qt5WidgetsConfig.cmake
$ export CMAKE_PREFIX_PATH=/usr/local/opt/qt5/
$ cd ./build
$ cmake ../CMakeLists.txt
$ make -j8
Acroding to http://www.cmake.org/cmake/help/v3.0/variable/CMAKE_PREFIX_PATH.html, the cmake function FIND_LIBRARY() will appends /lib to each of the directories. So done.
You need to set the CMAKE_PREFIX_PATH to the Qt installation.
See http://doc.qt.io/qt-5/cmake-manual.html
Fixed it with the following in a CMakeLists.txt file:
set(CMAKE_PREFIX_PATH $ENV{HOME}/Qt5.5.0/5.5/gcc_64)
For me, the context ended up something like:
# Ubuntu 14.04 LTS, CMake 2.8.12.2
wget http://download.qt.io/official_releases/qt/5.5/5.5.0/qt-opensource-linux-x64-5.5.0.run
chmod u+x qt-opensource-linux-x64-5.5.0.run
./qt-opensource-linux-x64-5.5.0.run
# Follow GUI prompts, installed to default location