How do I include the assimp library in the project via CMake?

Viewed 36

I followed the asssimp library's installation guide, which used Visual Studio and did all the necessary steps to include it in the project through the GUI when I did everything through pure CMake and MinGW.

I need to include headers and two library files in my project: assimp-[...].dll and assimp-[...].lib

My assimp proj hierarchy

I started to figure out how to write my own CMakeLists.txt and came up with this:

cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(Assimp)

add_library(assimp SHARED IMPORTED GLOBAL)

file(GLOB_RECURSE ROOT_SOURCE "./assimp/*.cpp")
file(GLOB_RECURSE ROOT_INLINE "./assimp/*.inl")
file(GLOB_RECURSE ROOT_HPP "./assimp/*.hpp")
file(GLOB_RECURSE ROOT_HEADER "./assimp/*.h")
file(GLOB_RECURSE COMPILER_HEADER "./assimp/Compiler/*.h")
file(GLOB_RECURSE PORT_HEADER "./assimp/port/AndroidJNI/*.h")

source_group("Compiler Files" FILES ${COMPILER_HEADER})
source_group("Port Files" FILES ${PORT_HEADER})

include(GNUInstallDirs)

if(BUILD_STATIC_LIBS)
    add_library(assimp_static STATIC
            ${ROOT_SOURCE}    ${ROOT_INLINE}    ${ROOT_HPP}
            ${ROOT_HEADER}    ${COMPILER_HEADER}    ${PORT_HEADER}
            )
    target_link_libraries(assimp_static PUBLIC assimp)
    add_library(assimp::assimp_static ALIAS assimp_static)
endif()

if(BUILD_SHARED_LIBS)
    add_library(assimp_shared SHARED
            ${ROOT_SOURCE}    ${ROOT_INLINE}    ${ROOT_HPP}
            ${ROOT_HEADER}    ${COMPILER_HEADER}    ${PORT_HEADER}
            )
    target_link_libraries(assimp_shared PUBLIC assimp)
    add_library(assimp::assimp_shared ALIAS assimp_shared)
endif()

set_property(TARGET assimp PROPERTY IMPORTED_LOCATION "${PROJECT_SOURCE_DIR}/external/assimp/lib/assimp-vc143-mtd.dll")
set_property(TARGET assimp PROPERTY IMPORTED_IMPLIB "${PROJECT_SOURCE_DIR}/external/assimp/lib/assimp-vc143-mtd.lib")

After that I'm linking it in the main CMakeLists.txt:

add_executable(${PROJECT_NAME} [src code files here])
add_subdirectory(external/assimp)
target_link_libraries(${PROJECT_NAME} PRIVATE assimp)

But after that, I can't see any header from this library, as well as its directory, and I'm not even sure if the dynamic libraries from the "lib" folder are included correctly.

What am I doing wrong?

0 Answers
Related