Implement SDL3 into the CMakeLists.txt.

This commit is contained in:
Yamagi 2024-04-03 21:14:41 +02:00
parent 8cedbb0694
commit 78c951d620

View file

@ -64,6 +64,7 @@ endif()
option(CURL_SUPPORT "cURL support" ON)
option(OPENAL_SUPPORT "OpenAL support" ON)
option(SYSTEMWIDE_SUPPORT "Enable systemwide installation of game assets" OFF)
option(SDL3_SUPPORT "Build against SDL 3 instead of SDL2" OFF)
set(SYSTEMDIR "" CACHE STRING "Override the system default directory")
@ -179,9 +180,14 @@ endif()
# Required libraries to build the different components of the binaries. Find
# them and add the include/linker directories and flags (in case the package
# manager find it in a weird place).
find_package(SDL2 REQUIRED)
list(APPEND yquake2IncludeDirectories "${SDL2_INCLUDE_DIR}/..")
list(APPEND yquake2SDLLinkerFlags ${SDL2_LIBRARY})
if (SDL3_SUPPORT)
find_package(SDL3 REQUIRED)
add_definitions(-DUSE_SDL3)
else()
find_package(SDL2 REQUIRED)
list(APPEND yquake2IncludeDirectories "${SDL2_INCLUDE_DIR}/..")
list(APPEND yquake2SDLLinkerFlags ${SDL2_LIBRARY})
endif()
# We need an OpenGL implementation.
set(OpenGL_GL_PREFERENCE GLVND)
@ -430,7 +436,6 @@ set(Client-Source
${CLIENT_SRC_DIR}/cl_view.c
${CLIENT_SRC_DIR}/curl/download.c
${CLIENT_SRC_DIR}/curl/qcurl.c
${CLIENT_SRC_DIR}/input/sdl.c
${CLIENT_SRC_DIR}/menu/menu.c
${CLIENT_SRC_DIR}/menu/qmenu.c
${CLIENT_SRC_DIR}/menu/videomenu.c
@ -440,7 +445,6 @@ set(Client-Source
${CLIENT_SRC_DIR}/sound/sdl.c
${CLIENT_SRC_DIR}/sound/sound.c
${CLIENT_SRC_DIR}/sound/wave.c
${CLIENT_SRC_DIR}/vid/glimp_sdl.c
${CLIENT_SRC_DIR}/vid/vid.c
${COMMON_SRC_DIR}/argproc.c
${COMMON_SRC_DIR}/clientserver.c
@ -477,6 +481,18 @@ set(Client-Source
${SERVER_SRC_DIR}/sv_world.c
)
if(SDL3_SUPPORT)
set(Client-SDL-Source
${CLIENT_SRC_DIR}/input/sdl3.c
${CLIENT_SRC_DIR}/vid/glimp_sdl3.c
)
else()
set(Client-SDL-Source
${CLIENT_SRC_DIR}/input/sdl2.c
${CLIENT_SRC_DIR}/vid/glimp_sdl2.c
)
endif()
set(Client-Header
${CLIENT_SRC_DIR}/header/client.h
${CLIENT_SRC_DIR}/header/console.h
@ -686,13 +702,16 @@ set(SOFT-Header
# Main Quake 2 executable
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_executable(yquake2 WIN32 ${Client-Source} ${Client-Header} ${Platform-Specific-Source}
${Backends-Generic-Source})
add_executable(yquake2 WIN32 ${Client-Source} ${Client-SDL-Source} ${Client-Header}
${Platform-Specific-Source} ${Backends-Generic-Source})
set_target_properties(yquake2 PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release
)
target_link_libraries(yquake2 ${yquake2LinkerFlags} ${yquake2ClientLinkerFlags}
${yquake2SDLLinkerFlags} ${yquake2ZLibLinkerFlags} ws2_32 winmm)
if(SDL3_SUPPORT)
target_link_libraries(yquake2 SDL3::SDL3)
endif()
if(MSVC AND CMAKE_MAJOR_VERSION GREATER 3 OR ( CMAKE_MAJOR_VERSION EQUAL 3 AND CMAKE_MINOR_VERSION GREATER_EQUAL 6 ))
# CMake >= 3.6 supports setting the default project started for debugging (instead of trying to launch ALL_BUILD ...)
@ -708,13 +727,16 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
add_executable(quake2 WIN32 ${Wrapper-Source})
set_target_properties(quake2 PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release)
else()
add_executable(quake2 ${Client-Source} ${Client-Header} ${Platform-Specific-Source}
${Backends-Generic-Source})
add_executable(quake2 ${Client-Source} ${Client-SDL-Source} ${Client-Header}
${Platform-Specific-Source} ${Backends-Generic-Source})
set_target_properties(quake2 PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release
)
target_link_libraries(quake2 ${yquake2LinkerFlags} ${yquake2ClientLinkerFlags}
${yquake2SDLLinkerFlags} ${yquake2ZLibLinkerFlags})
if(SDL3_SUPPORT)
target_link_libraries(quake2 SDL3::SDL3)
endif()
endif()
# Quake 2 Dedicated Server
@ -725,19 +747,17 @@ set_target_properties(q2ded PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release
)
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
target_link_libraries(q2ded ${yquake2LinkerFlags}
target_link_libraries(q2ded ${yquake2LinkerFlags})
else()
target_link_libraries(q2ded ${yquake2LinkerFlags} ${yquake2ServerLinkerFlags} ${yquake2ZLibLinkerFlags})
endif()
# Build the game dynamic library
add_library(game MODULE ${Game-Source} ${Game-Header})
set_target_properties(game PROPERTIES
PREFIX ""
SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}
)
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(isMultiConfig) # multi-config, like Visual Studio solution
set_target_properties(game PROPERTIES
@ -750,7 +770,6 @@ else() # single-config, like normal Makefiles
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release/baseq2
)
endif()
target_link_libraries(game ${yquake2LinkerFlags})
# Build the GL1 dynamic library
@ -761,7 +780,11 @@ set_target_properties(ref_gl1 PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/release
SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}
)
target_link_libraries(ref_gl1 ${yquake2LinkerFlags} ${yquake2OpenGLLinkerFlags} ${yquake2SDLLinkerFlags})
target_link_libraries(ref_gl1 ${yquake2LinkerFlags} ${yquake2OpenGLLinkerFlags}
${yquake2SDLLinkerFlags})
if(SDL3_SUPPORT)
target_link_libraries(ref_gl1 SDL3::SDL3)
endif()
# Build the GL3 dynamic library
add_library(ref_gl3 MODULE ${GL3-Source} ${Glad-GL3-Source} ${GL3-Header} ${Glad-GL3-Header} ${REF-Platform-Specific-Source})
@ -773,6 +796,9 @@ set_target_properties(ref_gl3 PROPERTIES
)
target_include_directories(ref_gl3 PRIVATE ${CMAKE_SOURCE_DIR}/src/client/refresh/gl3/glad/include)
target_link_libraries(ref_gl3 ${yquake2LinkerFlags} ${yquake2SDLLinkerFlags})
if(SDL3_SUPPORT)
target_link_libraries(ref_gl3 SDL3::SDL3)
endif()
# Build the GLES3 dynamic library
add_library(ref_gles3 MODULE ${GL3-Source} ${Glad-GLES3-Source} ${GL3-Header} ${Glad-GLES3-Header} ${REF-Platform-Specific-Source})
@ -786,6 +812,9 @@ set_target_properties(ref_gles3 PROPERTIES
target_include_directories(ref_gles3 PRIVATE ${CMAKE_SOURCE_DIR}/src/client/refresh/gl3/glad-gles3/include)
target_compile_definitions(ref_gles3 PRIVATE YQ2_GL3_GLES3=1 YQ2_GL3_GLES=1)
target_link_libraries(ref_gles3 ${yquake2LinkerFlags} ${yquake2SDLLinkerFlags})
if(SDL3_SUPPORT)
target_link_libraries(ref_gles3 SDL3::SDL3)
endif()
# Build the soft renderer dynamic library
add_library(ref_soft MODULE ${SOFT-Source} ${SOFT-Header} ${REF-Platform-Specific-Source})
@ -796,3 +825,6 @@ set_target_properties(ref_soft PROPERTIES
SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}
)
target_link_libraries(ref_soft ${yquake2LinkerFlags} ${yquake2SDLLinkerFlags})
if(SDL3_SUPPORT)
target_link_libraries(ref_soft SDL3::SDL3)
endif()