'Using assimp makes compilations 30 times slower

I'm using cmake and including assimp with the following two lines:

add_subdirectory(external/assimp)
target_link_libraries(${PROJECT_NAME} assimp)

I've also added #include <assimp/Importer.hpp> into a my cpp.

Usually the compilation takes ~2 seconds. However, if I actually use assimp in my code, such as adding the following line:

Assimp::Importer importer;

with no mention of assimp anywhere else, it jumps to ~55 seconds. Note that #include <assimp/Importer.hpp> is the present in both cases. Step [1/2] Building CXX object CMakeFiles/Project.dir/src/Project.cpp.obj takes the majority of time.

If I update the code, as long as assimp is used, recompilation will take another ~55 seconds to recompile.

I've tried putting the include into the precompiled header, but the behaviour is the same. What am I doing wrong? Why does it take so long?

I'm using CLion, but with gcc from msys2/mingw64 installation.

Here's the full cmake file:

cmake_minimum_required(VERSION 3.21)
project(PathTracer)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++ -static-libgcc")
set(CMAKE_CXX_STANDARD 23)

find_package(Vulkan REQUIRED)

add_executable(${PROJECT_NAME} src/main.cpp src/Project.h src/Project.cpp)

target_link_libraries(${PROJECT_NAME} Vulkan::Headers)

set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(external/glfw)
target_link_libraries(${PROJECT_NAME} glfw)

add_subdirectory(external/assimp)
target_link_libraries(${PROJECT_NAME} assimp)

add_subdirectory(shaders)
add_dependencies(${PROJECT_NAME} Shaders)

target_precompile_headers(${PROJECT_NAME} PRIVATE src/pch.h)

if (NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/assets)
    #Developer mode needs to be active on Windows 10 or later for this command to work
    file(CREATE_LINK ${CMAKE_CURRENT_SOURCE_DIR}/assets ${CMAKE_CURRENT_BINARY_DIR}/assets SYMBOLIC)
endif ()

if (ENABLE_VALIDATION)
    add_definitions(-DENABLE_VALIDATION=1)
endif (ENABLE_VALIDATION)

if (ENABLE_API_DUMP)
    add_definitions(-DENABLE_API_DUMP=1)
endif (ENABLE_API_DUMP)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source