From b5a3296276bc9b14f0bddf9dcc633f0dc5fe8e6a Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 13 Nov 2025 19:52:35 +0100 Subject: [PATCH] copy pa- uuhh port blankarts cmake build stuff it actually compiles an executable that even starts!!! TODO: - fix windoze lib stuff, we dont use cpm - fix git commit related stuff (shows just "illegal" on titlescreen) - readd saturn specific things like saturnpak, fbo etc - fix CMAKECONFIG --- CMakeLists.txt | 250 +++++--- assets/CMakeLists.txt | 81 ++- cmake/Comptime.cmake | 19 + cmake/Modules/FindDiscordRPC.cmake | 10 + cmake/Modules/FindGME.cmake | 12 +- cmake/Modules/FindOPENMPT.cmake | 12 +- cmake/Modules/FindSDL2.cmake | 10 + cmake/Modules/FindSDL2_mixer.cmake | 10 + cmake/Modules/GitUtilities.cmake | 64 ++- src/CMakeLists.txt | 883 ++++++++++++----------------- src/blua/CMakeLists.txt | 1 + src/hardware/CMakeLists.txt | 1 + src/sdl/CMakeLists.txt | 429 ++++---------- 13 files changed, 779 insertions(+), 1003 deletions(-) create mode 100644 cmake/Comptime.cmake create mode 100644 src/blua/CMakeLists.txt create mode 100644 src/hardware/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index b7d280190..256c6c806 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,60 +1,161 @@ -cmake_minimum_required(VERSION 3.5) -# DO NOT CHANGE THIS SRB2 STRING! Some variable names depend on this string. -# Version change is fine. -project(SRB2 - VERSION 1.6 - LANGUAGES C) +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) -if(${PROJECT_SOURCE_DIR} MATCHES ${PROJECT_BINARY_DIR}) - message(FATAL_ERROR "In-source builds will bring you a world of pain. Please make a separate directory to invoke CMake from.") +if("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") + message(FATAL_ERROR "In-source builds are blocked. Please build from a separate directory.") endif() # Set up CMAKE path set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") -### Useful functions +include(CMakeDependentOption) +#include(cmake/CPM.cmake) -# Prepend sources with current source directory -function(prepend_sources SOURCE_FILES) - foreach(SOURCE_FILE ${${SOURCE_FILES}}) - set(MODIFIED ${MODIFIED} ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE}) - endforeach() - set(${SOURCE_FILES} ${MODIFIED} PARENT_SCOPE) -endfunction() +# DO NOT CHANGE THIS SRB2 STRING! Some variable names depend on this string. +# Version change is fine. +project(SRB2 + VERSION 1.6 + LANGUAGES C CXX) -# Macro to add OSX framework -macro(add_framework fwname appname) - find_library(FRAMEWORK_${fwname} - NAMES ${fwname} - PATHS ${CMAKE_OSX_SYSROOT}/System/Library - ${CMAKE_OSX_SYSROOT}/Library - /System/Library - /Library - ATH_SUFFIXES Frameworks - NO_DEFAULT_PATH) - if( ${FRAMEWORK_${fwname}} STREQUAL FRAMEWORK_${fwname}-NOTFOUND) - MESSAGE(ERROR ": Framework ${fwname} not found") - else() - TARGET_LINK_LIBRARIES(${appname} PRIVATE "${FRAMEWORK_${fwname}}/${fwname}") - MESSAGE(STATUS "Framework ${fwname} found at ${FRAMEWORK_${fwname}}") - endif() -endmacro() +if(APPLE) + # DiscordRPC needs but does not properly specify ObjC + enable_language(OBJC) +endif() -# Macro to copy Windows DLLs to Debug/Release folder for easy debugging -# Note: this is general purpose, we could copy anything. Just using for DLLs on MSVC though -macro(copy_files_to_build_dir target dlllist_var) - if(MSVC) - # http://stackoverflow.com/a/26983405/3064195 - foreach(dlllist_item ${${dlllist_var}}) - get_filename_component(dllname ${dlllist_item} NAME) - add_custom_command(TARGET ${target} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${dlllist_item} - $/${dllname} - ) - endforeach() +##### PACKAGE CONFIGURATION ##### + +set(SRB2_CPACK_GENERATOR "" CACHE STRING "Generator to use for making a package. E.g., ZIP, TGZ, DragNDrop (OSX only). Leave blank for default generator.") + +if("${SRB2_CPACK_GENERATOR}" STREQUAL "") + if("${CMAKE_SYSTEM_NAME}" MATCHES "Windows") + set(SRB2_CPACK_GENERATOR "ZIP") + elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") + set(SRB2_CPACK_GENERATOR "TGZ") + elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") + set(SRB2_CPACK_GENERATOR "TGZ") endif() -endmacro() +endif() + +set(CPACK_GENERATOR ${SRB2_CPACK_GENERATOR}) +set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "SRB2Kart" CACHE STRING "Program name for display purposes") +set(CPACK_PACKAGE_VENDOR "Kart Krew" CACHE STRING "Vendor name for display purposes") +#set(CPACK_PACKAGE_DESCRIPTION_FILE ) +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") +set(CPACK_PACKAGE_VERSION_MAJOR ${SRB2_VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${SRB2_VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${SRB2_VERSION_PATCH}) +set(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMAKE_VERSION_MAJOR}.${CMAKE_VERSION_MINOR}") +SET(CPACK_OUTPUT_FILE_PREFIX package) +include(CPack) + +# Options + +if("${CMAKE_SYSTEM_NAME}" MATCHES Linux) + set(SRB2_CONFIG_SYSTEM_LIBRARIES_DEFAULT ON) +else() + set(SRB2_CONFIG_SYSTEM_LIBRARIES_DEFAULT OFF) +endif() + +option( + SRB2_CONFIG_SYSTEM_LIBRARIES + "Link dependencies using CMake's find_package and do not use internal builds" + ${SRB2_CONFIG_SYSTEM_LIBRARIES_DEFAULT} +) +option(SRB2_CONFIG_ENABLE_TESTS "Build the test suite" OFF) +# This option isn't recommended for distribution builds and probably won't work (yet). +cmake_dependent_option( + SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES + "Use dynamic libraries when compiling internal dependencies" + OFF "NOT SRB2_CONFIG_SYSTEM_LIBRARIES" + OFF +) +option(SRB2_CONFIG_ENABLE_DISCORDRPC "Enable Discord RPC features" ON) +option(SRB2_CONFIG_STATIC_STDLIB "Link static version of standard library. All dependencies must also be static" ON) +option(SRB2_CONFIG_HWRENDER "Enable hardware render (OpenGL) support" ON) +option(SRB2_CONFIG_STATIC_OPENGL "Enable static linking GL (do not do this)" OFF) +option(SRB2_CONFIG_ERRORMODE "Compile C code with warnings treated as errors." OFF) +option(SRB2_CONFIG_DEBUGMODE "Compile with PARANOIA, ZDEBUG, RANGECHECK and PACKETDROP defined." OFF) +option(SRB2_CONFIG_MOBJCONSISTANCY "Compile with MOBJCONSISTANCY defined." OFF) +option(SRB2_CONFIG_PACKETDROP "Compile with PACKETDROP defined." OFF) +option(SRB2_CONFIG_ZDEBUG "Compile with ZDEBUG defined." OFF) +# SRB2_CONFIG_PROFILEMODE is probably superceded by some CMake setting. +option(SRB2_CONFIG_PROFILEMODE "Compile for profiling (GCC only)." OFF) +option(SRB2_CONFIG_TRACY "Compile with Tracy profiling enabled" OFF) +option(SRB2_CONFIG_ASAN "Compile with AddressSanitizer (libasan)." OFF) +option(SRB2_CONFIG_UBSAN "Compile with UndefinedBehaviorSanitizer (libubsan)." OFF) +set(SRB2_CONFIG_ASSET_DIRECTORY "" CACHE PATH "Path to directory that contains all asset files for the installer. If set, assets will be part of installation and cpack.") +option(SRB2_CONFIG_LTO "Enable link time optimizations, improves performance at the cost of longer link times." ON) +option(SRB2_CONFIG_TIDY "Enable clang tiny, checks compiled code for issues at the cost of longer compile times." OFF) + +#if(SRB2_CONFIG_ENABLE_TESTS) + # https://github.com/catchorg/Catch2 +# CPMAddPackage( +# NAME Catch2 +# VERSION 3.1.1 +# GITHUB_REPOSITORY catchorg/Catch2 +# OPTIONS +# "CATCH_INSTALL_DOCS OFF" +# ) +# list(APPEND CMAKE_MODULE_PATH "${Catch2_SOURCE_DIR}/extras") +# include(CTest) +# include(Catch) +# add_executable(srb2tests) +# # To add tests, use target_sources to add individual test files to the target in subdirs. +# target_link_libraries(srb2tests PRIVATE Catch2::Catch2 Catch2::Catch2WithMain) +# target_compile_features(srb2tests PRIVATE c_std_11 cxx_std_17) +# catch_discover_tests(srb2tests) +#endif() + +# Enable CCache +# (Set USE_CCACHE=ON to use, CCACHE_OPTIONS for options) +if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL Windows) + option(USE_CCACHE "Enable ccache support" OFF) + + if(USE_CCACHE) + find_program(CCACHE_TOOL_PATH ccache) + if(CCACHE_TOOL_PATH) + set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_TOOL_PATH} CACHE STRING "" FORCE) + set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_TOOL_PATH} CACHE STRING "" FORCE) + else() + message(WARNING "USE_CCACHE was set but ccache is not found (set CCACHE_TOOL_PATH)") + endif() + endif() +else() + # TODO: fix windoze crap, i dont want cpm lol + #CPMAddPackage( + # NAME Ccache.cmake + # GITHUB_REPOSITORY TheLartians/Ccache.cmake + # VERSION 1.2.5 + #) +endif() + +# Dependencies +#add_subdirectory(thirdparty) + +if("${SRB2_CONFIG_SYSTEM_LIBRARIES}") + find_package(ZLIB REQUIRED) + find_package(PNG REQUIRED) + find_package(SDL2 REQUIRED) + find_package(SDL2_mixer REQUIRED) + find_package(CURL REQUIRED) + find_package(OPENMPT REQUIRED) + find_package(GME REQUIRED) + find_package(DiscordRPC REQUIRED) +endif() + +if(${PROJECT_SOURCE_DIR} MATCHES ${PROJECT_BINARY_DIR}) + message(FATAL_ERROR "In-source builds will bring you a world of pain. Please make a separate directory to invoke CMake from.") +endif() + +if ((${SRB2_USE_CCACHE}) AND (${CMAKE_C_COMPILER} MATCHES "clang")) + message(WARNING "Using clang and CCache: You may want to set environment variable CCACHE_CPP2=yes to prevent include errors during compile.") +endif() + +# Add sources from Sourcefile +function(target_sourcefile type) + file(STRINGS Sourcefile list + REGEX "[-0-9A-Za-z_]+\.${type}") + target_sources(SRB2SDL2 PRIVATE ${list}) +endfunction() # bitness check set(SRB2_SYSTEM_BITS 0) @@ -70,66 +171,39 @@ if(${SRB2_SYSTEM_BITS} EQUAL 0) message(STATUS "Target bitness is unknown") endif() -# OS macros -if (UNIX) - add_definitions(-DUNIXCOMMON) -endif() - -if(CMAKE_COMPILER_IS_GNUCC) - find_program(OBJCOPY objcopy) -endif() - -if(${CMAKE_SYSTEM} MATCHES "Linux") - add_definitions(-DLINUX) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - add_definitions(-DLINUX64) - endif() -endif() - -if(${CMAKE_SYSTEM} MATCHES "Darwin") - add_definitions(-DMACOSX) -endif() - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") # Set EXE names so the assets CMakeLists can refer to its target -set(SRB2_SDL2_EXE_NAME srb2kart CACHE STRING "Executable binary output name") -set(SRB2_WIN_EXE_NAME srb2kartdd CACHE STRING "Executable binary output name for DirectDraw build") +set(SRB2_SDL2_EXE_NAME "" CACHE STRING "Override executable binary output name") +set(SRB2_SDL2_EXE_SUFFIX "" CACHE STRING "Optional executable suffix, separated by an underscore") include_directories(${CMAKE_CURRENT_BINARY_DIR}/src) add_subdirectory(src) add_subdirectory(assets) - ## config.h generation set(GIT_EXECUTABLE "git" CACHE FILEPATH "Path to git binary") include(GitUtilities) git_latest_commit(SRB2_COMP_COMMIT "${CMAKE_SOURCE_DIR}") git_current_branch(SRB2_GIT_BRANCH "${CMAKE_SOURCE_DIR}") +#git_working_tree_dirty(SRB2_COMP_UNCOMMITTED "${CMAKE_SOURCE_DIR}") #TODO: fix this set(SRB2_COMP_BRANCH "${SRB2_GIT_BRANCH}") set(SRB2_COMP_REVISION "${SRB2_COMP_COMMIT}") configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/src/config.h) -##### PACKAGE CONFIGURATION ##### +if("${SRB2_SDL2_EXE_NAME}" STREQUAL "") + list(APPEND EXE_NAME_PARTS "srb2kart-saturn") -if(${CMAKE_SYSTEM} MATCHES "Windows") - set(CPACK_GENERATOR "ZIP") -endif() -if(${CMAKE_SYSTEM} MATCHES "Linux") - set(CPACK_GENERATOR "TGZ") -endif() -if(${CMAKE_SYSTEM} MATCHES "Darwin") - set(CPACK_GENERATOR "DragNDrop") + if(NOT "${SRB2_GIT_BRANCH}" STREQUAL "master") + list(APPEND EXE_NAME_PARTS ${SRB2_GIT_BRANCH}) + endif() +else() + list(APPEND EXE_NAME_PARTS ${SRB2_SDL2_EXE_NAME}) endif() -set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Sonic Robo Blast 2 Kart" CACHE STRING "Program name for display purposes") -set(CPACK_PACKAGE_VENDOR "Kart Krew" CACHE STRING "Vendor name for display purposes") -#set(CPACK_PACKAGE_DESCRIPTION_FILE ) -set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") -set(CPACK_PACKAGE_VERSION_MAJOR ${SRB2_VERSION_MAJOR}) -set(CPACK_PACKAGE_VERSION_MINOR ${SRB2_VERSION_MINOR}) -set(CPACK_PACKAGE_VERSION_PATCH ${SRB2_VERSION_PATCH}) -set(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMAKE_VERSION_MAJOR}.${CMAKE_VERSION_MINOR}") -include(CPack) +list(APPEND EXE_NAME_PARTS ${SRB2_SDL2_EXE_SUFFIX}) + +list(JOIN EXE_NAME_PARTS "_" EXE_NAME) +set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME ${EXE_NAME}) diff --git a/assets/CMakeLists.txt b/assets/CMakeLists.txt index 12be1c470..74744ab6a 100644 --- a/assets/CMakeLists.txt +++ b/assets/CMakeLists.txt @@ -1,59 +1,52 @@ ## Assets Target Configuration ## -# For prepending the current source path, later -FUNCTION(PREPEND var prefix) - SET(listVar "") - FOREACH(f ${ARGN}) - LIST(APPEND listVar "${prefix}/${f}") - ENDFOREACH(f) - SET(${var} "${listVar}" PARENT_SCOPE) -ENDFUNCTION(PREPEND) +if(${CMAKE_SYSTEM} MATCHES Linux) + # Asset installation isn't part of the Linux target + return() +endif() -set(SRB2_ASSET_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/installer" - CACHE STRING "Path to directory that contains all asset files for the installer.") +if("${SRB2_CONFIG_ASSET_DIRECTORY}" STREQUAL "") + message(WARNING "SRB2_CONFIG_ASSET_DIRECTORY is not set, so installation will not contain data files.") + return() +endif() -set(SRB2_ASSET_HASHED -"srb2.srb;\ -gfx.kart;\ -textures.kart;\ -chars.kart;\ -maps.kart" - CACHE STRING "Asset filenames to apply MD5 checks. No spaces between entries!" +get_filename_component(SRB2_ASSET_DIRECTORY_ABSOLUTE "${SRB2_CONFIG_ASSET_DIRECTORY}" ABSOLUTE) + +set(SRB2_ASSETS_DOCS + "README.txt" + "HISTORY.txt" + "README-SDL.txt" + "LICENSE.txt" + "LICENSE-3RD-PARTY.txt" ) +list(TRANSFORM SRB2_ASSETS_DOCS PREPEND "/") +list(TRANSFORM SRB2_ASSETS_DOCS PREPEND "${SRB2_ASSET_DIRECTORY_ABSOLUTE}") -set(SRB2_ASSET_DOCS -"README.txt;\ -HISTORY.txt;\ -LICENSE.txt;\ -LICENSE-3RD-PARTY.txt" - CACHE STRING "Documentation filenames. In OS X, these are packaged separately from other assets. No spaces between entries!" +#################### +# POST-V2.2 NOTE: Do not forget to add patch.pk3 to the end of this list! +#################### + +set(SRB2_ASSETS_GAME + "srb2.srb" + "gfx.kart" + "textures.kart" + "chars.kart" + "maps.kart" ) +list(TRANSFORM SRB2_ASSETS_GAME PREPEND "/") +list(TRANSFORM SRB2_ASSETS_GAME PREPEND "${SRB2_ASSET_DIRECTORY_ABSOLUTE}") -PREPEND(SRB2_ASSET_DOCS ${SRB2_ASSET_DIRECTORY} ${SRB2_ASSET_DOCS}) - -foreach(SRB2_ASSET ${SRB2_ASSET_HASHED}) - file(MD5 ${SRB2_ASSET_DIRECTORY}/${SRB2_ASSET} "SRB2_ASSET_${SRB2_ASSET}_HASH") - set(SRB2_ASSET_${SRB2_ASSET}_HASH ${SRB2_ASSET_${SRB2_ASSET}_HASH} PARENT_SCOPE) -endforeach() +set(SRB2_ASSETS ${SRB2_ASSET_DOCS} ${SRB2_ASSETS_GAME}) # Installation if(${CMAKE_SYSTEM} MATCHES Darwin) get_target_property(outname SRB2SDL2 OUTPUT_NAME) - install(DIRECTORY "${SRB2_ASSET_DIRECTORY}/" - DESTINATION "${outname}.app/Contents/Resources" - ) - install(FILES ${SRB2_ASSET_DOCS} - DESTINATION . - OPTIONAL - ) + install(FILES ${SRB2_ASSETS} DESTINATION "${outname}.app/Contents/Resources") + install(DIRECTORY "${SRB2_ASSET_DIRECTORY_ABSOLUTE}/models" DESTINATION "${outname}.app/Contents/Resources") + install(FILES ${SRB2_ASSETS_DOCS} DESTINATION .) else() - install(DIRECTORY "${SRB2_ASSET_DIRECTORY}/" - DESTINATION . - ) - # Docs are assumed to be located in SRB2_ASSET_DIRECTORY, so don't install again - #install(FILES ${SRB2_ASSET_DOCS} - # DESTINATION . - # OPTIONAL - #) + install(FILES ${SRB2_ASSETS} DESTINATION .) + install(DIRECTORY "${SRB2_ASSET_DIRECTORY_ABSOLUTE}/models" DESTINATION .) endif() + diff --git a/cmake/Comptime.cmake b/cmake/Comptime.cmake new file mode 100644 index 000000000..c3c1a4cd6 --- /dev/null +++ b/cmake/Comptime.cmake @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) + +set(CMAKE_BINARY_DIR "${BINARY_DIR}") +set(CMAKE_CURRENT_BINARY_DIR "${BINARY_DIR}") + +# Set up CMAKE path +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") + +include(GitUtilities) + +git_current_branch(SRB2_COMP_BRANCH) +git_working_tree_dirty(SRB2_COMP_UNCOMMITTED) + +git_latest_commit(SRB2_COMP_REVISION) +git_subject(subject) +string(REGEX REPLACE "([\"\\])" "\\\\\\1" SRB2_COMP_LASTCOMMIT "${subject}") + +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/config.h") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/build/src/config.h") diff --git a/cmake/Modules/FindDiscordRPC.cmake b/cmake/Modules/FindDiscordRPC.cmake index e71762767..2d3c987c1 100644 --- a/cmake/Modules/FindDiscordRPC.cmake +++ b/cmake/Modules/FindDiscordRPC.cmake @@ -21,3 +21,13 @@ find_library(DISCORDRPC_LIBRARY set(DISCORDRPC_PROCESS_INCLUDES DISCORDRPC_INCLUDE_DIR) set(DISCORDRPC_PROCESS_LIBS DISCORDRPC_LIBRARY) libfind_process(DISCORDRPC) + +if(DISCORDRPC_FOUND AND NOT TARGET DiscordRPC::DiscordRPC) + add_library(DiscordRPC::DiscordRPC UNKNOWN IMPORTED) + set_target_properties( + DiscordRPC::DiscordRPC + PROPERTIES + IMPORTED_LOCATION "${DISCORDRPC_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${DISCORDRPC_INCLUDE_DIR}" + ) +endif() diff --git a/cmake/Modules/FindGME.cmake b/cmake/Modules/FindGME.cmake index ea80af454..3af0a94be 100644 --- a/cmake/Modules/FindGME.cmake +++ b/cmake/Modules/FindGME.cmake @@ -20,4 +20,14 @@ find_library(GME_LIBRARY set(GME_PROCESS_INCLUDES GME_INCLUDE_DIR) set(GME_PROCESS_LIBS GME_LIBRARY) -libfind_process(GME) \ No newline at end of file +libfind_process(GME) + +if(GME_FOUND AND NOT TARGET gme) + add_library(gme UNKNOWN IMPORTED) + set_target_properties( + gme + PROPERTIES + IMPORTED_LOCATION "${GME_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${GME_INCLUDE_DIR}" + ) +endif() diff --git a/cmake/Modules/FindOPENMPT.cmake b/cmake/Modules/FindOPENMPT.cmake index 2d334b6f0..7e5b2d5a3 100644 --- a/cmake/Modules/FindOPENMPT.cmake +++ b/cmake/Modules/FindOPENMPT.cmake @@ -20,4 +20,14 @@ find_library(OPENMPT_LIBRARY set(OPENMPT_PROCESS_INCLUDES OPENMPT_INCLUDE_DIR) set(OPENMPT_PROCESS_LIBS OPENMPT_LIBRARY) -libfind_process(OPENMPT) \ No newline at end of file +libfind_process(OPENMPT) + +if(OPENMPT_FOUND AND NOT TARGET openmpt) + add_library(openmpt UNKNOWN IMPORTED) + set_target_properties( + openmpt + PROPERTIES + IMPORTED_LOCATION "${OPENMPT_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${OPENMPT_INCLUDE_DIR}" + ) +endif() diff --git a/cmake/Modules/FindSDL2.cmake b/cmake/Modules/FindSDL2.cmake index 2fc833cef..2d625f84c 100644 --- a/cmake/Modules/FindSDL2.cmake +++ b/cmake/Modules/FindSDL2.cmake @@ -31,3 +31,13 @@ find_library(SDL2_LIBRARY set(SDL2_PROCESS_INCLUDES SDL2_INCLUDE_DIR) set(SDL2_PROCESS_LIBS SDL2_LIBRARY) libfind_process(SDL2) + +if(SDL2_FOUND AND NOT TARGET SDL2::SDL2) + add_library(SDL2::SDL2 UNKNOWN IMPORTED) + set_target_properties( + SDL2::SDL2 + PROPERTIES + IMPORTED_LOCATION "${SDL2_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIR}" + ) +endif() diff --git a/cmake/Modules/FindSDL2_mixer.cmake b/cmake/Modules/FindSDL2_mixer.cmake index 9af3e26dd..637498e53 100644 --- a/cmake/Modules/FindSDL2_mixer.cmake +++ b/cmake/Modules/FindSDL2_mixer.cmake @@ -32,3 +32,13 @@ find_library(SDL2_MIXER_LIBRARY set(SDL2_MIXER_PROCESS_INCLUDES SDL2_MIXER_INCLUDE_DIR) set(SDL2_MIXER_PROCESS_LIBS SDL2_MIXER_LIBRARY) libfind_process(SDL2_MIXER) + +if(SDL2_MIXER_FOUND AND NOT TARGET SDL2_mixer::SDL2_mixer) + add_library(SDL2_mixer::SDL2_mixer UNKNOWN IMPORTED) + set_target_properties( + SDL2_mixer::SDL2_mixer + PROPERTIES + IMPORTED_LOCATION "${SDL2_MIXER_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${SDL2_MIXER_INCLUDE_DIR}" + ) +endif() diff --git a/cmake/Modules/GitUtilities.cmake b/cmake/Modules/GitUtilities.cmake index d29e6b509..cad925bd2 100644 --- a/cmake/Modules/GitUtilities.cmake +++ b/cmake/Modules/GitUtilities.cmake @@ -6,38 +6,54 @@ endif() set(__GitUtilities ON) -function(git_describe variable path) - execute_process(COMMAND "${GIT_EXECUTABLE}" "describe" - WORKING_DIRECTORY "${path}" - RESULT_VARIABLE result +macro(_git_command) + execute_process( + COMMAND "${GIT_EXECUTABLE}" ${ARGN} + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_VARIABLE output ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE ) +endmacro() + +macro(_git_easy_command) + _git_command(${ARGN}) + set(${variable} "${output}" PARENT_SCOPE) +endmacro() + +function(git_current_branch variable) + _git_command(symbolic-ref -q --short HEAD) + + # If a detached head, a ref could still be resolved. + if("${output}" STREQUAL "") + _git_command(describe --all --exact-match) + + # Get the ref, in the form heads/master or + # remotes/origin/master so isolate the final part. + string(REGEX REPLACE ".*/" "" output "${output}") + endif() set(${variable} "${output}" PARENT_SCOPE) endfunction() -function(git_current_branch variable path) - execute_process(COMMAND ${GIT_EXECUTABLE} "symbolic-ref" "--short" "HEAD" - WORKING_DIRECTORY "${path}" - RESULT_VARIABLE result - OUTPUT_VARIABLE output - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - - set(${variable} "${output}" PARENT_SCOPE) +function(git_latest_commit variable) + _git_easy_command(rev-parse --short HEAD) endfunction() -function(git_latest_commit variable path) - execute_process(COMMAND ${GIT_EXECUTABLE} "rev-parse" "--short" "HEAD" - WORKING_DIRECTORY "${path}" - RESULT_VARIABLE result - OUTPUT_VARIABLE output - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE - ) +function(git_working_tree_dirty variable) + _git_command(status --porcelain -uno) - set(${variable} "${output}" PARENT_SCOPE) -endfunction() \ No newline at end of file + if(output STREQUAL "") + set(${variable} FALSE PARENT_SCOPE) + else() + set(${variable} TRUE PARENT_SCOPE) + endif() +endfunction() + +function(git_subject variable) + _git_easy_command(log -1 "--format=%h %s") +endfunction() + +function(get_git_dir variable) + _git_easy_command(rev-parse --git-dir) +endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index de9cd142d..b6bd1c439 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,439 +1,148 @@ -# SRB2 Core +add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32) + +if(("${CMAKE_COMPILER_IS_GNUCC}" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows") + target_link_options(SRB2SDL2 PRIVATE "-Wl,--disable-dynamicbase") + if("${SRB2_CONFIG_STATIC_STDLIB}") + # On MinGW with internal libraries, link the standard library statically + if(CMAKE_LINKER_TYPE STREQUAL "LLD") + target_link_options(SRB2SDL2 PRIVATE -Wl, -static-libgcc -static-libstdc++ -static -lpthread) + else() + target_link_options(SRB2SDL2 PRIVATE -Wl,--add-stdcall-alias -static-libgcc -static-libstdc++ -static -lpthread) + endif() + set(THREADS_PREFER_PTHREAD_FLAG TRUE) + find_package(Threads REQUIRED) + target_link_libraries(SRB2SDL2 PRIVATE Threads::Threads) + endif() + if(CMAKE_SIZEOF_VOID_P EQUAL 4) + target_link_options(SRB2SDL2 PRIVATE "-Wl,--large-address-aware") + endif() +endif() + +set(SRB2_CONFIG_STD23 OFF CACHE BOOL + "Compiles the game under c23 and cxx23 instead c11 and cxx17.") + +if(SRB2_CONFIG_STD23) + message("-- Compiling game with C23 and CXX23.") + target_compile_features(SRB2SDL2 PRIVATE c_std_23 cxx_std_23) + set_property(TARGET SRB2SDL2 PROPERTY C_STANDARD 23) + set_property(TARGET SRB2SDL2 PROPERTY CXX_STANDARD 23) +else() + message("-- Compiling game with C11 and CXX17.") + target_compile_features(SRB2SDL2 PRIVATE c_std_11 cxx_std_17) + set_property(TARGET SRB2SDL2 PROPERTY C_STANDARD 11) + set_property(TARGET SRB2SDL2 PROPERTY CXX_STANDARD 17) +endif() # Core sources -set(SRB2_CORE_SOURCES - am_map.c - b_bot.c - command.c - comptime.c - console.c - d_clisrv.c - d_main.c - d_net.c - d_netcmd.c - d_netfil.c - d_protocol.c - dehacked.c - f_finale.c - f_wipe.c - filesrch.c - g_game.c - g_demo.c - g_input.c - hu_stuff.c - i_tcp.c - info.c - lzf.c - m_aatree.c - m_anigif.c - m_argv.c - m_bbox.c - m_cheat.c - m_cond.c - m_fixed.c - m_emotes.cpp - m_menu.c - m_textinput.c - m_misc.c - m_perfstats.c - m_queue.c - m_random.c - md5.c - mserv.c - http-mserv.c - qs22j.c - s_sound.c - screen.c - sounds.c - st_stuff.c - #string.c - tables.c - v_video.c - w_wad.c - y_inter.c - z_zone.cpp -) - -set(SRB2_CORE_HEADERS - am_map.h - b_bot.h - byteptr.h - command.h - console.h - cxxutil.hpp - d_clisrv.h - d_event.h - d_main.h - d_net.h - d_netcmd.h - d_netfil.h - d_player.h - d_protocol.h - d_think.h - d_ticcmd.h - dehacked.h - doomdata.h - doomdef.h - doomstat.h - doomtype.h - endian.h - f_finale.h - fastcmp.h - filesrch.h - g_game.h - g_demo.h - g_input.h - g_state.h - hu_stuff.h - i_joy.h - i_net.h - i_sound.h - i_system.h - i_tcp.h - i_time.h - i_video.h - info.h - keys.h - lzf.h - m_aatree.h - m_anigif.h - m_argv.h - m_bbox.h - m_cheat.h - m_cond.h - m_dllist.h - m_fixed.h - m_emotes.h - m_menu.h - m_textinput.h - m_misc.h - m_queue.h - m_perfstats.h - m_random.h - m_swap.h - md5.h - mserv.h - qs22j.h - s_sound.h - screen.h - sounds.h - st_stuff.h - tables.h - v_video.h - w_wad.h - y_inter.h - z_zone.h - - config.h.in -) - -set(SRB2_CORE_RENDER_SOURCES - r_bsp.cpp - r_data.c - r_draw.cpp - r_draw_column.cpp - r_draw_flush.cpp - r_draw_span.cpp - r_fps.cpp - r_main.cpp - r_patch.cpp - r_patchrotation.cpp - r_plane.cpp - r_segs.cpp - r_skins.c - r_sky.c - r_splats.c - r_things.cpp - r_portal.c - - r_bsp.h - r_data.h - r_defs.h - r_draw.h - r_fps.h - r_local.h - r_main.h - r_patch.h - r_patchrotation.h - r_plane.h - r_segs.h - r_skins.h - r_sky.h - r_splats.h - r_state.h - r_things.h - r_portal.h -) - -set(SRB2_CORE_GAME_SOURCES - p_ceilng.c - p_enemy.c - p_floor.c - p_inter.c - p_lights.c - p_map.c - p_maputl.cpp - p_mobj.c - p_polyobj.c - p_saveg.c - p_setup.c - p_sight.c - p_slopes.c - p_spec.c - p_telept.c - p_tick.c - p_user.c - k_director.c - k_kart.c - k_hud.c - k_stats.c - i_time.c - - p_local.h - p_maputl.h - p_mobj.h - p_polyobj.h - p_pspr.h - p_saveg.h - p_setup.h - p_slopes.h - p_spec.h - p_tick.h - k_director.h - k_kart.h - k_hud.h - k_stats.h -) - -if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) - set(SRB2_CORE_SOURCES ${SRB2_CORE_SOURCES} string.c) -endif() - -prepend_sources(SRB2_CORE_SOURCES) -prepend_sources(SRB2_CORE_HEADERS) -prepend_sources(SRB2_CORE_RENDER_SOURCES) -prepend_sources(SRB2_CORE_GAME_SOURCES) - -set(SRB2_CORE_HEADERS ${SRB2_CORE_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/config.h) -source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS}) -source_group("Renderer" FILES ${SRB2_CORE_RENDER_SOURCES}) -source_group("Game" FILES ${SRB2_CORE_GAME_SOURCES}) +target_sourcefile(c) +target_sources(SRB2SDL2 PRIVATE comptime.c config.h.in) ### Configuration -set(SRB2_CONFIG_HAVE_BLUA ON CACHE BOOL - "Enable Lua interpreter support") -set(SRB2_CONFIG_HAVE_PNG ON CACHE BOOL - "Enable PNG support. Depends on zlib, so will be disabled if you don't enable that too.") -set(SRB2_CONFIG_HAVE_ZLIB ON CACHE BOOL - "Enable zlib support.") -set(SRB2_CONFIG_HAVE_GME ON CACHE BOOL - "Enable GME support.") -set(SRB2_CONFIG_HAVE_OPENMPT ON CACHE BOOL - "Enable OpenMPT support.") -set(SRB2_CONFIG_HAVE_DISCORDRPC OFF CACHE BOOL - "Enable Discord rich presence support.") -set(SRB2_CONFIG_HAVE_CURL ON CACHE BOOL - "Enable curl support, used for downloading files via HTTP.") -set(SRB2_CONFIG_HWRENDER ON CACHE BOOL - "Enable hardware rendering through OpenGL.") -set(SRB2_CONFIG_STATIC_OPENGL OFF CACHE BOOL - "Use statically linked OpenGL. NOT RECOMMENDED.") -set(SRB2_CONFIG_USE_FBO_OGL ON CACHE BOOL - "Enable OpenGL FBO Downsampling support.") -set(SRB2_CONFIG_DEDICATED OFF CACHE BOOL - "Build a dedicated server.") +set(SRB2_CONFIG_DEV_BUILD OFF CACHE BOOL + "Compile a development build of SRB2Kart.") -if(${SRB2_CONFIG_DEDICATED}) - set(SRB2_CONFIG_HAVE_GME NO) - set(SRB2_CONFIG_HAVE_OPENMPT NO) - set(SRB2_CONFIG_HWRENDER NO) -endif() +set(SRB2_CONFIG_SKIP_COMPTIME OFF CACHE BOOL + "Skip Comptime rebuild.") -### use internal libraries? -if(${CMAKE_SYSTEM} MATCHES "Windows") ###set on Windows only - set(SRB2_CONFIG_USE_INTERNAL_LIBRARIES OFF CACHE BOOL - "Use SRB2Kart's internal copies of required dependencies (SDL2, PNG, zlib, GME, OpenMPT).") -endif() - -if(${SRB2_CONFIG_HAVE_BLUA}) - add_definitions(-DHAVE_BLUA) - set(SRB2_LUA_SOURCES - lua_baselib.c - lua_blockmaplib.c - lua_consolelib.c - lua_hooklib.c - lua_hudlib.c - lua_hudlib_drawlist.c - lua_infolib.c - lua_maplib.c - lua_mathlib.c - lua_mobjlib.c - lua_playerlib.c - lua_script.c - lua_skinlib.c - lua_thinkerlib.c - lua_udatalib.c - lua_glib.c +if(NOT SRB2_CONFIG_SKIP_COMPTIME) + # This updates the modification time for comptime.c at the + # end of building so when the build system is ran next time, + # that file gets flagged. comptime.c will always be rebuilt. + # + # This begs the question, why always rebuild comptime.c? + # Some things like the git commit must be checked each time + # the program is built. But the build system determines which + # files should be rebuilt before anything else. So + # comptime.c, which only needs to be rebuilt based on + # information known at build time, must be told to rebuild + # before that information can be ascertained. + add_custom_command( + TARGET SRB2SDL2 + POST_BUILD + COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${CMAKE_CURRENT_SOURCE_DIR}/comptime.c ) - set(SRB2_LUA_HEADERS - lua_hook.h - lua_hud.h - lua_hudlib_drawlist.h - lua_libs.h - lua_script.h - lua_udatalib.h - lua_glib.h - ) - - prepend_sources(SRB2_LUA_SOURCES) - prepend_sources(SRB2_LUA_HEADERS) - - source_group("LUA" FILES ${SRB2_LUA_SOURCES} ${SRB2_LUA_HEADERS}) - - set(SRB2_BLUA_SOURCES - blua/lapi.c - blua/lauxlib.c - blua/lbaselib.c - blua/ldblib.c - blua/lcode.c - blua/ldebug.c - blua/ldo.c - blua/ldump.c - blua/lfunc.c - blua/lgc.c - blua/linit.c - blua/liolib.c - blua/llex.c - blua/lmem.c - blua/lobject.c - blua/lopcodes.c - blua/lparser.c - blua/lstate.c - blua/lstring.c - blua/lstrlib.c - blua/ltable.c - blua/ltablib.c - blua/ltm.c - blua/lundump.c - blua/lvm.c - blua/lzio.c - ) - set(SRB2_BLUA_HEADERS - blua/lapi.h - blua/lauxlib.h - blua/lcode.h - blua/ldebug.h - blua/ldo.h - blua/lfunc.h - blua/lgc.h - blua/llex.h - blua/llimits.h - blua/lmem.h - blua/lobject.h - blua/lopcodes.h - blua/lparser.h - blua/lstate.h - blua/lstring.h - blua/ltable.h - blua/ltm.h - blua/lua.h - blua/luaconf.h - blua/lualib.h - blua/lundump.h - blua/lvm.h - blua/lzio.h - ) - - prepend_sources(SRB2_BLUA_SOURCES) - prepend_sources(SRB2_BLUA_HEADERS) - - source_group("LUA\\Interpreter" FILES ${SRB2_BLUA_SOURCES} ${SRB2_BLUA_HEADERS}) endif() -if(${SRB2_CONFIG_HAVE_GME}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(GME_FOUND ON) - set(GME_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/gme/include) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win64 -lgme") - else() # 32-bit - set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win32 -lgme") - endif() - else() - find_package(GME) - endif() - if(${GME_FOUND}) - set(SRB2_HAVE_GME ON) - add_definitions(-DHAVE_LIBGME) - else() - message(WARNING "You have specified that GME is available but it was not found.") +set(GIT_EXECUTABLE "git" CACHE FILEPATH "Path to git binary") +add_custom_target(_SRB2_reconf ALL + COMMAND ${CMAKE_COMMAND} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DBINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/.. -P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Comptime.cmake + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.." +) +add_dependencies(SRB2SDL2 _SRB2_reconf) + +if(SRB2_CONFIG_ASAN) + target_compile_options(SRB2SDL2 PRIVATE -fsanitize=address) + target_link_options(SRB2SDL2 PRIVATE -fsanitize=address) +endif() + +if(SRB2_CONFIG_UBSAN) + target_compile_options(SRB2SDL2 PRIVATE -fsanitize=undefined) + target_link_options(SRB2SDL2 PRIVATE -fsanitize=undefined) +endif() + +if(SRB2_CONFIG_TIDY) + set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*") +endif() + +add_subdirectory(blua) +add_subdirectory(sdl) +add_subdirectory(core) + +# OS macros +if (UNIX) + target_compile_definitions(SRB2SDL2 PRIVATE -DUNIXCOMMON) +endif() + +if(CMAKE_COMPILER_IS_GNUCC) + find_program(OBJCOPY objcopy) +endif() + +if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") + target_compile_definitions(SRB2SDL2 PRIVATE -DLINUX) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + target_compile_definitions(SRB2SDL2 PRIVATE -DLINUX64) endif() endif() -if(${SRB2_CONFIG_HAVE_DISCORDRPC}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(DISCORDRPC_FOUND ON) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(DISCORDRPC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/discord-rpc/win64-dynamic/include) - set(DISCORDRPC_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/discord-rpc/win64-dynamic/lib -ldiscord-rpc") - else() # 32-bit - set(DISCORDRPC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/discord-rpc/win32-dynamic/include) - set(DISCORDRPC_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/discord-rpc/win32-dynamic/lib -ldiscord-rpc") - endif() - else() - find_package(DiscordRPC) - endif() - if(${DISCORDRPC_FOUND}) - set(SRB2_HAVE_DISCORDRPC ON) - add_definitions(-DHAVE_DISCORDRPC) - add_definitions(-DUSE_STUN) - set(SRB2_DISCORDRPC_SOURCES discord.c stun.c) - set(SRB2_DISCORDRPC_HEADERS discord.h stun.h) - prepend_sources(SRB2_DISCORDRPC_SOURCES) - prepend_sources(SRB2_DISCORDRPC_HEADERS) - source_group("Discord Rich Presence" FILES ${SRB2_DISCORDRPC_SOURCES} ${SRB2_DISCORDRPC_HEADERS}) - else() - message(WARNING "You have specified that Discord Rich Presence is available but it was not found.") - endif() +if("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") + target_compile_definitions(SRB2SDL2 PRIVATE -DMACOSX) endif() -if(${SRB2_CONFIG_HAVE_OPENMPT}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(OPENMPT_FOUND ON) - set(OPENMPT_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/inc) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86_64/mingw -lopenmpt") - else() # 32-bit - set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86/mingw -lopenmpt") - endif() - else() - find_package(OPENMPT) - endif() - if(${OPENMPT_FOUND}) - set(SRB2_HAVE_OPENMPT ON) - add_definitions(-DHAVE_OPENMPT) - else() - message(WARNING "You have specified that OpenMPT is available but it was not found.") - endif() +target_link_libraries(SRB2SDL2 PRIVATE openmpt) +target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_OPENMPT) + +target_link_libraries(SRB2SDL2 PRIVATE ZLIB::ZLIB PNG::PNG CURL::libcurl) +target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_ZLIB -DHAVE_PNG -DHAVE_CURL -D_LARGEFILE64_SOURCE) + +target_compile_definitions(SRB2SDL2 PRIVATE -DUSE_STUN) +if(SRB2_CONFIG_ENABLE_DISCORDRPC) + target_link_libraries(SRB2SDL2 PRIVATE DiscordRPC::DiscordRPC) + target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_DISCORDRPC) + target_sources(SRB2SDL2 PRIVATE discord.c) endif() +set(SRB2_HAVE_THREADS ON) +target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_THREADS) + if(${SRB2_CONFIG_HAVE_ZLIB}) if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) set(ZLIB_FOUND ON) - set(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/zlib) + set(ZLIB_COMPAT ON) + set(WITH_GTEST OFF) + set(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/thirdparty/zlib-ng) if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz64") + set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/thirdparty/zlib-ng/win32 -lz64") else() # 32-bit - set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz32") + set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/thirdparty/zlib-ng/win32 -lz32") endif() else() find_package(ZLIB) endif() if(${ZLIB_FOUND}) set(SRB2_HAVE_ZLIB ON) - add_definitions(-DHAVE_ZLIB) + target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_ZLIB) else() - message(WARNING "You have specified that ZLIB is available but it was not found. SRB2Kart may not compile correctly.") + message(WARNING "You have specified that ZLIB is available but it was not found. BlanKart may not compile correctly.") endif() endif() @@ -441,140 +150,286 @@ if(${SRB2_CONFIG_HAVE_PNG} AND ${SRB2_CONFIG_HAVE_ZLIB}) if (${ZLIB_FOUND}) if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) set(PNG_FOUND ON) - set(PNG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libpng-src) + set(PNG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/thirdparty/libpng-src) if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng64") + set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/thirdparty/libpng-src/projects -lpng64") else() # 32-bit - set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng32") + set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/thirdparty/libpng-src/projects -lpng32") endif() else() find_package(PNG) endif() if(${PNG_FOUND}) set(SRB2_HAVE_PNG ON) - add_definitions(-DHAVE_PNG) - add_definitions(-D_LARGEFILE64_SOURCE) - source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS}) + target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_PNG) + target_compile_definitions(SRB2SDL2 PRIVATE -D_LARGEFILE64_SOURCE) else() - message(WARNING "You have specified that PNG is available but it was not found. SRB2Kart may not compile correctly.") + message(WARNING "You have specified that PNG is available but it was not found. BlanKart may not compile correctly.") endif() endif() endif() -if(${SRB2_CONFIG_HAVE_CURL}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(CURL_FOUND ON) - set(CURL_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/curl/include) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib64 -lcurl") - else() # 32-bit - set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib32 -lcurl") +if("${SRB2_CONFIG_HWRENDER}") + target_compile_definitions(SRB2SDL2 PRIVATE -DHWRENDER) + add_subdirectory(hardware) + + if("${SRB2_CONFIG_STATIC_OPENGL}") + find_package(OpenGL) + if(${OPENGL_FOUND}) + target_compile_definitions(SRB2SDL2 PRIVATE -DSTATIC_OPENGL) + else() + message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.") endif() - else() - find_package(CURL) - endif() - if(${CURL_FOUND}) - set(SRB2_HAVE_CURL ON) - add_definitions(-DHAVE_CURL) - else() - message(WARNING "You have specified that CURL is available but it was not found. SRB2Kart may not compile correctly.") endif() endif() -if(${SRB2_CONFIG_HWRENDER}) - add_definitions(-DHWRENDER) - set(SRB2_HWRENDER_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_bsp.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_cache.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_draw.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_portal.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.c +# TODO: build this with the game +if(${CMAKE_SYSTEM} MATCHES Windows AND ${CMAKE_C_COMPILER_ID} MATCHES "GNU" AND ${SRB2_SYSTEM_BITS} EQUAL 32) + target_link_libraries(SRB2SDL2 PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty/drmingw/lib/win32/libexchndl.a" + "${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty/drmingw/lib/win32/libmgwhelp.a" ) - - set (SRB2_HWRENDER_HEADERS - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_data.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_defs.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_dll.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_gl.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_glob.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_portal.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.h - ) - - set(SRB2_R_OPENGL_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/r_opengl/r_opengl.c - ) - - set(SRB2_R_OPENGL_HEADERS - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/r_opengl/r_opengl.h - ) - -endif() - -if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) - find_package(OpenGL) - if(${OPENGL_FOUND}) - add_definitions(-DHWRENDER) - add_definitions(-DSTATIC_OPENGL) - else() - message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.") - endif() -endif() - -if(${SRB2_CONFIG_HWRENDER}) - if(${SRB2_CONFIG_USE_FBO_OGL}) - set(SRB2_USE_FBO_OGL ON) - add_definitions(-DUSE_FBO_OGL) - endif() + target_include_directories(SRB2SDL2 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../thirdparty/drmingw/include") endif() # Targets +# If using CCACHE, then force it. +# https://github.com/Cockatrice/Cockatrice/pull/3052/files +if ("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") + get_property(RULE_LAUNCH_COMPILE GLOBAL PROPERTY RULE_LAUNCH_COMPILE) + if(RULE_LAUNCH_COMPILE) + MESSAGE(STATUS "Force enabling CCache usage under macOS") + # Set up wrapper scripts + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/launch-c.in ${CMAKE_BINARY_DIR}/launch-c) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/launch-cxx.in ${CMAKE_BINARY_DIR}/launch-cxx) + execute_process(COMMAND chmod a+rx + "${CMAKE_BINARY_DIR}/launch-c" + "${CMAKE_BINARY_DIR}/launch-cxx") + + # Set Xcode project attributes to route compilation through our scripts + set(CMAKE_XCODE_ATTRIBUTE_CC "${CMAKE_BINARY_DIR}/launch-c") + set(CMAKE_XCODE_ATTRIBUTE_CXX "${CMAKE_BINARY_DIR}/launch-cxx") + set(CMAKE_XCODE_ATTRIBUTE_LD "${CMAKE_BINARY_DIR}/launch-c") + set(CMAKE_XCODE_ATTRIBUTE_LDPLUSPLUS "${CMAKE_BINARY_DIR}/launch-cxx") + endif() +endif() + # Compatibility flag with later versions of GCC # We should really fix our code to not need this -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -mno-ms-bitfields) +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + target_compile_options(SRB2SDL2 PRIVATE -mno-ms-bitfields) endif() -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-absolute-value) -endif() +# TODO: fix prng and P_CreateBlockmap overflow at some point +target_compile_options(SRB2SDL2 PRIVATE -fwrapv) -add_definitions(-DCMAKECONFIG) - -#add_library(SRB2Core STATIC -# ${SRB2_CORE_SOURCES} -# ${SRB2_CORE_HEADERS} -# ${SRB2_CORE_RENDER_SOURCES} -# ${SRB2_CORE_GAME_SOURCES} -# ${SRB2_LUA_SOURCES} -# ${SRB2_LUA_HEADERS} -# ${SRB2_BLUA_SOURCES} -# ${SRB2_BLUA_HEADERS} -#) - -if(${SRB2_CONFIG_DEDICATED}) - add_subdirectory(dedicated) +if (${CMAKE_BUILD_TYPE} MATCHES Debug) + target_compile_options(SRB2SDL2 PRIVATE -O0) else() - add_subdirectory(sdl) + target_compile_options(SRB2SDL2 PRIVATE -O3) endif() -if(NOT ${SRB2_SDL2_AVAILABLE} AND NOT ${SRB2_WIN32_AVAILABLE}) - message(FATAL_ERROR "There are no targets available to build an SRB2Kart executable. :(") +# Compiler warnings configuration +target_compile_options(SRB2SDL2 PRIVATE + # Using generator expressions to handle per-language compile options + + # C, GNU + # This is a direct translation from versions.mk + $<$,$>: + -Wall + -Wextra + -Wno-trigraphs + -W # Was controlled by RELAXWARNINGS + -Wfloat-equal + -Wundef + -Wpointer-arith + -Wbad-function-cast + -Wcast-qual + -Wcast-align # Was controlled by NOCASTALIGNWARN + -Wwrite-strings + -Wsign-compare + -Wno-comment + -Wno-alloc-size-larger-than # holy shit, be quiet up GCC + -Wmissing-prototypes + -Wmissing-declarations + -Wmissing-noreturn + -Wnested-externs + -Wformat-y2k + -Wformat-security + + $<$,2.9.5>: + -Wno-div-by-zero + -Wendif-labels + -Wdisabled-optimization + > + + $<$,4.0.0>: + -Wold-style-definition + -Wmissing-field-initializers + > + + $<$,4.1.0>: + -Wshadow + > + + $<$,4.3.0>: + -funit-at-a-time + -Wlogical-op + > + + $<$,4.5.0>: + -Wlogical-op + -Wno-error=array-bounds + > + + $<$,4.6.0>: + -Wno-suggest-attribute=noreturn + -Wno-error=suggest-attribute=noreturn + > + + $<$,5.4.0>: + -Wno-logical-op + -Wno-error=logical-op + > + + $<$,6.1.0>: + -Wno-tautological-compare + -Wno-error=tautological-compare + > + + $<$,7.1.0>: + -Wno-error=format-overflow=2 + -Wimplicit-fallthrough=4 + > + + $<$,8.1.0>: + -Wno-error=format-overflow + -Wno-error=stringop-truncation + -Wno-error=stringop-overflow + -Wno-format-overflow + -Wno-stringop-truncation + -Wno-stringop-overflow + -Wno-error=multistatement-macros + > + + $<$,9.1.0>: + -Wno-error=address-of-packed-member + > + > + + # C, Clang and Apple Clang + $<$,$,$>>: + -Wall + -Wextra + -Wno-absolute-value + -Wno-trigraphs + -Wno-error=non-literal-null-conversion + -Wno-error=constant-conversion + -Wno-unused-but-set-variable + -Wno-error=unused-but-set-variable + > + + # C++, GNU, Clang and Apple Clang + $<$,$,$,$>>: + -Wall + -Wno-unused-function + -Wno-unused-but-set-variable + -Wno-unused-private-field + > + + # GNU + $<$: + -fmax-errors=5 + > +) +if(SRB2_CONFIG_ERRORMODE) + target_compile_options(SRB2SDL2 PRIVATE + $<$,$,$>: + -Werror + > + ) +endif() + +# Link warnings configuration +target_link_options(SRB2SDL2 PRIVATE + $<$: + # -Wl,--as-needed - Was controlled by NOLDWARNING + > +) + +if(${SRB2_CONFIG_DEV_BUILD}) + target_compile_definitions(SRB2SDL2 PRIVATE -DDEVELOP) +endif() +#target_compile_definitions(SRB2SDL2 PRIVATE -DCMAKECONFIG) #TODO: fix this + +# Misc. build options from Makefiles +if(SRB2_CONFIG_DEBUGMODE) + target_compile_definitions(SRB2SDL2 PRIVATE -D_DEBUG -DZDEBUG -DPARANOIA -DRANGECHECK -DPACKETDROP) +endif() +if(SRB2_CONFIG_MOBJCONSISTANCY) + target_compile_definitions(SRB2SDL2 PRIVATE -DMOBJCONSISTANCY) +endif() +if(SRB2_CONFIG_PACKETDROP) + target_compile_definitions(SRB2SDL2 PRIVATE -DPACKETDROP) +endif() +if(SRB2_CONFIG_ZDEBUG) + target_compile_definitions(SRB2SDL2 PRIVATE -DZDEBUG) +endif() +if(SRB2_CONFIG_PROFILEMODE AND "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") + target_compile_options(SRB2SDL2 PRIVATE -pg) + target_link_options(SRB2SDL2 PRIVATE -pg) +endif() + +if(SRB2_CONFIG_LTO AND NOT SRB2_CONFIG_DEBUGMODE) + set_property(TARGET SRB2SDL2 PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) +endif() + +# strip debug symbols into separate file when using gcc or clang. +# to be consistent with Makefile, don't generate for OS X. +if((CMAKE_COMPILER_IS_GNUCC OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") AND NOT ("${CMAKE_SYSTEM_NAME}" MATCHES Darwin)) + if((${CMAKE_BUILD_TYPE} MATCHES Debug) OR (${CMAKE_BUILD_TYPE} MATCHES RelWithDebInfo)) + if(${CMAKE_BUILD_TYPE} MATCHES Debug) + set(OBJCOPY_ONLY_KEEP_DEBUG "--only-keep-debug") + endif() + message(STATUS "Will make separate debug symbols in *.debug") + add_custom_command(TARGET SRB2SDL2 POST_BUILD + COMMAND ${CMAKE_OBJCOPY} ${OBJCOPY_ONLY_KEEP_DEBUG} $ $.debug + # mold linker: .gnu_debuglink is present by default, so --add-gnu-debuglink would fail + COMMAND ${CMAKE_OBJCOPY} --strip-debug --remove-section=.gnu_debuglink $ + COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=$.debug $ + ) + endif() +endif() + +# copy DLLs to bin/ directory if building internal shared on windows +if("${CMAKE_SYSTEM_NAME}" STREQUAL Windows AND NOT "${SRB2_CONFIG_INTERNAL_LIBRARIES}" AND "${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}") + set(ADDITIONAL_DLLS "") + if("${CMAKE_C_COMPILER_ID}" STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + # also copy implicitly linked system libraries + get_filename_component(MINGW_BIN_PATH ${CMAKE_CXX_COMPILER} PATH) + if("${CMAKE_C_COMPILER_ID}" STREQUAL GNU) + list(APPEND ADDITIONAL_DLLS + "libgcc_s_dw2-1.dll" + "libstdc++-6.dll" + "libwinpthread-1.dll" + ) + else() + list(APPEND ADDITIONAL_DLLS + "libunwind.dll" + "libc++.dll" + "libwinpthread-1.dll" + ) + endif() + list(TRANSFORM ADDITIONAL_DLLS PREPEND "${MINGW_BIN_PATH}/") + endif() + add_custom_command(TARGET SRB2SDL2 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + ${ADDITIONAL_DLLS} + + $ + COMMAND_EXPAND_LISTS + COMMENT "Copying runtime DLLs" + ) endif() diff --git a/src/blua/CMakeLists.txt b/src/blua/CMakeLists.txt new file mode 100644 index 000000000..4e9c67d2f --- /dev/null +++ b/src/blua/CMakeLists.txt @@ -0,0 +1 @@ +target_sourcefile(c) diff --git a/src/hardware/CMakeLists.txt b/src/hardware/CMakeLists.txt new file mode 100644 index 000000000..4e9c67d2f --- /dev/null +++ b/src/hardware/CMakeLists.txt @@ -0,0 +1 @@ +target_sourcefile(c) diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt index 5a5d19890..d40d39ad7 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -1,350 +1,117 @@ # Declare SDL2 interface sources -set(SRB2_CONFIG_SDL2_USEMIXER ON CACHE BOOL "Use SDL2_mixer or regular sdl sound") - -if(${SRB2_CONFIG_SDL2_USEMIXER}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(SDL2_MIXER_FOUND ON) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(SDL2_MIXER_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/SDL2_mixer/x86_64-w64-mingw32/include/SDL2) - set(SDL2_MIXER_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/SDL2_mixer/x86_64-w64-mingw32/lib -lSDL2_mixer") - else() # 32-bit - set(SDL2_MIXER_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/SDL2_mixer/i686-w64-mingw32/include/SDL2) - set(SDL2_MIXER_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/SDL2_mixer/i686-w64-mingw32/lib -lSDL2_mixer") - endif() - else() - find_package(SDL2_mixer) - endif() - if(${SDL2_MIXER_FOUND}) - set(SRB2_HAVE_MIXER ON) - set(SRB2_SDL2_SOUNDIMPL mixer_sound.c) - else() - message(WARNING "You specified that SDL2_mixer is available, but it was not found. Falling back to sdl sound.") - set(SRB2_SDL2_SOUNDIMPL sdl_sound.c) - endif() -else() - set(SRB2_SDL2_SOUNDIMPL sdl_sound.c) -endif() - -set(SRB2_SDL2_SOURCES +target_sources(SRB2SDL2 PRIVATE + mixer_sound.c + ogl_sdl.c + i_threads.c + i_net.c + i_system.cpp + i_main.c + i_video.c dosstr.c endtxt.c hwsym_sdl.c - i_main.c - i_net.c - i_system.cpp - i_ttf.c - i_video.c - i_threads.c - #IMG_xpm.c - ogl_sdl.c - - ${SRB2_SDL2_SOUNDIMPL} ) -set(SRB2_SDL2_HEADERS - endtxt.h - hwsym_sdl.h - i_ttf.h - ogl_sdl.h - sdlmain.h -) - -source_group("Interface Code" FILES ${SRB2_SDL2_SOURCES} ${SRB2_SDL2_HEADERS}) - -# Dependency -if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(SDL2_FOUND ON) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(SDL2_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/SDL2/x86_64-w64-mingw32/include/SDL2) - set(SDL2_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/SDL2/x86_64-w64-mingw32/lib -lSDL2") - else() # 32-bit - set(SDL2_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/SDL2/i686-w64-mingw32/include/SDL2) - set(SDL2_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/SDL2/i686-w64-mingw32/lib -lSDL2") - endif() -else() - find_package(SDL2) +if("${CMAKE_SYSTEM_NAME}" MATCHES Windows) + target_sources(SRB2SDL2 PRIVATE + ../win32/win_dbg.c + ../win32/Srb2win.rc) endif() -if(${SDL2_FOUND}) - set(SRB2_SDL2_TOTAL_SOURCES - ${SRB2_CORE_SOURCES} - ${SRB2_CORE_HEADERS} - ${SRB2_DISCORDRPC_SOURCES} - ${SRB2_DISCORDRPC_HEADERS} - ${SRB2_PNG_SOURCES} - ${SRB2_PNG_HEADERS} - ${SRB2_CORE_RENDER_SOURCES} - ${SRB2_CORE_GAME_SOURCES} - ${SRB2_LUA_SOURCES} - ${SRB2_LUA_HEADERS} - ${SRB2_BLUA_SOURCES} - ${SRB2_BLUA_HEADERS} - ${SRB2_SDL2_SOURCES} - ${SRB2_SDL2_HEADERS} +if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin) + set(MACOSX_BUNDLE_ICON_FILE Srb2mac.icns) + set_source_files_properties(macosx/Srb2mac.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") + target_sources(SRB2SDL2 PRIVATE + macosx/mac_alert.c + macosx/mac_alert.h + macosx/mac_resources.c + macosx/mac_resources.h + macosx/Srb2mac.icns ) +endif() - source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS} - ${SRB2_PNG_SOURCES} ${SRB2_PNG_HEADERS}) - source_group("Renderer" FILES ${SRB2_CORE_RENDER_SOURCES}) - source_group("Game" FILES ${SRB2_CORE_GAME_SOURCES}) - source_group("Discord Rich Presence" FILES ${SRB2_DISCORDRPC_SOURCES} ${SRB2_DISCORDRPC_HEADERS}) - source_group("Assembly" FILES ${SRB2_ASM_SOURCES} ${SRB2_NASM_SOURCES}) - source_group("LUA" FILES ${SRB2_LUA_SOURCES} ${SRB2_LUA_HEADERS}) - source_group("LUA\\Interpreter" FILES ${SRB2_BLUA_SOURCES} ${SRB2_BLUA_HEADERS}) - - - if(${SRB2_CONFIG_HWRENDER}) - set(SRB2_SDL2_TOTAL_SOURCES ${SRB2_SDL2_TOTAL_SOURCES} - ${SRB2_HWRENDER_SOURCES} - ${SRB2_HWRENDER_HEADERS} - ${SRB2_R_OPENGL_SOURCES} - ${SRB2_R_OPENGL_HEADERS} - ) - - source_group("Hardware" FILES ${SRB2_HWRENDER_SOURCES} ${SRB2_HWRENDER_HEADERS}) - source_group("Hardware\\OpenGL Renderer" FILES ${SRB2_R_OPENGL_SOURCES} ${SRB2_R_OPENGL_HEADERS}) - endif() - - if(${SRB2_USEASM}) - set(SRB2_SDL2_TOTAL_SOURCES ${SRB2_SDL2_TOTAL_SOURCES} - ${SRB2_NASM_SOURCES} - ) - endif() - - if(${CMAKE_SYSTEM} MATCHES Windows) - set(SRB2_SDL2_TOTAL_SOURCES ${SRB2_SDL2_TOTAL_SOURCES} - ${CMAKE_SOURCE_DIR}/src/win32/win_dbg.c - ${CMAKE_SOURCE_DIR}/src/win32/Srb2win.rc - ) - endif() - - if(${CMAKE_SYSTEM} MATCHES Darwin) - set(MACOSX_BUNDLE_ICON_FILE Srb2mac.icns) - set_source_files_properties(macosx/Srb2mac.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") - set(SRB2_SDL2_MAC_SOURCES - macosx/mac_alert.c - macosx/mac_alert.h - macosx/mac_resources.c - macosx/mac_resources.h - macosx/Srb2mac.icns - ) - source_group("Interface Code\\OSX Compatibility" FILES ${SRB2_SDL2_MAC_SOURCES}) - set(SRB2_SDL2_TOTAL_SOURCES ${SRB2_SDL2_TOTAL_SOURCES} ${SRB2_SDL2_MAC_SOURCES}) - endif() - - add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32 ${SRB2_SDL2_TOTAL_SOURCES}) - set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME ${SRB2_SDL2_EXE_NAME}) - - if(${CMAKE_SYSTEM} MATCHES Darwin) - find_library(CORE_FOUNDATION_LIBRARY "CoreFoundation") - target_link_libraries(SRB2SDL2 PRIVATE - ${CORE_FOUNDATION_LIBRARY} - ) - set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") - - # Configure the app bundle icon and plist properties - target_sources(SRB2SDL2 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/macosx/Srb2mac.icns") - set_target_properties(SRB2SDL2 PROPERTIES - MACOSX_BUNDLE_ICON_FILE "Srb2mac" - MACOSX_BUNDLE_BUNDLE_NAME "Sonic Robo Blast 2" - MACOSX_BUNDLE_BUNDLE_VERSION ${SRB2_VERSION} - - RESOURCE "${CMAKE_CURRENT_SOURCE_DIR}/macosx/Srb2mac.icns" - ) - endif() - +if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin) + find_library(CORE_FOUNDATION_LIBRARY "CoreFoundation") target_link_libraries(SRB2SDL2 PRIVATE - ${SDL2_LIBRARIES} - ${SDL2_MIXER_LIBRARIES} - ${GME_LIBRARIES} - ${OPENMPT_LIBRARIES} - ${MIXERX_LIBRARIES} - ${PNG_LIBRARIES} - ${ZLIB_LIBRARIES} - ${OPENGL_LIBRARIES} - ${CURL_LIBRARIES} - ${DISCORDRPC_LIBRARIES} + ${CORE_FOUNDATION_LIBRARY} ) - if(${CMAKE_SYSTEM} MATCHES Linux) - target_link_libraries(SRB2SDL2 PRIVATE - m - rt - ) - endif() - - if(${CMAKE_SYSTEM} MATCHES Windows AND ${CMAKE_C_COMPILER_ID} MATCHES "GNU" AND ${SRB2_SYSTEM_BITS} EQUAL 32) - target_link_libraries(SRB2SDL2 PRIVATE - "${CMAKE_CURRENT_SOURCE_DIR}/../../libs/drmingw/lib/win32/libexchndl.a" - "${CMAKE_CURRENT_SOURCE_DIR}/../../libs/drmingw/lib/win32/libmgwhelp.a" - ) - target_include_directories(SRB2SDL2 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../../libs/drmingw/include") - endif() - #target_link_libraries(SRB2SDL2 PRIVATE SRB2Core) + set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}") - if(${SRB2_USEASM}) - if(${SRB2_CONFIG_YASM}) - set(ASM_ASSEMBLER_TEMP ${CMAKE_ASM_YASM_COMPILER}) - set(ASM_ASSEMBLER_OBJFORMAT ${CMAKE_ASM_YASM_OBJECT_FORMAT}) - set_source_files_properties(${SRB2_NASM_SOURCES} LANGUAGE ASM_YASM) - else() - set(ASM_ASSEMBLER_TEMP ${CMAKE_ASM_NASM_COMPILER}) - set(ASM_ASSEMBLER_OBJFORMAT ${CMAKE_ASM_NASM_OBJECT_FORMAT}) - set_source_files_properties(${SRB2_NASM_SOURCES} LANGUAGE ASM_NASM) - endif() - endif() + # Configure the app bundle icon and plist properties + target_sources(SRB2SDL2 PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/macosx/Srb2mac.icns") + set_target_properties(SRB2SDL2 PROPERTIES + MACOSX_BUNDLE_ICON_FILE "Srb2mac" + MACOSX_BUNDLE_BUNDLE_NAME "SRB2Kart-Saturn" + MACOSX_BUNDLE_BUNDLE_VERSION 1.6 - if(${CMAKE_SYSTEM} MATCHES Windows) - target_link_libraries(SRB2SDL2 PRIVATE - ws2_32 - ) - target_compile_options(SRB2SDL2 PRIVATE - -U_WINDOWS - ) - endif() - - target_include_directories(SRB2SDL2 PRIVATE - ${SDL2_INCLUDE_DIRS} - ${SDL2_MIXER_INCLUDE_DIRS} - ${GME_INCLUDE_DIRS} - ${OPENMPT_INCLUDE_DIRS} - ${PNG_INCLUDE_DIRS} - ${ZLIB_INCLUDE_DIRS} - ${OPENGL_INCLUDE_DIRS} - ${CURL_INCLUDE_DIRS} - ${DISCORDRPC_INCLUDE_DIRS} + RESOURCE "${CMAKE_CURRENT_SOURCE_DIR}/macosx/Srb2mac.icns" ) - - if(${SRB2_HAVE_MIXER}) - target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_MIXER -DSOUND=SOUND_MIXER) - endif() - - target_compile_definitions(SRB2SDL2 PRIVATE - -DHAVE_SDL - -DHAVE_THREADS - ) - - ## strip debug symbols into separate file when using gcc - # if(CMAKE_COMPILER_IS_GNUCC) - # if(${CMAKE_BUILD_TYPE} MATCHES Debug) - # message(STATUS "Will make separate debug symbols in *.debug") - # add_custom_command(TARGET SRB2SDL2 POST_BUILD - # COMMAND ${OBJCOPY} --only-keep-debug $ $.debug - # COMMAND ${OBJCOPY} --strip-debug $ - # COMMAND ${OBJCOPY} --add-gnu-debuglink=$.debug $ - # ) - # endif() - # endif() - - #### Installation #### - if(${CMAKE_SYSTEM} MATCHES Darwin) - install(TARGETS SRB2SDL2 - BUNDLE DESTINATION . - ) - set_property(TARGET SRB2SDL2 PROPERTY INSTALL_RPATH_USE_LINK_PATH ON) - else() - install(TARGETS SRB2SDL2 SRB2SDL2 - RUNTIME DESTINATION . - ) - endif() - - if(${CMAKE_SYSTEM} MATCHES Windows) - set(win_extra_dll_list "") - macro(getwinlib dllname defaultname) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - if (${CMAKE_GENERATOR} STREQUAL "MinGW Makefiles") - if(${SRB2_SYSTEM_BITS} EQUAL 64) - find_library(SRB2_SDL2_DLL_${dllname} "${defaultname}" - HINTS ${CMAKE_SOURCE_DIR}/libs/dll-binaries/x86_64 - HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2/x86_64-w64-mingw32/bin - HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2_mixer/x86_64-w64-mingw32/bin - HINTS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/bin/x86_64/mingw - ) - else() - find_library(SRB2_SDL2_DLL_${dllname} "${defaultname}" - HINTS ${CMAKE_SOURCE_DIR}/libs/dll-binaries/i686 - HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2/i686-w64-mingw32/bin - HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2_mixer/i686-w64-mingw32/bin - HINTS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/bin/x86/mingw - ) - endif() - else() - if(${SRB2_SYSTEM_BITS} EQUAL 64) - find_library(SRB2_SDL2_DLL_${dllname} "${defaultname}" - HINTS ${CMAKE_SOURCE_DIR}/libs/dll-binaries/x86_64 - HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2/lib/x64 - HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2_mixer/lib/x64 - HINTS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/bin/x86_64/mingw - ) - else() - find_library(SRB2_SDL2_DLL_${dllname} "${defaultname}" - HINTS ${CMAKE_SOURCE_DIR}/libs/dll-binaries/i686 - HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2/lib/x86 - HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2_mixer/lib/x86 - HINTS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/bin/x86/mingw - ) - endif() - endif() - - list(APPEND win_extra_dll_list ${SRB2_SDL2_DLL_${dllname}}) - else() - find_library(SRB2_SDL2_DLL_${dllname} "${defaultname}") - list(APPEND win_extra_dll_list ${SRB2_SDL2_DLL_${dllname}}) - endif() - endmacro() - getwinlib(SDL2 "SDL2.dll") - if(${SRB2_CONFIG_SDL2_USEMIXER}) - getwinlib(SDL2_mixer "SDL2_mixer.dll") - getwinlib(libogg_0 "libogg-0.dll") - getwinlib(libvorbis_0 "libvorbis-0.dll") - getwinlib(libvorbisfile_3 "libvorbisfile-3.dll") - endif() - if(${SRB2_CONFIG_HAVE_GME}) - getwinlib(libgme "libgme.dll") - endif() - if(${SRB2_CONFIG_HAVE_OPENMPT}) - getwinlib(libopenmpt "libopenmpt.dll") - endif() - - if(${SRB2_CONFIG_HAVE_DISCORDRPC}) - getwinlib(discord-rpc "discord-rpc.dll") - endif() - - install(PROGRAMS - ${win_extra_dll_list} - DESTINATION . - ) - - # We also want to copy those DLLs to build directories on MSVC. - # So we'll add a post_build step. - copy_files_to_build_dir(SRB2SDL2 win_extra_dll_list) - endif() - - - # Mac bundle fixup - # HACK: THIS IS IMPORTANT! See the escaped \${CMAKE_INSTALL_PREFIX}? This - # makes it so that var is evaluated LATER during cpack, not right now! - # This fixes the quirk where the bundled libraries don't land in the final package - # https://cmake.org/pipermail/cmake/2011-March/043532.html - # - # HOWEVER: ${CPACK_PACKAGE_DESCRIPTION_SUMMARY} is NOT escaped, because that var - # is only available to us at this step. Read the link: ${CMAKE_INSTALL_PREFIX} at - # this current step points to the CMAKE build folder, NOT the folder that CPACK uses. - # Therefore, it makes sense to escape that var, but not the other. - if(${CMAKE_SYSTEM} MATCHES Darwin) - install(CODE " - include(BundleUtilities) - fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${CPACK_PACKAGE_DESCRIPTION_SUMMARY}.app\" - \"\" - /Library/Frameworks - )" - ) - endif() - - set(SRB2_SDL2_AVAILABLE YES PARENT_SCOPE) -else() - message(WARNING "SDL2 was not found, so the SDL2 target will not be available.") - set(SRB2_SDL2_AVAILABLE NO PARENT_SCOPE) endif() + +if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}" AND NOT "${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}") + target_link_libraries(SRB2SDL2 PRIVATE SDL2::SDL2-static SDL2_mixer::SDL2_mixer-static) +else() + target_link_libraries(SRB2SDL2 PRIVATE SDL2::SDL2 SDL2_mixer::SDL2_mixer) +endif() + +if("${CMAKE_SYSTEM_NAME}" MATCHES Linux) + target_link_libraries(SRB2SDL2 PRIVATE m rt) +endif() + +if("${CMAKE_SYSTEM_NAME}" MATCHES Windows) + target_link_libraries(SRB2SDL2 PRIVATE + ws2_32 + ) + target_compile_options(SRB2SDL2 PRIVATE + -U_WINDOWS + ) +endif() + +target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_MIXER -DSOUND=SOUND_MIXER) +target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_SDL) + +#### Installation #### +if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin) + install(TARGETS SRB2SDL2 + BUNDLE DESTINATION . + ) + set_property(TARGET SRB2SDL2 PROPERTY INSTALL_RPATH_USE_LINK_PATH ON) +else() + install(TARGETS SRB2SDL2 SRB2SDL2 + RUNTIME DESTINATION . + ) + if ((${CMAKE_BUILD_TYPE} MATCHES Debug) OR (${CMAKE_BUILD_TYPE} MATCHES RelWithDebInfo)) + set(SRB2_DEBUG_INSTALL OFF CACHE BOOL "Insert *.debug file into the install directory or package.") + if (${SRB2_DEBUG_INSTALL}) + install(FILES $.debug + DESTINATION . + OPTIONAL + ) + endif() + endif() +endif() + +# Mac bundle fixup +# HACK: THIS IS IMPORTANT! See the escaped \${CMAKE_INSTALL_PREFIX}? This +# makes it so that var is evaluated LATER during cpack, not right now! +# This fixes the quirk where the bundled libraries don't land in the final package +# https://cmake.org/pipermail/cmake/2011-March/043532.html +# +# HOWEVER: ${CPACK_PACKAGE_DESCRIPTION_SUMMARY} is NOT escaped, because that var +# is only available to us at this step. Read the link: ${CMAKE_INSTALL_PREFIX} at +# this current step points to the CMAKE build folder, NOT the folder that CPACK uses. +# Therefore, it makes sense to escape that var, but not the other. +if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin) + install(CODE " + include(BundleUtilities) + fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${CPACK_PACKAGE_DESCRIPTION_SUMMARY}.app\" + \"\" + /Library/Frameworks + )" + ) +endif() + +set(SRB2_SDL2_AVAILABLE YES PARENT_SCOPE)