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.