Add support for compiling both opengl1 and opengl2 when they're built as shared libraries
Some checks failed
CodeQL / Analyze (push) Waiting to run
Build branch / build-all (push) Failing after 26s

renderercommon is now used, which will appropriately use opengl1 when building static libraries, or compile both opengl1/opengl2 modules when building shared libraries
This commit is contained in:
smallmodel 2024-12-18 23:24:04 +01:00
parent 7d369dec74
commit 38427fa3c5
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
4 changed files with 83 additions and 31 deletions

View file

@ -188,8 +188,7 @@ if (NOT BUILD_NO_CLIENT)
option(NO_MODERN_DMA "Use older sound-system" FALSE)
add_subdirectory("code/client")
add_subdirectory("code/renderergl1")
#add_subdirectory("code/renderergl2")
add_subdirectory("code/renderercommon")
add_subdirectory("code/sdl")
add_executable(openmohaa "misc/dummy.c")

View file

@ -0,0 +1,34 @@
cmake_minimum_required(VERSION 3.12)
project(omohrenderer)
file(GLOB_RECURSE SOURCES_RENDERER_COMMON "./*.c" "./*.cpp")
add_library(omohrenderer_common STATIC ${SOURCES_RENDERER_COMMON})
target_include_directories(omohrenderer_common PUBLIC "../sdl" "./")
target_link_libraries(omohrenderer_common PUBLIC qcommon_shared)
target_link_libraries(omohrenderer_common PUBLIC omohsdl_gl)
target_compile_definitions(omohrenderer_common PRIVATE USE_INTERNAL_JPEG=1)
# Add JPEG
if(USE_INTERNAL_JPEG)
file(GLOB_RECURSE SOURCES_JPEG_8 "../jpeg-8c/*.c")
add_library(jpeg8 STATIC ${SOURCES_JPEG_8})
target_include_directories(jpeg8 PRIVATE "../jpeg-8c")
target_include_directories(omohrenderer_common PUBLIC "../jpeg-8c")
target_link_libraries(omohrenderer_common PRIVATE jpeg8)
else()
target_include_directories(omohrenderer_common PUBLIC ${JPEG_INCLUDE_DIRS})
target_link_libraries(omohrenderer_common PRIVATE ${JPEG_LIBRARIES})
endif()
add_subdirectory("../renderergl1" renderergl1)
add_library(omohrenderer INTERFACE)
target_link_libraries(omohrenderer INTERFACE omohrenderergl1)
if (${USE_RENDERER_DLOPEN})
add_subdirectory("../renderergl2" renderergl2)
target_link_libraries(omohrenderer INTERFACE omohrenderergl2)
endif()

View file

