2023-05-16 12:31:44 +00:00
|
|
|
cmake_minimum_required(VERSION 3.9)
|
2021-04-09 15:24:47 +00:00
|
|
|
project(GLdc)
|
|
|
|
|
2023-05-16 12:31:44 +00:00
|
|
|
set(CMAKE_VERBOSE_MAKEFILE ON)
|
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
# set the default backend
|
|
|
|
if(PLATFORM_DREAMCAST)
|
|
|
|
set(BACKEND "kospvr" CACHE STRING "Backend to use")
|
|
|
|
else()
|
|
|
|
set(BACKEND "software" CACHE STRING "Backend to use")
|
|
|
|
endif()
|
|
|
|
|
2023-05-16 12:31:44 +00:00
|
|
|
include(CheckIPOSupported)
|
|
|
|
check_ipo_supported(RESULT FLTO_SUPPORTED OUTPUT FLTO_ERROR)
|
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
# List of possible backends
|
|
|
|
set_property(CACHE BACKEND PROPERTY STRINGS kospvr software)
|
|
|
|
|
|
|
|
message("\nCompiling using backend: ${BACKEND}\n")
|
|
|
|
|
|
|
|
string(TOUPPER ${BACKEND} BACKEND_UPPER)
|
|
|
|
add_definitions(-DBACKEND_${BACKEND_UPPER})
|
|
|
|
|
|
|
|
set(CMAKE_C_STANDARD 99)
|
2023-04-20 19:45:59 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
2021-04-09 15:24:47 +00:00
|
|
|
|
|
|
|
include_directories(include)
|
|
|
|
|
|
|
|
if(NOT PLATFORM_DREAMCAST)
|
2021-09-18 13:36:47 +00:00
|
|
|
set(FIND_LIBRARY_USE_LIB32_PATHS true)
|
|
|
|
set(FIND_LIBRARY_USE_LIB64_PATHS false)
|
2022-11-04 19:34:42 +00:00
|
|
|
else()
|
2023-03-04 22:13:44 +00:00
|
|
|
include(CheckCCompilerFlag)
|
|
|
|
check_c_compiler_flag("-mfsrra" COMPILER_HAS_FSRRA)
|
|
|
|
check_c_compiler_flag("-mfsca" COMPILER_HAS_FSCA)
|
|
|
|
if(COMPILER_HAS_FSRRA)
|
|
|
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mfsrra")
|
2023-04-17 17:34:56 +00:00
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mfsrra")
|
2023-05-11 14:22:27 +00:00
|
|
|
|
|
|
|
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -mfsrra")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -mfsrra")
|
2023-03-04 22:13:44 +00:00
|
|
|
endif()
|
|
|
|
if(COMPILER_HAS_FSCA)
|
|
|
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mfsca")
|
2023-04-17 17:34:56 +00:00
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mfsca")
|
2023-05-11 14:22:27 +00:00
|
|
|
|
|
|
|
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -mfsca")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -mfsca")
|
2023-03-04 22:13:44 +00:00
|
|
|
endif()
|
|
|
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ffp-contract=fast -ffast-math")
|
2023-04-17 17:34:56 +00:00
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -ffast-math")
|
2023-05-11 14:22:27 +00:00
|
|
|
|
|
|
|
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -ffp-contract=fast -ffast-math")
|
|
|
|
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -ffast-math")
|
2021-04-09 15:24:47 +00:00
|
|
|
endif()
|
|
|
|
|
2023-05-16 12:31:44 +00:00
|
|
|
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -mpretend-cmove -fexpensive-optimizations -fomit-frame-pointer -finline-functions")
|
2023-05-11 14:22:27 +00:00
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++14 -O3 -g0 -s -fomit-frame-pointer -fstrict-aliasing")
|
|
|
|
|
2023-05-16 12:31:44 +00:00
|
|
|
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O3 -mpretend-cmove -fexpensive-optimizations -fomit-frame-pointer -finline-functions")
|
2023-05-11 14:22:27 +00:00
|
|
|
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -std=c++14 -O3 -fomit-frame-pointer -fstrict-aliasing")
|
2023-04-17 17:34:56 +00:00
|
|
|
|
2022-05-21 19:16:26 +00:00
|
|
|
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g -Wall -Wextra")
|
2023-04-17 17:34:56 +00:00
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -Wall -Wextra")
|
2021-04-19 19:21:46 +00:00
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
set(
|
|
|
|
SOURCES
|
|
|
|
containers/aligned_vector.c
|
|
|
|
containers/named_array.c
|
|
|
|
containers/stack.c
|
|
|
|
GL/draw.c
|
|
|
|
GL/error.c
|
|
|
|
GL/flush.c
|
|
|
|
GL/fog.c
|
|
|
|
GL/framebuffer.c
|
|
|
|
GL/glu.c
|
|
|
|
GL/immediate.c
|
|
|
|
GL/lighting.c
|
|
|
|
GL/matrix.c
|
|
|
|
GL/state.c
|
|
|
|
GL/texture.c
|
|
|
|
GL/util.c
|
2023-08-31 07:45:05 +00:00
|
|
|
GL/alloc/alloc.c
|
2021-04-09 15:24:47 +00:00
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/version.c
|
|
|
|
)
|
|
|
|
|
|
|
|
execute_process(
|
|
|
|
COMMAND git describe --abbrev=4 --dirty --always --tags
|
|
|
|
OUTPUT_VARIABLE GLDC_VERSION
|
|
|
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
|
|
|
|
configure_file(GL/version.c.in ${CMAKE_CURRENT_BINARY_DIR}/version.c)
|
|
|
|
|
|
|
|
if(PLATFORM_DREAMCAST)
|
|
|
|
set(SOURCES ${SOURCES} GL/platforms/sh4.c)
|
|
|
|
else()
|
2021-09-18 13:36:47 +00:00
|
|
|
find_package(PkgConfig)
|
|
|
|
pkg_check_modules(SDL2 REQUIRED sdl2)
|
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
include_directories(${SDL2_INCLUDE_DIRS})
|
|
|
|
link_libraries(${SDL2_LIBRARIES})
|
|
|
|
set(
|
|
|
|
SOURCES
|
|
|
|
${SOURCES}
|
|
|
|
GL/platforms/software.c
|
|
|
|
GL/platforms/software/edge_equation.c
|
|
|
|
GL/platforms/software/parameter_equation.c
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_library(GLdc STATIC ${SOURCES})
|
2022-05-21 19:16:26 +00:00
|
|
|
|
2023-05-16 12:31:44 +00:00
|
|
|
if(FLTO_SUPPORTED)
|
|
|
|
set_property(TARGET GLdc PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
|
|
endif()
|
|
|
|
|
2022-05-21 19:16:26 +00:00
|
|
|
if(NOT PLATFORM_DREAMCAST)
|
|
|
|
set_target_properties(GLdc PROPERTIES
|
|
|
|
COMPILE_OPTIONS "-m32"
|
|
|
|
LINK_OPTIONS "-m32"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
link_libraries(m)
|
|
|
|
|
|
|
|
include_directories(include)
|
|
|
|
|
|
|
|
link_libraries(GLdc)
|
|
|
|
|
|
|
|
function(gen_sample sample)
|
|
|
|
set(SAMPLE_SRCS ${ARGN})
|
|
|
|
set(GENROMFS "$ENV{KOS_BASE}/utils/genromfs/genromfs")
|
|
|
|
set(BIN2O $ENV{KOS_BASE}/utils/bin2o/bin2o)
|
|
|
|
set(ROMDISK_IMG "${CMAKE_SOURCE_DIR}/samples/${sample}/romdisk.img")
|
|
|
|
set(ROMDISK_O "${CMAKE_SOURCE_DIR}/samples/${sample}/romdisk.o")
|
|
|
|
set(ROMDISK_DIR "${CMAKE_SOURCE_DIR}/samples/${sample}/romdisk")
|
|
|
|
|
|
|
|
add_executable(${sample} ${SAMPLE_SRCS})
|
|
|
|
|
2023-05-16 12:31:44 +00:00
|
|
|
if(FLTO_SUPPORTED)
|
|
|
|
# FIXME: Cubes + LTO causes an ICE
|
|
|
|
if(NOT ${sample} MATCHES "cubes")
|
|
|
|
set_property(TARGET ${sample} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
if(PLATFORM_DREAMCAST)
|
|
|
|
if(EXISTS "${CMAKE_SOURCE_DIR}/samples/${sample}/romdisk")
|
|
|
|
message("Generating romdisk for sample: ${sample}")
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${ROMDISK_IMG}
|
|
|
|
COMMAND ${GENROMFS} -f ${ROMDISK_IMG} -d ${ROMDISK_DIR} -v
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_command(
|
|
|
|
OUTPUT ${ROMDISK_O}
|
|
|
|
COMMAND ${BIN2O} romdisk.img romdisk romdisk.o
|
|
|
|
DEPENDS ${ROMDISK_IMG}
|
|
|
|
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/samples/${sample}"
|
|
|
|
)
|
|
|
|
|
|
|
|
add_custom_target(${sample}_romdisk DEPENDS ${ROMDISK_O})
|
|
|
|
add_dependencies(${sample} ${sample}_romdisk)
|
|
|
|
target_link_libraries(${sample} ${ROMDISK_O})
|
|
|
|
|
|
|
|
else()
|
|
|
|
message("No such romdisk for sample: ${sample} at 'samples/${sample}/romdisk'")
|
|
|
|
endif()
|
2022-05-21 19:16:26 +00:00
|
|
|
else()
|
|
|
|
set_target_properties(${sample} PROPERTIES
|
|
|
|
COMPILE_OPTIONS "-m32"
|
|
|
|
LINK_OPTIONS "-m32"
|
|
|
|
)
|
2021-04-09 15:24:47 +00:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2023-08-26 19:34:11 +00:00
|
|
|
add_subdirectory(tests)
|
|
|
|
|
2021-04-09 15:24:47 +00:00
|
|
|
gen_sample(blend_test samples/blend_test/main.c)
|
|
|
|
gen_sample(depth_funcs samples/depth_funcs/main.c)
|
|
|
|
gen_sample(depth_funcs_alpha_testing samples/depth_funcs_alpha_testing/main.c samples/depth_funcs_alpha_testing/gl_png.c)
|
|
|
|
gen_sample(depth_funcs_ortho samples/depth_funcs_ortho/main.c)
|
2022-01-31 10:30:26 +00:00
|
|
|
gen_sample(lerabot01 samples/lerabot01/main.c samples/loadbmp.c)
|
|
|
|
gen_sample(lights samples/lights/main.c samples/loadbmp.c)
|
|
|
|
gen_sample(mipmap samples/mipmap/main.c samples/loadbmp.c)
|
2021-04-09 15:24:47 +00:00
|
|
|
gen_sample(multitexture_arrays samples/multitexture_arrays/main.c samples/multitexture_arrays/pvr-texture.c)
|
|
|
|
gen_sample(nehe02 samples/nehe02/main.c)
|
|
|
|
gen_sample(nehe02de samples/nehe02de/main.c)
|
|
|
|
gen_sample(nehe02va samples/nehe02va/main.c)
|
|
|
|
gen_sample(nehe03 samples/nehe03/main.c)
|
|
|
|
gen_sample(nehe04 samples/nehe04/main.c)
|
|
|
|
gen_sample(nehe05 samples/nehe05/main.c)
|
2022-01-31 10:30:26 +00:00
|
|
|
gen_sample(nehe06 samples/nehe06/main.c samples/loadbmp.c)
|
2021-04-09 15:24:47 +00:00
|
|
|
gen_sample(nehe06_vq samples/nehe06_vq/main.c)
|
2021-04-13 20:28:59 +00:00
|
|
|
gen_sample(nehe06_4444twid samples/nehe06_4444twid/main.c)
|
2021-04-30 19:47:33 +00:00
|
|
|
gen_sample(nehe08 samples/nehe08/main.c samples/nehe08/pvr-texture.c)
|
2022-06-10 19:26:51 +00:00
|
|
|
gen_sample(nehe10 samples/nehe10/main.c samples/loadbmp.c)
|
2022-01-31 10:30:26 +00:00
|
|
|
gen_sample(nehe20 samples/nehe20/main.c samples/loadbmp.c)
|
2021-04-09 15:24:47 +00:00
|
|
|
gen_sample(ortho2d samples/ortho2d/main.c)
|
|
|
|
gen_sample(paletted samples/paletted/main.c)
|
|
|
|
gen_sample(paletted_pcx samples/paletted_pcx/main.c)
|
|
|
|
gen_sample(polygon_offset samples/polygon_offset/main.c)
|
|
|
|
gen_sample(terrain samples/terrain/main.c)
|
|
|
|
gen_sample(zclip samples/zclip/main.c)
|
|
|
|
gen_sample(zclip_triangle samples/zclip_triangle/main.c)
|
|
|
|
gen_sample(zclip_trianglestrip samples/zclip_trianglestrip/main.c)
|
2021-04-14 20:38:33 +00:00
|
|
|
gen_sample(scissor samples/scissor/main.c)
|
2021-04-18 20:33:23 +00:00
|
|
|
gen_sample(polymark samples/polymark/main.c)
|
2023-04-08 19:24:52 +00:00
|
|
|
gen_sample(cubes samples/cubes/main.cpp)
|
2023-04-19 19:57:44 +00:00
|
|
|
gen_sample(zclip_test tests/zclip/main.cpp)
|
2021-04-09 15:24:47 +00:00
|
|
|
|
|
|
|
if(PLATFORM_DREAMCAST)
|
|
|
|
gen_sample(trimark samples/trimark/main.c)
|
2021-04-20 15:08:58 +00:00
|
|
|
gen_sample(quadmark samples/quadmark/main.c samples/profiler.c)
|
2023-09-01 19:22:19 +00:00
|
|
|
gen_sample(prof_texture_upload samples/prof_texture_upload/main.c samples/profiler.c)
|
2021-04-20 15:08:58 +00:00
|
|
|
else()
|
|
|
|
gen_sample(quadmark samples/quadmark/main.c)
|
2023-09-01 19:22:19 +00:00
|
|
|
gen_sample(prof_texture_upload samples/prof_texture_upload/main.c)
|
2021-04-09 15:24:47 +00:00
|
|
|
endif()
|