Libtorch takes forever to compile

I am working with libtorch in a cpp environment. When I link libtorch against my cmake target and attempt to compile it takes 2-3 minutes to build. Why is this so slow?

I’m fetching libtorch like this:

##############################
# Libtorch
##############################

set(BUILD_TEST OFF)
set(CMAKE_CXX_STANDARD 17)
set(TORCH_USE_CUDA_DSA 1)
find_package(Torch ${libtorch_VERSION} QUIET CONFIG)
if (NOT Torch_FOUND)
    message(STATUS "libtorch ${libtorch_VERSION} - not found")
    message(STATUS "Fetching libtorch")
    include(FetchContent)
    FetchContent_Declare(
            libtorch
            # URL https://download.pytorch.org/libtorch/cu121/libtorch-cxx11-abi-shared-with-deps-2.1.2%2Bcu121.zip
            URL https://download.pytorch.org/libtorch/cu121/libtorch-cxx11-abi-static-with-deps-2.1.0%2Bcu121.zip
            SOURCE_DIR libtorch)
    FetchContent_GetProperties(libtorch)
    if (NOT libtorch_POPULATED)
        unset(FETCHCONTENT_QUIET CACHE)
        FetchContent_Populate(libtorch)
        list(APPEND CMAKE_PREFIX_PATH ${CMAKE_BINARY_DIR}/libtorch)
    endif ()
    find_package(Torch ${libtorch_VERSION} CONFIG REQUIRED)
else ()
    message(STATUS "libtorch ${libtorch_VERSION} - found")
endif ()

and link to my project link this:


##############################################
# Setup Tests
##############################################

enable_testing()

add_executable(
        tests
        test_core.cu

)
target_link_libraries(
        tests
        GTest::gtest_main
        ${CUDA_LIBRARIES}
        ${TORCH_LIBRARIES}
        simulator
        viewer
)
target_include_directories(tests PUBLIC
        ${CUDA_INCLUDE_DIRS}
        ${TORCH_INCLUDE_DIRS}
)

Yet building the tests target takes 3 minutes. Why so slow?