I'm trying to build a C++ project with Conan to download the libraries, but the problem is that I can't build it since Asio throw error on it's own functions.
Here is the result of the build : https://pastebin.com/WQ2bFHvm
I'm going to share you my configuration :
//Conan Profile
[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=12.0
os=Macos
os_build=Macos
[options]
[build_requires]
[env]
conanfile.txt
//conanfile.txt
[requires]
asio/1.20.0
boost/1.77.0
libbacktrace/cci.20210118
sfml/2.5.1#bincrafters/stable
[options]
libstd:compiler.libcxx=libstdc++11
[generators]
cmake
cmake_find_package
CMakeLists.txt :
//CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(R-Type)
# conan
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
include(build/conanbuildinfo.cmake)
conan_basic_setup()
# Package
find_package(asio 1.20.0 REQUIRED)
find_package(Boost 1.77.0 REQUIRED)
find_package(SFML 2.5.1 COMPONENTS graphics window system REQUIRED)
# .cmake files
include(./rtype/client/build.cmake)
include(./rtype/server/build.cmake)
include(./ecs-engine/build.cmake)
include(./graphics/build.cmake)
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
include(build/conanbuildinfo.cmake)
conan_basic_setup()
include_directories(${CMAKE_INCLUDE_PATH})
find_package(asio 1.19.2 REQUIRED)
find_package(SFML 2.5.1 COMPONENTS window graphics system audio REQUIRED)
set(ECS_ENGINE_DIR ./ecs-engine/)
set(GRAPHICS_DIR ./graphics/)
set(RTYPE_CLIENT_DIR ./rtype/client/)
set(RTYPE_SERVER_DIR ./rtype/server/)
build_engine()
set(ECS_ENGINE_INCLUDES INCLUDE_DIR)
build_graphics()
build_server()
build_client()
Server cmake build :
//build.cmake
set(RTYPE_SERVER_EXECUTABLE rtype_server)
set(RTYPE_SERVER_DIR ./rtype/server/)
macro(build_server)
set(SOURCE_DIR ${RTYPE_SERVER_DIR}/sources)
set(INCLUDE_DIR ${RTYPE_SERVER_DIR}/includes)
include_directories(${CMAKE_INCLUDE_PATH} ${INCLUDE_DIR})
add_executable(${RTYPE_SERVER_EXECUTABLE}
${SOURCE_DIR}/main.cpp
${SOURCE_DIR}/UDP.cpp
)
target_link_libraries(${RTYPE_SERVER_EXECUTABLE} ${CONAN_LIBS})
endmacro()
And finally here are the commands I run to build the project :
rm -rf build
mkdir build && cd build
conan install .. --build=missing
cmake .. -G "Unix Makefiles"
cmake --build .
I've tried to install the libraries locally but it does not work, do you guys have any idea on what I'm missing ?
Related
Edit: Solution at bottom
Here is my CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(game)
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
)
# Conan Requirements
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(game ${SOURCES})
find_package(SDL2 REQUIRED)
find_package(sol2 REQUIRED)
target_compile_options( game PRIVATE
$<$<CONFIG:Debug>:
-fsanitize=address,leak
>
)
target_link_options( game PRIVATE
$<$<CONFIG:Debug>:
-fsanitize=address,leak
>
)
target_compile_features(game
PRIVATE
cxx_std_20
)
target_link_libraries(game PRIVATE
SDL2::SDL2
sol2::sol
)
Here is my conanfile.txt
[requires]
lua/5.4.4
sdl/2.0.20
[generators]
cmake
cmake_find_package
CMakeDeps
CMakeToolchain
I get the following error:
CMake Error at CMakeLists.txt:16 (find_package):
By not providing "Findsol2.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "sol2", but
CMake did not find one.
Could not find a package configuration file provided by "sol2" with any of
the following names:
sol2Config.cmake
sol2-config.cmake
Add the installation prefix of "sol2" to CMAKE_PREFIX_PATH or set
"sol2_DIR" to a directory containing one of the above files. If "sol2"
provides a separate development package or SDK, be sure it has been
installed.
I am building using the following methods:
conan install . --install-folder build --build=missing
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -S . -B build -GNinja
cmake --build build
It's odd because I'm only getting the error about sol2 and not SDL
edit: SOLUTION IS:
CMakeLists.txt file
cmake_minimum_required(VERSION 3.20)
project(game)
set(SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
)
# Conan Requirements
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(game ${SOURCES})
find_package(SDL2 REQUIRED)
find_package(sol2 REQUIRED)
target_compile_options( game PRIVATE
$<$<CONFIG:Debug>:
-fsanitize=address,leak
>
)
target_link_options( game PRIVATE
$<$<CONFIG:Debug>:
-fsanitize=address,leak
>
)
target_compile_features(game
PRIVATE
cxx_std_20
)
target_link_libraries(game PRIVATE
SDL2::SDL2
sol2::sol2
)
conanfile.txt is
[requires]
sol2/3.3.0
sdl/2.0.20
[generators]
cmake
cmake_find_package
CMakeDeps
CMakeToolchain
build script is
#!/usr/bin/sh
conan install . --install-folder build --build=missing
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -S . -B build -GNinja
I have prepared a simple reproductive draft of my problem.
conanfile.txt:
[requires]
grpc/1.48.0
[generators]
cmake_paths
CMakeLists.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 3.18.3)
PROJECT(GRPC_FIND_PACKAGE_TEST)
# Default values
IF(NOT CMAKE_BUILD_TYPE
OR
(
NOT ${CMAKE_BUILD_TYPE} MATCHES "Debug"
AND NOT ${CMAKE_BUILD_TYPE} MATCHES "Release"
)
)
#SET(CMAKE_BUILD_TYPE Debug)
MESSAGE(FATAL_ERROR "Build type is unknown!")
ENDIF()
SET(BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}")
# Conan initialization command
SET(CONAN_INITIALIZATION_COMMAND
conan install "${CMAKE_CURRENT_LIST_DIR}" -s build_type=${CMAKE_BUILD_TYPE} --build=missing
)
# Executes conan initialization command
EXECUTE_PROCESS(
COMMAND ${CONAN_INITIALIZATION_COMMAND}
WORKING_DIRECTORY "${BUILD_DIR}"
RESULT_VARIABLE CMD_RESULT_CODE
ERROR_VARIABLE CMD_ERROR
COMMAND_ECHO STDOUT
)
INCLUDE(${BUILD_DIR}/conan_paths.cmake)
# Find Protobuf installation
# Looks for protobuf-config.cmake file installed by Protobuf's cmake installation.
set(protobuf_MODULE_COMPATIBLE TRUE)
find_package(Protobuf REQUIRED)
message(STATUS "Using protobuf ${Protobuf_VERSION}")
# Find gRPC installation
# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")
Issue
For some reason, FIND_PACKAGE cannot find the grpc package.
I had also error with:
find_package(Protobuf CONFIG REQUIRED)
I had to remove "CONFIG" and it started detecting this package properly.
What's going on? what's the problem?
I wanted to use DearImGui therefore I needed to either copy ImGui into the project or use a package manager, so I chose the latter. I'm currently using Conan as a my package manager, the file looks like this:
conanfile.txt
[requires]
boost/1.79.0
imgui/1.88
glad/0.1.36
glfw/3.3.7
[generators]
cmake_find_package
cmake_paths
CMakeDeps
CMakeToolchain
It has all the dependancies as a normal ImGui project would need as well as boost which had been downloaded as a binary previously and works fine, using just a normal header like #include <boost/asio.hpp>. I figure this happens because it was aleady installed.
I have a basic file structure that looks like this, prebuild:
conanfile.txt
CMakeLists.txt
src -
main.cpp
With this main CMakeLists I set up a linker with conan and simple setup instructions like the project name, executable, and the libraries
cmake_minimum_required(VERSION 3.23)
project(RenderCam CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(${CMAKE_CURRENT_SOURCE_DIR}/build/conan_paths.cmake)
add_executable(${PROJECT_NAME} src/main.cpp)
find_package(Boost 1.79.0 REQUIRED COMPONENTS thread system filesystem)
if(TARGET boost::boost)
target_link_libraries(${PROJECT_NAME} boost::boost)
endif()
find_package(glfw3 3.3 REQUIRED)
if(TARGET glfw)
message("Found GLFW")
target_link_libraries(${PROJECT_NAME} glfw)
endif()
find_package(imgui 1.88 REQUIRED)
if(TARGET imgui::imgui)
message("found imgui")
target_link_libraries(${PROJECT_NAME} imgui::imgui)
endif()
After running two commands (conan install .. and cmake .. -DCMAKE_BUILD_TYPE=Release) in the new build directory the CMake build responds with all the found messages for the project as well as the location of the files, which should be expected. Though when add the #include <imgui.h> to the main.cpp it states the file is not found which shouldn't be if I have linked it. On the other hand #include <boost/asio.hpp> has no errors and I can go upon my day with all of the commands. I would just like to include the directories and have tried multiple steps and guides before I took it here. For further reference, this is my conanprofile :
Configuration for profile default:
[settings]
os=Macos
os_build=Macos
arch=x86_64
arch_build=x86_64
compiler=apple-clang
compiler.version=13
compiler.libcxx=libc++
build_type=Release
[options]
[conf]
[build_requires]
[env]
Don't mix up mutually exclusive generators like cmake_find_package vs CMakeDeps, or cmake_paths vs CMakeToolchain.
Here is a basic example of non-intrusive integration of conan:
conanfile.txt
[requires]
boost/1.79.0
imgui/1.88
glfw/3.3.7
[generators]
CMakeToolchain
CMakeDeps
CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(RenderCam CXX)
find_package(Boost 1.79.0 REQUIRED thread system filesystem)
find_package(glfw3 3.3 REQUIRED)
find_package(imgui 1.88 REQUIRED)
add_executable(${PROJECT_NAME} src/main.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE Boost::headers Boost::thread Boost::system Boost::filesystem glfw imgui::imgui)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
Install dependencies, configure & build:
mkdir build && cd build
conan install .. -s build_type=Release -b missing
cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release
Before saying anything: Yes, I googled and searched for a long time before asking this here so 99% the solution of other similar questions doesn't work for me.
I have an opengl application that uses the following libraries:
glfw
imgui
glad
stb
assimp
glm
filebrowser (an extension of imgui for dialog boxes)
all these libraries are in a folder called external each one in its dir.
Moreover, glfw, assimp, glm are git submodules of my repo so they're downloaded when i clone my repo with git clone --recursive mygitrepo.
You can have a better understanding of the structure of the project looking at my git repo.
My idea was to use the add_subdirectories to make them compile with their own CMakeLists and my main one looks like this:
cmake_minimum_required(VERSION 3.21.3)
project(Reskinner)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_VERBOSE_MAKEFILE ON)
add_executable(${PROJECT_NAME} Main.cpp)
add_subdirectory(external/glfw)
add_subdirectory(external/assimp)
add_subdirectory(external/glad)
add_subdirectory(external/imgui)
add_subdirectory(external/stb)
add_subdirectory(external/glm)
add_subdirectory(external/FileBrowser)
add_subdirectory(src)
find_package(OpenGL REQUIRED)
target_include_directories(${PROJECT_NAME}
PUBLIC external/glfw/include
PUBLIC external/assimp/include
PUBLIC external/glm
PUBLIC external
PUBLIC src
)
target_link_libraries(${PROJECT_NAME} glfw glad imgui stb glm Engine assimp FileBrowser)
The project was developed with visual studio on windows and I want to compile it on linux without using visualstudio. The cmake doesn't give me any errors but when i run the make command it gives me this error:
#include <assimp/quaternion.h> there's no file or directory with this name.
like i didn't put the assimp include folder in the cmake (but i did).
Do you have any idea how to make it works? I want to make a bash script to install all the dependencies and tools needed like xorg-dev, build-essential, git, cmake, make etc. So if there's any simple fix using some bash commands it's ok for me.
I figured out how to fix it. I just installed conan and used it to download and find assimp. So I removed assimp, glm, glfw and glad from 'external' folder and just added a conanfile.txt.
Here the conanfile.txt:
[requires]
assimp/5.2.2
glfw/3.3.7
glm/0.9.9.8
glad/0.1.35
[generators]
cmake_find_package
cmake_paths
my main CMakeLists.txt now it's as following:
cmake_minimum_required(VERSION 3.21.3)
project(Reskinner)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_VERBOSE_MAKEFILE ON)
add_executable(${PROJECT_NAME} Main.cpp)
include(${CMAKE_BINARY_DIR}/conan_paths.cmake)
# Retrieve conan.cmake
if (NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/master/conan.cmake" "${CMAKE_BINARY_DIR}/conan.cmake")
endif ()
include("${CMAKE_BINARY_DIR}/conan.cmake")
conan_cmake_run(CONANFILE "conanfile.txt" BASIC_SETUP UPDATE BUILD missing)
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR})
find_package(OpenGL REQUIRED)
find_package(glad REQUIRED)
find_package(glfw3 REQUIRED)
find_package(glm REQUIRED)
find_package(assimp REQUIRED)
add_subdirectory(external/stb)
add_subdirectory(external/imgui)
add_subdirectory(external/FileBrowser)
add_subdirectory(src)
file(MAKE_DIRECTORY
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Shaders")
function(install_file_to_bin file_name)
file(INSTALL "${CMAKE_SOURCE_DIR}/Shaders/${file_name}" DESTINATION "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/Shaders")
endfunction()
install_file_to_bin(1.model_loading.fs)
install_file_to_bin(1.model_loading.vs)
install_file_to_bin(4.1.fshader.fs)
install_file_to_bin(4.1.vshader.vs)
install_file_to_bin(animated_model_loading.fs)
install_file_to_bin(animated_model_loading.gs)
install_file_to_bin(animated_model_loading.vs)
install_file_to_bin(bb.vs)
install_file_to_bin(bb.fs)
install_file_to_bin(default.frag)
install_file_to_bin(default.fs)
install_file_to_bin(default.geom)
install_file_to_bin(default.vert)
install_file_to_bin(default.vs)
install_file_to_bin(floor.fs)
install_file_to_bin(floor.vs)
install_file_to_bin(framebuffer.frag)
install_file_to_bin(framebuffer.vert)
install_file_to_bin(grey_model.fs)
install_file_to_bin(grey_model.vs)
install_file_to_bin(hover.fs)
install_file_to_bin(hover.vs)
install_file_to_bin(influence_of_single_bone.fs)
install_file_to_bin(influence_of_single_bone.vs)
install_file_to_bin(mouse_shader.fs)
install_file_to_bin(mouse_shader.vs)
install_file_to_bin(normal_visualizer.fs)
install_file_to_bin(normal_visualizer.gs)
install_file_to_bin(normal_visualizer.vs)
install_file_to_bin(no_lighting_shader.fs)
install_file_to_bin(no_lighting_shader.vs)
install_file_to_bin(num_bones_visualization.fs)
install_file_to_bin(num_bones_visualization.vs)
install_file_to_bin(screen_shader.fs)
install_file_to_bin(screen_shader.vs)
install_file_to_bin(selected.fs)
install_file_to_bin(selected.vs)
install_file_to_bin(smooth_lighting_shader.fs)
install_file_to_bin(smooth_lighting_shader.vs)
install_file_to_bin(wireframe.vs)
install_file_to_bin(wireframe.fs)
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE 1)
set(CMAKE_LINK_WHAT_YOU_USE 1)
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
include_directories(
${OpenGL_INCLUDE_DIRS}
${glad_INCLUDE_DIRS}
${glfw3_INCLUDE_DIRS}
${glm_INCLUDE_DIRS}
${assimp_INCLUDE_DIRS}
external
src
)
target_link_libraries(${PROJECT_NAME}
${OpenGL_LIBRARIES}
${glad_LIBRARIES}
${glfw3_LIBRARIES}
${glm_LIBRARIES}
stb
${assimp_LIBRARIES}
imgui
FileBrowser
Engine
)
Some notes that can be usefull for other people having this troubles:
Assimp has some linking problem when used with conan because it seems that it doesn't download everything but just what you need so it works for the #include but it complains in the linking phase. Adding the following 3 rows fixed the problem:
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE 1)
set(CMAKE_LINK_WHAT_YOU_USE 1)
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
I have a script to install everything you need on linux and install the stuff with conan, launch the cmake etc.. Even if I install the conan packages with the command conan install .. [...] I need the conan.cmake file so the lines at the beginning looking for the conan.cmake files fixed a lot of problems
The shell scripts is the following:
#!/bin/bash
sudo apt-get update
sudo apt-get install git
sudo apt-get install xorg-dev
sudo apt-get install make
sudo apt-get install cmake
sudo apt-get install build-essential
cd build
rm -rf *
conan install .. --settings os="Linux" --settings compiler="gcc" --settings compiler.version=11 --build missing
cmake -S .. -B . -D CMAKE_BUILD_TYPE=Release
make
cd build
Hope this can help you
I want to build Google glog with CMake as part of bigger project (solution, in words of Visual Studio). What I want to have as a result:
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug
-DCMAKE_INSTALL_PREFIX:PATH=xxx {MAIN CMakeLists.txt location}
cmake --build . --target install --config Debug
will build solution in Debug configuration and install files to xxx folder.
Ok, glog is sub project of main solution:
add_subdirectory(third_party/glog_0.3.4)
On Windows everything is ok (see CMakeLists.txt): everything works as expected.
To build glog on Linux, I need to configure .h.in files too (among other work). CMake configure_file does not works: I have .h files but they contain #undef's only. But glog's ./configure works fine, so I found that ExternalProject_Add() may help:
if(UNIX)
include(ExternalProject)
ExternalProject_Add(glog
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/configure
CMAKE_GENERATOR 'Unix Makefiles'
BUILD_COMMAND ${MAKE})
endif()
And cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX:PATH=xxx . works fine, but cmake --build . --target install --config Debug will give me:
make: *** No rule to make target 'install'. Stop.
If I invoke cmake --build . --config Debug, then it will build and install glog to /usr/local/lib. Next try:
if(UNIX)
include(ExternalProject)
get_filename_component(glog_absolute_install_dir ${CMAKE_INSTALL_PREFIX} ABSOLUTE)
ExternalProject_Add(glog
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}
CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/configure --prefix=${glog_absolute_install_dir}
CMAKE_GENERATOR 'Unix Makefiles'
BUILD_COMMAND ${MAKE}
INSTALL_DIR ${glog_absolute_install_dir}
INSTALL_COMMAND "${MAKE}")
endif()
will not install files to xxx and just build it to glog-prefix/src/glog-build/.
Ok, I have no idea how to make it work.. And how to
specify install dir
lib build type (static/shared)
configure type (Debug/Release) - not sure that now it works
On Windows, according to glog's documentation, for 2nd case I do next:
add_library(${lib_name} ${lib_type} ${src_files})
if(build_shared_lib)
add_definitions(-DLIBGLOG_EXPORTS)
else()
add_definitions(-DGOOGLE_GLOG_DLL_DECL=)
endif()
Thanks for any help
I will show you by example, the below is my project structure:
The file FindGLog.cmake in the directory cmake is used to find glog, it contents :
# - Try to find Glog
#
# The following variables are optionally searched for defaults
# GLOG_ROOT_DIR: Base directory where all GLOG components are found
#
# The following are set after configuration is done:
# GLOG_FOUND
# GLOG_INCLUDE_DIRS
# GLOG_LIBRARIES
include(FindPackageHandleStandardArgs)
if (NOT DEFINED GLOG_ROOT)
message("set GLOG_ROOT========================")
set (GLOG_ROOT /usr /usr/local /usr/include/)
endif (NOT DEFINED GLOG_ROOT)
#set(GLOG_ROOT_DIR "" CACHE PATH "Folder contains Google glog")
find_path(GLOG_INCLUDE_DIR glog/logging.h
PATHS
${GLOG_ROOT_DIR}
PATH_SUFFIXES
src)
find_library(GLOG_LIBRARY glog libglog
PATHS
${GLOG_ROOT_DIR}
PATH_SUFFIXES
.libs
lib
lib64)
find_package_handle_standard_args(GLOG DEFAULT_MSG
GLOG_INCLUDE_DIR GLOG_LIBRARY)
if(GLOG_FOUND)
set(GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIR})
set(GLOG_LIBRARIES ${GLOG_LIBRARY})
message("GLOG_INCLUDE_DIRS ${GLOG_INCLUDE_DIRS}===========")
message("GLOG_LIBRARY ${GLOG_LIBRARY}===========")
endif()
The main CMakeLists.txt use the above FindGLog.cmake to find glog:
cmake_minimum_required(VERSION 3.5)
project(my_caffe)
set(CMAKE_CXX_STANDARD 11)
# find glog
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(GLog REQUIRED)
set(SOURCE_FILES main.cpp)
add_executable(my_caffe_test ${SOURCE_FILES})
# link glog
target_link_libraries(my_caffe_test
${GLOG_LIBRARIES}
)
cited from:https://davidstutz.de/running-google-glog-on-travis-ci/
Nowadays (presumably this will be in glog release 0.3.5), there is a CMakeLists.txt included with glog, so no longer any need for ExternalProject.