Assimp isn't found by CMake - c++

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

Related

C++ file cannot find library linked with CMake

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

Cannot find "Findaws-lambda-runtime.cmake" on ubuntu18.04

Trying to build the hello world example, but the cmake always complain
By not providing "Findaws-lambda-runtime.cmake" in CMAKE_MODULE_PATH this
project has asked CMake to find a package configuration file provided by
"aws-lambda-runtime", but CMake did not find one.
Environment
OS : ubuntu18.04.3 LTS,64bits
install curl by : sudo apt-get install libcurl4-openssl-dev
install cmake by ubuntu software(cmake version 3.16.1)
Steps to build and install aws lambda cpp
git clone https://github.com/awslabs/aws-lambda-cpp.git
cd aws-lambda-cpp
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_INSTALL_PREFIX=${PWD}/install
make -j2
sudo make install
CmakeLists.txt(omit another part, want to make sure find_package works first)
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(aws_cpp_test LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/")
list(APPEND CMAKE_MODULE_PATH "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/")
find_package(aws-lambda-runtime REQUIRED)
add_executable(${PROJECT_NAME} "main.cpp")
I do not use the ec2 to build the project, how could I tell the cmake where should it find the aws-lambda-runtime?
Edit :
Based on the suggestion of Yevhenii Mamontov, I change the CMakeLists.txt to
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(aws_cpp_test LANGUAGES CXX)
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/")
set(CMAKE_PREFIX_PATH "${AWS_LAMBDA_CMAKE};${CMAKE_PREFIX_PATH}")
#check the prefix paths are correct or wrong
foreach(path ${CMAKE_PREFIX_PATH})
message("Path: " ${path})
endforeach(path)
find_package(aws-lambda-runtime REQUIRED)
But it come with different error message
CMake Error at
/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/aws-lambda-runtime-config.cmake:6
(include): include could not find load file:
/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/#CMAKE_PROJECT_NAME#-targets.cmake
I tried with different paths
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/install")
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/install/lib/aws-lambda-runtime/cmake")
and tried to do not add any new path, but all of them give the same error messages
Edit 2 :
Find a way to make it work
Remove the contents of /home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/aws-lambda-runtime-config.cmake
set path as set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/build/install/lib/aws-lambda-runtime/cmake")
However, this solution is awkward, should ask the cmake do not search from the path "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake" first
Edit 3:
The solution I written in Edit 2 do not work. It fail when I add
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME} PUBLIC AWS::aws-lambda-runtime)
Error messages are
Target "aws_cpp_test" links to target "AWS::aws-lambda-runtime" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
Could you try to set CMAKE_PREFIX_PATH just before the find_package?
Something like this:
set(AWS_LAMBDA_CMAKE "/home/yyyy/Qt/3rdLibs/aws-lambda-cpp/cmake/")
set(CMAKE_PREFIX_PATH "${AWS_LAMBDA_CMAKE};${CMAKE_PREFIX_PATH}")
The first set() creates a variable with the path to your lib cmake folder.
The second set() appends to CMAKE_PREFIX_PATH one more path to search for any package that you've indicated in find_package().
Find out the solution, all you need to do are set the path of the aws library installed.
Example:
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project(encoder LANGUAGES CXX)
set(AWS_LAMBDA_CMAKE ${CMAKE_CURRENT_SOURCE_DIR}/../../3rdLibs/aws-lambda-cpp/build/install/)
set(AWS_LAMBDA_CPP_SDK ${CMAKE_CURRENT_SOURCE_DIR}/../../3rdLibs/aws-sdk-cpp/build/install/)
set(CMAKE_PREFIX_PATH "${AWS_LAMBDA_CMAKE};${CMAKE_PREFIX_PATH};${AWS_LAMBDA_CPP_SDK}")
find_package(CURL REQUIRED)
find_package(aws-lambda-runtime REQUIRED)
find_package(AWSSDK COMPONENTS s3)
add_executable(${PROJECT_NAME} "main.cpp")
target_link_libraries(${PROJECT_NAME}
${CURL_LIBRARIES}
AWS::aws-lambda-runtime
${AWSSDK_LINK_LIBRARIES})
aws_lambda_package_target(${PROJECT_NAME})
You may need to install following libs on your ubuntu if you haven't
sudo apt-get install zlib1g-dev libssl-dev libcurl4-openssl-dev
I got the same error, the answer marked as solution worked pretty well, but I also found tha this works:
set(aws-lambda-runtime_DIR /lib/aws-lambda/lib64/aws-lambda-runtime/cmake/)
I am using CMake 3.13 and had the lambda runtime installed on "/lib/aws-lambda" when running tha cmake as instructed by the installation instructions:
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/lib/aws-lambda

adding boost library to clion on MacOsX

Hello i installed boost using comand
brew install boost
it installed 1.66.0 version
I edited CMakeLists in this way
cmake_minimum_required(VERSION 3.8)
project(fraction)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.cpp source/Fraction.cpp headers/Fraction.h headers/MyStack.h unitTest.cpp)
add_executable(fraction ${SOURCE_FILES})
set(BOOST_ROOT "/usr/local/Cellar/boost/1.66.0")
find_package(Boost 1.66.0)
if(NOT Boost_FOUND)
message(FATAL_ERROR "Could not find boost!")
endif()
I don't have any error, in file unitTest.cpp I want to write test and I'm trying to include this
#include <boost/test/unit_test.hpp>
but I got error "Cannot find 'boost'"
What I do wrong ?
Ok I find why it doesn't work, brew didn't link boost
on high sierra it should be in this way
if usr/local/include and usr/local/Frameworks don't exist it must be created by
sudo mkdir usr/local/include
sudo mkdir usr/local/Frameworks
after that we can chown usr/local/include by
sudo chown -R $(whoami) $(brew --prefix)/*

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

`make install` with CMake + SWIG + Python

I am writing a C++ library which can be used from both C++ and Python on Mac and Linux. So I have decided to use CMake and SWIG for my project.
As well described in the SWIG 2.0 documentation, combination of SWIG and CMake also works fine on my Mac.
http://www.swig.org/Doc2.0/SWIGDocumentation.html#Introduction_build_system
But I have a question about make install.
After typing cmake . and make, _example.so was successfully generated. But make install does not work, because the auto-generated Makefile does not have install target. I would like to know how I can add install target in the Makefile. I would like _example.so to be installed under site-packages directory on each system.
I would very appreciate it if anyone could tell me how to modify the CMake example written in the above link.
find_package(SWIG REQUIRED)
find_package(PythonLibs REQUIRED)
include(${SWIG_USE_FILE})
set(CMAKE_SWIG_FLAGS "")
include_directories(${PYTHON_INCLUDE_DIRS})
set_source_files_properties(target.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties(target.i PROPERTIES SWIG_FLAGS "-includeall")
swig_add_module(target python target.i ${SOURCES})
swig_link_libraries(target ${PYTHON_LIBRARIES})
execute_process(COMMAND python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()" OUTPUT_VARIABLE PYTHON_SITE_PACKAGES OUTPUT_STRIP_TRAILING_WHITESPACE)
install(TARGETS _target DESTINATION ${PYTHON_SITE_PACKAGES})
install(FILES ${CMAKE_BINARY_DIR}/src/target.py DESTINATION ${PYTHON_SITE_PACKAGES})
The CMake interface to make install is the CMake command install(). In your example, you could add an installation rule like this:
install(
TARGETS ${SWIG_MODULE_example_REAL_NAME}
# ... add other arguments to install() as necessary
)
Once there are any install() commands in a CMakeList, CMake will generate an install target callable as make install.