Files

114 lines
4.0 KiB
CMake

include(FetchContent)
find_package(OpenGL QUIET)
# When using the Visual Studio generator, it is necessary to suppress stderr output entirely so it does not interrupt the patch command.
# Redirecting to nul is used here instead of the `--quiet` flag, as that flag was only recently introduced in git 2.25.0 (Jan 2022)
if (CMAKE_GENERATOR MATCHES "Visual Studio")
set(git_hide_output 2> nul)
endif()
#=================== ImGui ===================
set(sdl_gamepad_patch_file ${CMAKE_CURRENT_SOURCE_DIR}/cmake/dependencies/patches/sdl-gamepad-fix.patch)
# Applies the patch or checks if it has already been applied successfully previously. Will error otherwise.
set(sdl_apply_patch_if_needed git apply ${sdl_gamepad_patch_file} ${git_hide_output} || git apply --reverse --check ${sdl_gamepad_patch_file})
FetchContent_Declare(
ImGui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG v1.90.6-docking
PATCH_COMMAND ${sdl_apply_patch_if_needed}
)
FetchContent_MakeAvailable(ImGui)
list(APPEND ADDITIONAL_LIB_INCLUDES ${imgui_SOURCE_DIR} ${imgui_SOURCE_DIR}/backends)
add_library(ImGui STATIC)
set_property(TARGET ImGui PROPERTY CXX_STANDARD 20)
target_sources(ImGui
PRIVATE
${imgui_SOURCE_DIR}/imgui_demo.cpp
${imgui_SOURCE_DIR}/imgui_draw.cpp
${imgui_SOURCE_DIR}/imgui_tables.cpp
${imgui_SOURCE_DIR}/imgui_widgets.cpp
${imgui_SOURCE_DIR}/imgui.cpp
)
target_sources(ImGui
PRIVATE
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_sdl2.cpp
)
target_include_directories(ImGui PUBLIC ${imgui_SOURCE_DIR} ${imgui_SOURCE_DIR}/backends PRIVATE ${SDL2_INCLUDE_DIRS})
# ========= StormLib =============
if(NOT EXCLUDE_MPQ_SUPPORT)
set(stormlib_patch_file ${CMAKE_CURRENT_SOURCE_DIR}/cmake/dependencies/patches/stormlib-optimizations.patch)
# Applies the patch or checks if it has already been applied successfully previously. Will error otherwise.
set(stormlib_apply_patch_if_needed git apply ${stormlib_patch_file} ${git_hide_output} || git apply --reverse --check ${stormlib_patch_file})
FetchContent_Declare(
StormLib
GIT_REPOSITORY https://github.com/ladislav-zezula/StormLib.git
GIT_TAG v9.25
PATCH_COMMAND ${stormlib_apply_patch_if_needed}
)
FetchContent_MakeAvailable(StormLib)
list(APPEND ADDITIONAL_LIB_INCLUDES ${stormlib_SOURCE_DIR}/src)
endif()
#=================== STB ===================
set(STB_DIR ${CMAKE_BINARY_DIR}/_deps/stb)
file(DOWNLOAD "https://github.com/nothings/stb/raw/0bc88af4de5fb022db643c2d8e549a0927749354/stb_image.h" "${STB_DIR}/stb_image.h")
file(WRITE "${STB_DIR}/stb_impl.c" "#define STB_IMAGE_IMPLEMENTATION\n#include \"stb_image.h\"")
add_library(stb STATIC)
target_sources(stb PRIVATE
${STB_DIR}/stb_image.h
${STB_DIR}/stb_impl.c
)
target_include_directories(stb PUBLIC ${STB_DIR})
list(APPEND ADDITIONAL_LIB_INCLUDES ${STB_DIR})
#=================== libgfxd ===================
if (GFX_DEBUG_DISASSEMBLER)
FetchContent_Declare(
libgfxd
GIT_REPOSITORY https://github.com/glankk/libgfxd.git
GIT_TAG 008f73dca8ebc9151b205959b17773a19c5bd0da
)
FetchContent_MakeAvailable(libgfxd)
add_library(libgfxd STATIC)
set_property(TARGET libgfxd PROPERTY C_STANDARD 11)
target_sources(libgfxd PRIVATE
${libgfxd_SOURCE_DIR}/gbi.h
${libgfxd_SOURCE_DIR}/gfxd.h
${libgfxd_SOURCE_DIR}/priv.h
${libgfxd_SOURCE_DIR}/gfxd.c
${libgfxd_SOURCE_DIR}/uc.c
${libgfxd_SOURCE_DIR}/uc_f3d.c
${libgfxd_SOURCE_DIR}/uc_f3db.c
${libgfxd_SOURCE_DIR}/uc_f3dex.c
${libgfxd_SOURCE_DIR}/uc_f3dex2.c
${libgfxd_SOURCE_DIR}/uc_f3dexb.c
)
target_include_directories(libgfxd PUBLIC ${libgfxd_SOURCE_DIR})
endif()
#======== thread-pool ========
FetchContent_Declare(
ThreadPool
GIT_REPOSITORY https://github.com/bshoshany/thread-pool.git
GIT_TAG v4.1.0
)
FetchContent_MakeAvailable(ThreadPool)
list(APPEND ADDITIONAL_LIB_INCLUDES ${threadpool_SOURCE_DIR}/include)