@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.12)
project(omohrenderer)
project(omohrenderergl1)
file(GLOB_RECURSE SOURCES_RENDERER "./*.c" "./*.cpp" "../renderercommon/tr_*.c")
file(GLOB_RECURSE SOURCES_RENDERER "./*.c" "./*.cpp")
list(REMOVE_ITEM SOURCES_RENDERER "./tr_subs.c")
set(SOURCES_RENDERER ${SOURCES_RENDERER}
@ -10,42 +10,28 @@ set(SOURCES_RENDERER ${SOURCES_RENDERER}
)
if (${USE_RENDERER_DLOPEN})
add_library(omohrenderer SHARED ${SOURCES_RENDERER})
add_library(omohrenderergl1 SHARED ${SOURCES_RENDERER})
else()
add_library(omohrenderer STATIC ${SOURCES_RENDERER})
add_library(omohrenderergl1 STATIC ${SOURCES_RENDERER})
endif()
target_include_directories(omohrenderer PUBLIC "../sdl" "../renderercommon")
target_compile_features(omohrenderer PUBLIC cxx_nullptr)
target_compile_features(omohrenderer PUBLIC c_variadic_macros)
target_compile_definitions(omohrenderer PRIVATE USE_INTERNAL_JPEG=1)
target_link_libraries(omohrenderer PRIVATE qcommon_shared)
target_link_libraries(omohrenderer PRIVATE omohsdl_gl)
get_target_property(target_type omohrenderer TYPE)
target_compile_features(omohrenderergl1 PUBLIC cxx_nullptr)
target_compile_features(omohrenderergl1 PUBLIC c_variadic_macros)
target_link_libraries(omohrenderergl1 PRIVATE omohrenderer_common)
get_target_property(target_type omohrenderergl1 TYPE)
if (target_type STREQUAL "SHARED_LIBRARY")
target_sources(omohrenderer PRIVATE "./tr_subs.c")
target_compile_definitions(omohrenderer PUBLIC USE_RENDERER_DLOPEN=1)
target_sources(omohrenderergl1 PRIVATE "./tr_subs.c")
target_compile_definitions(omohrenderergl1 PUBLIC USE_RENDERER_DLOPEN=1)
endif ()
if(USE_INTERNAL_JPEG)
file(GLOB_RECURSE SOURCES_JPEG_8 "../jpeg-8c/*.c")
add_library(jpeg8 STATIC ${SOURCES_JPEG_8})
target_include_directories(jpeg8 PRIVATE "../jpeg-8c")
target_include_directories(omohrenderer PUBLIC "../jpeg-8c")
target_link_libraries(omohrenderer PRIVATE jpeg8)
else()
target_include_directories(omohrenderer PUBLIC ${JPEG_INCLUDE_DIRS})
target_link_libraries(omohrenderer PRIVATE ${JPEG_LIBRARIES})
endif()
set_target_properties(omohrenderer PROPERTIES PREFIX "")
set_target_properties(omohrenderer PROPERTIES OUTPUT_NAME "renderer_opengl1${TARGET_BIN_SUFFIX}")
set_target_properties(omohrenderergl1 PROPERTIES PREFIX "")
set_target_properties(omohrenderergl1 PROPERTIES OUTPUT_NAME "renderer_opengl1${TARGET_BIN_SUFFIX}")
if (target_type STREQUAL "SHARED_LIBRARY")
INSTALL(TARGETS omohrenderer DESTINATION ${CMAKE_INSTALL_LIBDIR}/${LIB_INSTALL_SUBDIR})
INSTALL(TARGETS omohrenderergl1 DESTINATION ${CMAKE_INSTALL_LIBDIR}/${LIB_INSTALL_SUBDIR})
if(MSVC)
INSTALL(FILES $<TARGET_PDB_FILE:omohrenderer> DESTINATION ${CMAKE_INSTALL_LIBDIR}/${LIB_INSTALL_SUBDIR} OPTIONAL)
INSTALL(FILES $<TARGET_PDB_FILE:omohrenderergl1> DESTINATION ${CMAKE_INSTALL_LIBDIR}/${LIB_INSTALL_SUBDIR} OPTIONAL)
endif()
endif ()

View file

@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.12)
project(omohrenderergl2)
file(GLOB SOURCES_RENDERER "./*.c" "./*.cpp" "../renderercommon/tr_*.c")
include("glsl/shaders.cmake")
if (${USE_RENDERER_DLOPEN})
add_library(omohrenderergl2 SHARED ${SOURCES_RENDERER} ${SHADER_SRCS})
else()
add_library(omohrenderergl2 STATIC ${SOURCES_RENDERER} ${SHADER_SRCS})
endif()
target_compile_features(omohrenderergl2 PUBLIC cxx_nullptr)
target_compile_features(omohrenderergl2 PUBLIC c_variadic_macros)
target_link_libraries(omohrenderergl2 PRIVATE omohrenderer_common)
get_target_property(target_type omohrenderergl2 TYPE)
if (target_type STREQUAL "SHARED_LIBRARY")
target_sources(omohrenderergl2 PRIVATE "./tr_subs.c")
target_compile_definitions(omohrenderergl2 PUBLIC USE_RENDERER_DLOPEN=1)
endif ()
set_target_properties(omohrenderergl2 PROPERTIES PREFIX "")
set_target_properties(omohrenderergl2 PROPERTIES OUTPUT_NAME "renderer_opengl2${TARGET_BIN_SUFFIX}")
if (target_type STREQUAL "SHARED_LIBRARY")
INSTALL(TARGETS omohrenderergl2 DESTINATION ${CMAKE_INSTALL_LIBDIR}/${LIB_INSTALL_SUBDIR})
if(MSVC)
INSTALL(FILES $<TARGET_PDB_FILE:omohrenderergl2> DESTINATION ${CMAKE_INSTALL_LIBDIR}/${LIB_INSTALL_SUBDIR} OPTIONAL)
endif()
endif ()