Troubles with CMake and Assimp - c++

I have the latest assimp source code (5.0.1 release), I have built it with CMake and installed using cmake --install. Now I am trying to add it to my CMake project: find_package(Assimp REQUIRED Assimp) - at this moment it configures fine. The problems started when I tried to add
target_link_libraries(
MyProj PRIVATE
Assimp::Assimp
)
And I get the following error:
[cmake] target "MyProj" links to target "Assimp::Assimp" but the target
[cmake] was not found. Perhaps a find_package() call is missing for an IMPORTED
[cmake] target, or an ALIAS target is missing?
After some research, I've tried target_link_libraries(MyProj PRIVATE ${ASSIMP_LIBRARIES}), this time I got a compile error, and when I displayed the value of the ${ASSIMP_LIBRARIES} variable (command: message("${ASSIMP_LIBRARIES}")) I got: assimp-vc142-mt.dll - it contains .dll name, even without full path. Have a lot of troubles with assimp, could anyone suggest a solution?

Without having any knowledge of assimp, I think what you want is this:
target_link_libraries(MyProj PRIVATE assimp::assimp)
As far as I know, CMake target names are case sensitive and the assimp::assimp alias target is created here with lowercase a.

Related

I use Cmake to make project, but it called error when generating : Target "xxxxxxx" links to: igl::core , but the target was not found

Configuring done
CMake Error at CMakeLists.txt:5 (target_link_libraries):
Target "101_GlyphRendering_bin" links to:
igl::core
but the target was not found. Possible reasons include:
* There is a typo in the target name.
* A find_package call is missing for an IMPORTED target.
* An ALIAS target is missing.
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(101_GlyphRendering)
add_executable(${PROJECT_NAME}_bin main.cpp)
target_link_libraries(${PROJECT_NAME}_bin PUBLIC igl::core igl::glfw igl::opengl tutorials)
I opened the project and built it, an error occurred:
C1083 Cannot open include file:'directional/directional_viewer.h':No such file or dictory
enter image description here
I'm not sure what exactly is your problem, but speaking of
C1083 Cannot open include file:'directional/directional_viewer.h':No
such file or directory
If you want to manually link libraries, you need to also include headers from that libraries. To do such, use
target_include_directories(<target> PUBLIC <include_folder_dir>)
where <target> is your ${PROJECT_NAME}_bin and <include_folder_dir> is folder with headers of library you are linking to.

cmake error [CMake Error at SDK/Util/CMakeLists.txt:132 (add_library)]

The following error occurs when the cmake that was running in a Windows environment is performed on Linux:
Error message is
(CMake GUI generate button click error message):
CMake Error at SDK/A/Util/CMakeLists.txt:132 (add_library):
Target "Util" links to target "VSI::GL" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
CMake Error at SDK/B/Vis/CMakeLists.txt:424 (add_library):
Target "Util" links to target "VSI::GL" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
The SDK/A/Util/CMakeLists.txt:132 is:
add_library(Util ${STATIC_OR_SHARED} ${UTIL_PROJECT_FILES})
set_target_properties(Util PROPERTIES
FOLDER "SDK"
PROJECT_LABEL "SDK - Util"
)
ApplySDKVersion(Util)
target_include_directories(Util PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/..>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(Util PUBLIC Vis Data Core)
target_link_libraries(Util PRIVATE VSI::GL)
if(UTIL_SHARED)
target_compile_definitions(Util PRIVATE Util_LIB_EXPORT_SHARED)
else()
target_compile_definitions(Util PUBLIC Util_LIB_EXPORT_STATIC)
endif()
Does anyone know how to fix this?
Thanks for reading!.
solved.
It was a problem with the external program.
In my case it was an OpenGL version issue.
thank you for read!
additional infomation
I was using vmware.
vmware supports only openGL version 2.1 (not pro version)
So, after installing Centos myself, update the opengl version, the program worked fine.
I hope it helps a lot!

Add a subproject by CMake

Apache Arrow submodule is stored at thirdparty/apache_arrow/cpp, so my main CMakeLists.txt looks like
cmake_minimum_required(VERSION 3.0.0)
project(arrow_parcer VERSION 0.1.0)
add_subdirectory(src)
add_subdirectory(thirdparty/apache_arrow/cpp)
At the thirdparty/apache_arrow stored whole Apache Arrow project.
When I'm trying to build project, last output lines is follow:
[cmake] CMake Error: INSTALL(EXPORT) given unknown export "arrow_targets"
[cmake] Generating done
[cms-driver] Error during CMake configure: [cmake-server] Failed to compute build system.
Apache Arrow can be easily builded by CMakeLists.txt at /cpp folder, but why there is an error if I trying to include it by add_subdirectory?
Apache Arrow C++ is not meant to be built using add_subdirectory, instead you should use CMake's ExternalProject_Add facility to build it:
ExternalProject_Add(arrow_ep
URL "https://www.apache.org/dist/arrow/arrow-0.15.1/apache-arrow-0.15.1.tar.gz"
SOURCE_SUBDIR cpp)
Instead of using URL you can also use different providers like GIT_REPOSITORY, too.
If you don't really need to setup the installation, here is a hack-y way to do this. In the CMakeLists.txt adding arrow's source dir, you define your own install.
function(install)
endfunction()
add_subdirectory(${arrow_SOURCE_DIR}/cpp ${arrow_BINARY_DIR})

GLFW directory not found with CMake and vcpkg

I have been unable to figure out how to get CMake to find and set correct GLFW CMake constants when using CMake in VS2017. Any help will be greatly appreciated :).
I downloaded glfw3 through Microsoft's vcpkg tool. I have checked that files do physically exist in the directory that vcpkg puts them in (~\vcpkg\installed\x86-windows\include). I set up my CMakeSettings.json as per their docs here. I used that tutorial as a basis for getting GLFW to be set up correctly.
I then use find_package(glfw3 REQUIRED) to find the glfw3 library. This does not spit out any errors. Actually the CMakeLists.txt doesn't complain at all. It's at the compile stage where it complains.
After that I add glfw3 with target_link_libraries(exe ${GLFW3_LIBRARIES}) to the executable.
Then when I try and build a simple example (including the header file), the compilation fails because it cannot find GLFW/glfw3.h.
The error from MSVC:
fatal error C1083: Cannot open include file: 'GLFW/glfw3.h': No such file or directory
Here is my CMakeLists.txt for added reference:
cmake_minimum_required(VERSION 3.7)
project(learn-opengl)
find_package(glfw3 REQUIRED)
add_executable(learn-opengl main.cpp)
target_link_libraries(learn-opengl ${GLFW3_LIBRARIES})
GLFW3_LIBRARIES I got from glfw3Config.cmake by snooping around what vcpkg puts in the installed directory (~\vcpkg\installed\x86-windows\share\glfw3)
And just in case, the main.cpp:
#include <GLFW/glfw3.h>
int main()
{
return 0;
}
I have tried calling cmake from the command line as well, but to no avail that didn't work either.
Am I missing something? Did I perhaps misunderstand something in vcpkg documentation? I have really no idea what I am missing... :/ I should say, in addition, that I am fairly new to CMake as well.
Reformulating my previous comment as answer:
You should add the imported target glfw to your target_link_libraries command instead of ${GLFW3_LIBRARIES}.
The find_package(glfw3) generates an import target glfw. By making your target learn-opengl dependent on this imported target you specify both the library to link with and the include directories to use.

