最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to include a dependency installed through FetchContent (CMake) - Stack Overflow

programmeradmin2浏览0评论

I want to find, and download if required, multiple librairies through CMake, namely SDL3, GLEW, imgui and RapidJSON.

The issue I'm facing is that I can only manage to properly get the includes for SDL.

find_package(SDL3 ${SDL3_VERSION} QUIET) # QUIET or REQUIRED
if (NOT SDL3_FOUND) # If there's none, fetch and build SDL3
    include(FetchContent)
    if (UNIX)
        FetchContent_Declare(
                SDL3
                URL ${SDL3_VERSION}.tar.gz
        )
        FetchContent_MakeAvailable(SDL3)
    elseif (WIN32)
        FetchContent_Declare(
                SDL3
                URL ${SDL3_VERSION}.zip
        )
        FetchContent_MakeAvailable(SDL3)
    endif()

endif()

My CMakeLists is made of multiple blocks like this one, for each dependency.

The include and linking part is currently as such

target_include_directories(${PROJECT_NAME} PUBLIC SDL3::SDL3 ${GLEW_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} SDL3::SDL3 ${GLEW_LIBRARIES} imgui RapidJSON)

My IDE is giving me hints for SDL3::SDL3 but not for GLEW or imgui. Running CMake only warns me about not finding PkgConfig and LibUSB, but no errors. Once in code, I can include SDL through

#include <SDL3/SDL.h>

But I can't do the same for GLEW and imgui, I need the absolute path, but they are properly getting downloaded into the _deps folder of my build.

Could someone please help me ? Preferably with a generic solution as I will likely need to add and changes dependencies later on. Thank you.

发布评论

评论列表(0)

  1. 暂无评论