Adding LLVM to my Cmake Project: Why are there hardcoded paths in LLVM's Cmake file?

I'm using LLVM/Clang in my C++ project. I can build and run everything fine with a Makefile.
I'm now trying to move to Cmake and I can't get things to work. Let me explain what I've done.
I'm following this tutorial:
http://llvm.org/docs/CMake.html#embedding
A relevant snippet from that webpage is:
From LLVM 3.5 onwards both the CMake and autoconf/Makefile build
systems export LLVM libraries as importable CMake targets.
Great! I'll go download LLVM 3.5 and I should be good to go. I went to the download page:
http://llvm.org/releases/download.html
and downloaded the pre-built binaries for Clang for Ubuntu 14.04 Linux.
Then, I added the following to my CMakeLists.txt file:
find_path (LLVM_DIR LLVM-Config.cmake
/home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake
)
message(STATUS "LLVM_DIR = ${LLVM_DIR}")
find_package(LLVM REQUIRED CONFIG)
(This is the same as the tutorial, except I set LLVM_DIR since it is currently in a non-standard location.)
When I run cmake, I get the following error:
[dev#beauty:/path/to/project/build (develop)] $ cmake ..
-- LLVM_DIR = /home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake
CMake Error at /home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake/LLVMConfig.cmake:50 (include):
include could not find load file:
/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/share/llvm/cmake/LLVMExports.cmake
Call Stack (most recent call first):
CMakeLists.txt:14 (find_package)
CMake Error at /home/dev/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake/LLVMConfig.cmake:53 (include):
include could not find load file:
/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/share/llvm/cmake/LLVM-Config.cmake
Call Stack (most recent call first):
CMakeLists.txt:14 (find_package)
So Cmake seems to be finding LLVM's Cmake file, but Cmake is complaining about some path starting with /home/ben/.
Indeed, it appears that LLVM's LLVMConfig.cmake file has some absolute paths in it that are not relevant for my machine. For example:
[dev#beauty:~/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu ] $ head ./share/llvm/cmake/LLVMConfig.cmake
# This file provides information and services to the final user.
set(LLVM_INSTALL_PREFIX "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install")
set(LLVM_VERSION_MAJOR 3)
set(LLVM_VERSION_MINOR 5)
set(LLVM_VERSION_PATCH 0)
set(LLVM_PACKAGE_VERSION 3.5.0)
set(LLVM_COMMON_DEPENDS )
Who's ben and what's he doing in this file? He shows up in a few more places:
[dev#beauty:~/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu ] $ grep ben ./share/llvm/cmake/LLVMConfig.cmake
set(LLVM_INSTALL_PREFIX "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install")
set(LLVM_INCLUDE_DIRS "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/include")
set(LLVM_LIBRARY_DIRS "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/lib")
set(LLVM_CMAKE_DIR "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/share/llvm/cmake")
set(LLVM_TOOLS_BINARY_DIR "/home/ben/development/llvm/3.5/final/Phase3/Release/llvmCore-3.5.0-final.install/bin")
Needless to say, those paths do not exist on my machine. I'm confused as to why these files have these paths in them? Am I supposed to run a tool or something to change these paths for my machine? Or do I need to change them all manually?
EDIT: Out of curiosity, I manually changed all those paths to point to paths on my machine:
[dev#beauty:~/Downloads/clang+llvm-3.5.0-x86_64-linux-gnu/share/llvm/cmake ] $ sed -i -e's/.home.ben.development.llvm.3.5.final.Phase3.Release.llvmCore-3.5.0-final.install/\/home\/dev\/Downloads\/clang+llvm-3.5.0-x86_64-linux-gnu/g' *
After that, Cmake no longer complained and my build proceeded.
I'd still like to know why I needed to do that.
Sounds like a LLVM bug. Feel free to enter it: http://llvm.org/bugs
We just have to build with 'Ninja' instead of 'Unix Makefiles' and that's all