diff --git a/.gitignore b/.gitignore index 7023aaa80..3eca1c57a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ Win32_LIB_ASM_Release /assets/debian /make /bin +/build diff --git a/CMakeLists.txt b/CMakeLists.txt index 0771f712c..c6cd6c3d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,15 @@ -cmake_minimum_required(VERSION 3.13) +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) -# Enable CCache early -set(SRB2_USE_CCACHE OFF CACHE BOOL "Use CCache") -if (${SRB2_USE_CCACHE}) - find_program(CCACHE_PROGRAM ccache) - if(CCACHE_PROGRAM) - message(STATUS "Found CCache: ${CCACHE_PROGRAM}") - set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") - else() - message(WARNING "You have specified to use CCACHE but it was not found. Object files will not be cached.") - endif() +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/") + +include(CMakeDependentOption) +include(cmake/CPM.cmake) + file(STRINGS src/version.h SRB2_VERSION) string(REGEX MATCH "[0-9]+\\.[0-9.]+" SRB2_VERSION ${SRB2_VERSION}) @@ -19,117 +17,11 @@ string(REGEX MATCH "[0-9]+\\.[0-9.]+" SRB2_VERSION ${SRB2_VERSION}) # Version change is fine. project(SRB2 VERSION ${SRB2_VERSION} - LANGUAGES C) + LANGUAGES C CXX) -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() - -# Set up CMAKE path -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") - -### Useful functions - -# Add sources from Sourcefile -function(target_sourcefile type) - file(STRINGS Sourcefile list - REGEX "[-0-9A-Za-z_]+\.${type}") - target_sources(SRB2SDL2 PRIVATE ${list}) -endfunction() - -# 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() - -# 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() - endif() -endmacro() - -# bitness check -set(SRB2_SYSTEM_BITS 0) -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - message(STATUS "Target is 64-bit") - set(SRB2_SYSTEM_BITS 64) -endif() -if(CMAKE_SIZEOF_VOID_P EQUAL 4) - message(STATUS "Target is 32-bit") - set(SRB2_SYSTEM_BITS 32) -endif() -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 ringracers CACHE STRING "Executable binary output name") - -include_directories(${CMAKE_CURRENT_BINARY_DIR}/src) - -## 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}") -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) - -add_subdirectory(src) -if(NOT ${SRB2_CONFIG_DEV_BUILD}) - add_subdirectory(assets) +if(APPLE) + # DiscordRPC needs but does not properly specify ObjC + enable_language(OBJC) endif() ##### PACKAGE CONFIGURATION ##### @@ -137,11 +29,11 @@ endif() 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} MATCHES "Windows") + if("${CMAKE_SYSTEM_NAME}" MATCHES "Windows") set(SRB2_CPACK_GENERATOR "ZIP") - elseif(${CMAKE_SYSTEM} MATCHES "Linux") + elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") set(SRB2_CPACK_GENERATOR "TGZ") - elseif(${CMAKE_SYSTEM} MATCHES "Darwin") + elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin") set(SRB2_CPACK_GENERATOR "TGZ") endif() endif() @@ -157,3 +49,132 @@ 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} +) +# 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_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) +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.") + +# 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() + CPMAddPackage( + NAME Ccache.cmake + GITHUB_REPOSITORY TheLartians/Ccache.cmake + VERSION 1.2 + ) +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) +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + message(STATUS "Target is 64-bit") + set(SRB2_SYSTEM_BITS 64) +endif() +if(CMAKE_SIZEOF_VOID_P EQUAL 4) + message(STATUS "Target is 32-bit") + set(SRB2_SYSTEM_BITS 32) +endif() +if(${SRB2_SYSTEM_BITS} EQUAL 0) + message(STATUS "Target bitness is unknown") +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 ringracers CACHE STRING "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}") +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) + + +list(APPEND EXE_NAME_PARTS ${SRB2_SDL2_EXE_NAME}) +if(NOT "${SRB2_GIT_BRANCH}" STREQUAL "master") + list(APPEND EXE_NAME_PARTS ${SRB2_GIT_BRANCH}) +endif() +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 a8f4cac5c..42243c9c1 100644 --- a/assets/CMakeLists.txt +++ b/assets/CMakeLists.txt @@ -1,75 +1,53 @@ ## 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_INSTALL ON - CACHE BOOL "Insert asset files into the install directory or package.") +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}") #################### # POST-V2.2 NOTE: Do not forget to add patch.pk3 to the end of this list! #################### -set(SRB2_ASSET_HASHED -"main.kart;\ -gfx.pk3;\ -textures.pk3;\ -chars.pk3;\ -maps.pk3;\ -patch.pk3" - CACHE STRING "Asset filenames to apply MD5 checks. No spaces between entries!" +set(SRB2_ASSETS_GAME + "main.kart" + "gfx.pk3" + "textures.pk3" + "chars.pk3" + "maps.pk3" + "followers.pk3" + "patch.pk3" ) +list(TRANSFORM SRB2_ASSETS_GAME PREPEND "/") +list(TRANSFORM SRB2_ASSETS_GAME PREPEND "${SRB2_ASSET_DIRECTORY_ABSOLUTE}") -set(SRB2_ASSET_DOCS -"README.txt;\ -HISTORY.txt;\ -LICENSE.txt;\ -LICENSE-3RD-PARTY.txt;\ -README-SDL.txt" - CACHE STRING "Documentation filenames. In OS X, these are packaged separately from other assets. No spaces between entries!" -) - -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) - if(${SRB2_ASSET_INSTALL}) - install(DIRECTORY "${SRB2_ASSET_DIRECTORY}/" - DESTINATION "${outname}.app/Contents/Resources" - ) - endif() - # Always install the doc files, even in non-asset packages. - 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() - if(${SRB2_ASSET_INSTALL}) - install(DIRECTORY "${SRB2_ASSET_DIRECTORY}/" - DESTINATION . - ) - # Docs are assumed to be located in SRB2_ASSET_DIRECTORY, so don't install them in their own call. - else() - # Always install the doc files, even in non-asset packages. - install(FILES ${SRB2_ASSET_DOCS} - DESTINATION . - OPTIONAL - ) - endif() + install(FILES ${SRB2_ASSETS} DESTINATION .) + install(DIRECTORY "${SRB2_ASSET_DIRECTORY_ABSOLUTE}/models" DESTINATION .) endif() diff --git a/cmake/CPM.cmake b/cmake/CPM.cmake new file mode 100644 index 000000000..772103fc3 --- /dev/null +++ b/cmake/CPM.cmake @@ -0,0 +1,21 @@ +set(CPM_DOWNLOAD_VERSION 0.36.0) + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) +if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION})) + message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}") + file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} + ) +endif() + +include(${CPM_DOWNLOAD_LOCATION}) 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/launch-c.in b/cmake/launch-c.in deleted file mode 100644 index c60558232..000000000 --- a/cmake/launch-c.in +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -export CCACHE_CPP2=true -exec "${RULE_LAUNCH_COMPILE}" "${CMAKE_C_COMPILER}" "$@" diff --git a/cmake/launch-cxx.in b/cmake/launch-cxx.in deleted file mode 100644 index c60558232..000000000 --- a/cmake/launch-cxx.in +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -export CCACHE_CPP2=true -exec "${RULE_LAUNCH_COMPILE}" "${CMAKE_C_COMPILER}" "$@" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d08fe0faa..5b681d042 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,12 @@ -# SRB2 Core - add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32) +if("${CMAKE_COMPILER_IS_GNUCC}" AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows" AND NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}" AND NOT "${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}") + # On MinGW with internal libraries, link the standard library statically + target_link_options(SRB2SDL2 PRIVATE "-static") +endif() + +set_property(TARGET SRB2SDL2 PROPERTY C_STANDARD 11) + # Core sources target_sourcefile(c) target_sources(SRB2SDL2 PRIVATE comptime.c md5.c config.h.in) @@ -11,110 +16,56 @@ set(SRB2_ASM_SOURCES vid_copy.s) set(SRB2_NASM_SOURCES tmap_mmx.nas tmap.nas) ### Configuration -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_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_HAVE_OPENMPT ON CACHE BOOL - "Enable OpenMPT support.") -set(SRB2_CONFIG_HAVE_CURL ON CACHE BOOL - "Enable curl support.") -set(SRB2_CONFIG_HAVE_THREADS ON CACHE BOOL - "Enable multithreading support.") -if(${CMAKE_SYSTEM} MATCHES Windows) - set(SRB2_CONFIG_HAVE_MIXERX ON CACHE BOOL - "Enable SDL Mixer X support.") -else() - set(SRB2_CONFIG_HAVE_MIXERX OFF) -endif() -set(SRB2_CONFIG_HWRENDER ON CACHE BOOL - "Enable hardware rendering through OpenGL.") set(SRB2_CONFIG_USEASM OFF CACHE BOOL "Enable NASM tmap implementation for software mode speedup.") set(SRB2_CONFIG_YASM OFF CACHE BOOL "Use YASM in place of NASM.") -set(SRB2_CONFIG_STATIC_OPENGL OFF CACHE BOOL - "Use statically linked OpenGL. NOT RECOMMENDED.") set(SRB2_CONFIG_DEV_BUILD OFF CACHE BOOL "Compile a development build of SRB2Kart.") -### 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, cURL).") -endif() - add_subdirectory(blua) -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) - target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_GME) - else() - message(WARNING "You have specified that GME is available but it was not found.") +# 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_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) - target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_OPENMPT) - else() - message(WARNING "You have specified that OpenMPT 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_MIXERX}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(MIXERX_FOUND ON) - set(MIXERX_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/SDLMixerX/i686-w64-mingw32/include/SDL2) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(MIXERX_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/SDLMixerX/x86_64-w64-mingw32/lib -lSDL2_mixer_ext") - else() # 32-bit - set(MIXERX_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/SDLMixerX/i686-w64-mingw32/lib -lSDL2_mixer_ext") - endif() - else() - # No support for non-Windows (yet?) - #find_package(MIXERX) - message(WARNING "SDL Mixer X is not supported as an external library.") - set(MIXERX_FOUND OFF) - endif() - if(${MIXERX_FOUND}) - set(SRB2_HAVE_MIXERX ON) - target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_MIXERX) - else() - message(WARNING "You have specified that SDL Mixer X is available but it was not found.") - endif() +target_link_libraries(SRB2SDL2 PRIVATE gme) +target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_GME) +if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}") + # this sucks but gme doesn't use modern cmake to delineate public headers + target_include_directories(SRB2SDL2 PRIVATE "${libgme_SOURCE_DIR}") 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_sources(SRB2SDL2 PRIVATE apng.c) + +target_link_libraries(SRB2SDL2 PRIVATE DiscordRPC::DiscordRPC) +target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_DISCORDRPC -DUSE_STUN) +target_sources(SRB2SDL2 PRIVATE discord.c stun.c) + +set(SRB2_HAVE_THREADS ON) +target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_THREADS) + if(${SRB2_CONFIG_HAVE_DISCORDRPC}) if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) set(DISCORDRPC_FOUND ON) @@ -182,49 +133,32 @@ if(${SRB2_CONFIG_HAVE_PNG} AND ${SRB2_CONFIG_HAVE_ZLIB}) 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") - endif() - else() - find_package(CURL) - endif() - if(${CURL_FOUND}) - set(SRB2_HAVE_CURL ON) - target_compile_definitions(SRB2SDL2 PRIVATE -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_HAVE_THREADS}) - set(SRB2_HAVE_THREADS ON) - target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_THREADS) -endif() - -if(${SRB2_CONFIG_HWRENDER}) +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() + endif() endif() -if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) - find_package(OpenGL) - if(${OPENGL_FOUND}) - target_compile_definitions(SRB2SDL2 PRIVATE -DHWRENDER) - target_compile_definitions(SRB2SDL2 PRIVATE -DSTATIC_OPENGL) - else() - message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.") - endif() +# 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}/../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() if(${SRB2_CONFIG_USEASM}) #SRB2_ASM_FLAGS can be used to pass flags to either nasm or yasm. - if(${CMAKE_SYSTEM} MATCHES "Linux") + if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") set(SRB2_ASM_FLAGS "-DLINUX ${SRB2_ASM_FLAGS}") endif() @@ -240,7 +174,7 @@ if(${SRB2_CONFIG_USEASM}) set(SRB2_USEASM ON) target_compile_definitions(SRB2SDL2 PRIVATE -DUSEASM) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3 -mfpmath=sse") + target_compile_options(SRB2SDL2 PRIVATE -msse3 -mfpmath=sse) target_sources(SRB2SDL2 PRIVATE ${SRB2_ASM_SOURCES} ${SRB2_NASM_SOURCES}) @@ -253,7 +187,7 @@ endif() # If using CCACHE, then force it. # https://github.com/Cockatrice/Cockatrice/pull/3052/files -if (${CMAKE_SYSTEM} MATCHES "Darwin") +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") @@ -275,35 +209,171 @@ 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) + 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) +# 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 + -Wno-trigraphs + -W # Was controlled by RELAXWARNINGS + -pedantic + -Wfloat-equal + -Wundef + -Wpointer-arith + -Wbad-function-cast + -Wcast-qual + -Wcast-align # Was controlled by NOCASTALIGNWARN + -Wwrite-strings + -Wsign-compare + -Wmissing-prototypes + -Wmissing-declarations + -Wmissing-noreturn + -Wnested-externs + -Winline + -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 + -Wno-absolute-value + -Wno-trigraphs + -Wno-error=non-literal-null-conversion + -Wno-error=constant-conversion + -Wno-error=unused-but-set-variable + > + + # C, MSVC + $<$,$>: + # All warnings at and before Visual Studio 2019 RTM + # https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warnings-by-compiler-version?view=msvc-170 + /Wv:19.20.27004.0 + > + + # C++, GNU, Clang and Apple Clang + $<$,$,$,$>>: + -Wall + > + + # C++, MSVC + $<$,$>: + /Wv:19.20.27004.0 + > +) +if(SRB2_CONFIG_ERRORMODE) + target_compile_options(SRB2SDL2 PRIVATE + $<$,$,$>: + -Werror + > + + $<$: + /WX + > + ) 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() - -set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-trigraphs) - target_compile_definitions(SRB2SDL2 PRIVATE -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} -#) +# Misc. build options from Makefiles +if(SRB2_CONFIG_DEBUGMODE) + target_compile_definitions(SRB2SDL2 PRIVATE -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() -## strip debug symbols into separate file when using gcc. -## to be consistent with Makefile, don't generate for OS X. -if((CMAKE_COMPILER_IS_GNUCC) AND NOT (${CMAKE_SYSTEM} MATCHES Darwin)) +add_subdirectory(sdl) +add_subdirectory(objects) + +# strip debug symbols into separate file when using gcc. +# to be consistent with Makefile, don't generate for OS X. +if((CMAKE_COMPILER_IS_GNUCC) 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") @@ -317,9 +387,26 @@ if((CMAKE_COMPILER_IS_GNUCC) AND NOT (${CMAKE_SYSTEM} MATCHES Darwin)) endif() endif() -add_subdirectory(sdl) -add_subdirectory(objects) +# 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) + # also copy implicitly linked system libraries + get_filename_component(MINGW_BIN_PATH ${CMAKE_CXX_COMPILER} PATH) + list(APPEND ADDITIONAL_DLLS + "libgcc_s_dw2-1.dll" + "libstdc++-6.dll" + "libwinpthread-1.dll" + ) + 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} -if(NOT ${SRB2_SDL2_AVAILABLE}) - message(FATAL_ERROR "There are no targets available to build an SRB2Kart executable. :(") + $ + COMMAND_EXPAND_LISTS + COMMENT "Copying runtime DLLs" + ) endif() diff --git a/src/config.h.in b/src/config.h.in index c27628ffd..d7b67cdce 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -11,15 +11,6 @@ #ifdef CMAKECONFIG -#define ASSET_HASH_MAIN_KART "${SRB2_ASSET_main.kart_HASH}" -#define ASSET_HASH_GFX_PK3 "${SRB2_ASSET_gfx.pk3_HASH}" -#define ASSET_HASH_TEXTURES_PK3 "${SRB2_ASSET_textures.pk3_HASH}" -#define ASSET_HASH_CHARS_PK3 "${SRB2_ASSET_chars.pk3_HASH}" -#define ASSET_HASH_MAPS_PK3 "${SRB2_ASSET_maps.pk3_HASH}" -#ifdef USE_PATCH_FILE -#define ASSET_HASH_PATCH_PK3 "${SRB2_ASSET_patch.pk3_HASH}" -#endif - #define SRB2_COMP_REVISION "${SRB2_COMP_REVISION}" #define SRB2_COMP_BRANCH "${SRB2_COMP_BRANCH}" // This is done with configure_file instead of defines in order to avoid @@ -29,9 +20,7 @@ #define COMPVERSION_UNCOMMITTED #endif -#define CMAKE_ASSETS_DIR "${CMAKE_SOURCE_DIR}/assets" - -#else +#endif /* Manually defined asset hashes for non-CMake builds * Last updated 2019 / 01 / 18 - Kart v1.0.2 - Main assets @@ -48,4 +37,3 @@ #endif #endif -#endif \ No newline at end of file diff --git a/src/discord.h b/src/discord.h index a6bb1134a..29a8ec596 100644 --- a/src/discord.h +++ b/src/discord.h @@ -15,7 +15,7 @@ #ifdef HAVE_DISCORDRPC -#include "discord_rpc.h" +#include extern consvar_t cv_discordrp; extern consvar_t cv_discordstreamer; diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt index 60921b587..dd8d304a4 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -1,303 +1,129 @@ # Declare SDL2 interface sources -if(NOT ${SRB2_CONFIG_HAVE_MIXERX}) - set(SRB2_CONFIG_SDL2_USEMIXER ON CACHE BOOL "Use SDL2_mixer or regular sdl sound") -else() - set(SRB2_CONFIG_SDL2_USEMIXER OFF) -endif() - -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) - target_sources(SRB2SDL2 PRIVATE mixer_sound.c) - else() - message(WARNING "You specified that SDL2_mixer is available, but it was not found. Falling back to sdl sound.") - target_sources(SRB2SDL2 PRIVATE sdl_sound.c) - endif() -elseif(${MIXERX_FOUND}) - target_sources(SRB2SDL2 PRIVATE mixer_sound.c) -else() - target_sources(SRB2SDL2 PRIVATE sdl_sound.c) -endif() +target_sources(SRB2SDL2 PRIVATE mixer_sound.c) target_sourcefile(c) target_sources(SRB2SDL2 PRIVATE ogl_sdl.c) -if(${SRB2_CONFIG_HAVE_THREADS}) - target_sources(SRB2SDL2 PRIVATE i_threads.c) +target_sources(SRB2SDL2 PRIVATE i_threads.c) + +if(${SRB2_USEASM}) + set_source_files_properties(${SRB2_ASM_SOURCES} PROPERTIES LANGUAGE C) + set_source_files_properties(${SRB2_ASM_SOURCES} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp") endif() -# 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() +if("${CMAKE_SYSTEM_NAME}" MATCHES Windows) + target_sources(SRB2SDL2 PRIVATE + ../win32/win_dbg.c + ../win32/Srb2win.rc) +endif() + +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() + +if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin) + find_library(CORE_FOUNDATION_LIBRARY "CoreFoundation") + target_link_libraries(SRB2SDL2 PRIVATE + ${CORE_FOUNDATION_LIBRARY} + ) + + #target_link_libraries(SRB2SDL2 PRIVATE SRB2Core) + 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 "Dr. Robotnik's Ring Racers" + MACOSX_BUNDLE_BUNDLE_VERSION ${SRB2_VERSION} + + RESOURCE "${CMAKE_CURRENT_SOURCE_DIR}/macosx/Srb2mac.icns" + ) +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() - find_package(SDL2) + target_link_libraries(SRB2SDL2 PRIVATE SDL2::SDL2 SDL2_mixer::SDL2_mixer) endif() -if(${SDL2_FOUND}) - if(${SRB2_USEASM}) - set_source_files_properties(${SRB2_ASM_SOURCES} PROPERTIES LANGUAGE C) - set_source_files_properties(${SRB2_ASM_SOURCES} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp") - endif() +if("${CMAKE_SYSTEM_NAME}" MATCHES Linux) + target_link_libraries(SRB2SDL2 PRIVATE m rt) +endif() - if(${CMAKE_SYSTEM} MATCHES Windows) - target_sources(SRB2SDL2 PRIVATE - ../win32/win_dbg.c - ../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") - target_sources(SRB2SDL2 PRIVATE - macosx/mac_alert.c - macosx/mac_alert.h - macosx/mac_resources.c - macosx/mac_resources.h - macosx/Srb2mac.icns - ) - endif() - - set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME ringracers) - - if(${CMAKE_SYSTEM} MATCHES Darwin) - find_library(CORE_LIB CoreFoundation) - target_link_libraries(SRB2SDL2 PRIVATE - ${CORE_LIB} - SDL2 - SDL2_mixer - ${GME_LIBRARIES} - ${OPENMPT_LIBRARIES} - ${MIXERX_LIBRARIES} - ${PNG_LIBRARIES} - ${ZLIB_LIBRARIES} - ${OPENGL_LIBRARIES} - ${CURL_LIBRARIES} - ${DISCORDRPC_LIBRARIES} - ) - 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() - 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} - ) + 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() - if(${CMAKE_SYSTEM} MATCHES Linux) - target_link_libraries(SRB2SDL2 PRIVATE - m - rt +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 -DDIRECTFULLSCREEN -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() - - 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) - - 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() - - set_target_properties(SRB2SDL2 PROPERTIES VERSION ${SRB2_VERSION}) - - 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} - ${MIXERX_INCLUDE_DIRS} - ${PNG_INCLUDE_DIRS} - ${ZLIB_INCLUDE_DIRS} - ${OPENGL_INCLUDE_DIRS} - ${CURL_INCLUDE_DIRS} - ${DISCORDRPC_INCLUDE_DIRS} - ) - - if((${SRB2_HAVE_MIXER}) OR (${SRB2_HAVE_MIXERX})) - target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_MIXER -DSOUND=SOUND_MIXER) - endif() - - target_compile_definitions(SRB2SDL2 PRIVATE - -DDIRECTFULLSCREEN -DHAVE_SDL - -DHAVE_THREADS - ) - - #### Installation #### - if(${CMAKE_SYSTEM} MATCHES Darwin) - install(TARGETS SRB2SDL2 - BUNDLE DESTINATION . - ) - 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() - - 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 - HINTS ${CMAKE_SOURCE_DIR}/libs/SDLMixerX/x86_64-w64-mingw32/bin - ) - 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 - HINTS ${CMAKE_SOURCE_DIR}/libs/SDLMixerX/i686-w64-mingw32/bin - ) - 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 - HINTS ${CMAKE_SOURCE_DIR}/libs/SDLMixerX/x86_64-w64-mingw32/bin - ) - 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 - HINTS ${CMAKE_SOURCE_DIR}/libs/SDLMixerX/i686-w64-mingw32/bin - ) - 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_MIXERX}) - getwinlib(SDL2_mixer_ext "SDL2_mixer_ext.dll") - getwinlib(libfluidsynth-2 "libfluidsynth-2.dll") - getwinlib(libgcc_s_sjlj-1 "libgcc_s_sjlj-1.dll") - getwinlib(libstdc++-6 "libstdc++-6.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() + +# 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) diff --git a/src/sdl/i_main.c b/src/sdl/i_main.c index de3ea3c9a..bc1200788 100644 --- a/src/sdl/i_main.c +++ b/src/sdl/i_main.c @@ -66,7 +66,7 @@ char logfilename[1024]; #endif #if defined (_WIN32) -#include "exchndl.h" +#include #endif #if defined (_WIN32) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index db4296f79..707d20427 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2273,18 +2273,6 @@ static const char *locateWad(void) } #endif - -#ifdef CMAKECONFIG -#ifndef NDEBUG - I_OutputMsg(","CMAKE_ASSETS_DIR); - strcpy(returnWadPath, CMAKE_ASSETS_DIR); - if (isWadPathOk(returnWadPath)) - { - return returnWadPath; - } -#endif -#endif - #ifdef __APPLE__ OSX_GetResourcesPath(returnWadPath); I_OutputMsg(",%s", returnWadPath); diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index d50bb49b5..5c4be227a 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -80,7 +80,7 @@ write netcode into the sound code, OKAY? #endif #ifdef HAVE_GME -#include "gme/gme.h" +#include #define GME_TREBLE 5.0f #define GME_BASS 1.0f #endif // HAVE_GME diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt new file mode 100644 index 000000000..41c26c4e0 --- /dev/null +++ b/thirdparty/CMakeLists.txt @@ -0,0 +1,518 @@ +macro(export) +endmacro() + +if(SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES) + set(SRB2_INTERNAL_LIBRARY_TYPE SHARED) + set(NOT_SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES OFF) +else() + set(SRB2_INTERNAL_LIBRARY_TYPE STATIC) + set(NOT_SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES ON) +endif() + + +if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}") + CPMAddPackage( + NAME SDL2 + VERSION 2.24.2 + URL "https://github.com/libsdl-org/SDL/archive/refs/tags/release-2.24.2.zip" + EXCLUDE_FROM_ALL ON + OPTIONS + "BUILD_SHARED_LIBS ${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}" + "SDL_SHARED ${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}" + "SDL_STATIC ${NOT_SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}" + "SDL_TEST OFF" + "SDL2_DISABLE_SDL2MAIN ON" + "SDL2_DISABLE_INSTALL ON" + ) +endif() + +if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}") + CPMAddPackage( + NAME SDL2_mixer + VERSION 2.6.2 + URL "https://github.com/libsdl-org/SDL_mixer/archive/refs/tags/release-2.6.2.zip" + EXCLUDE_FROM_ALL ON + OPTIONS + "BUILD_SHARED_LIBS ${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}" + "SDL2MIXER_INSTALL OFF" + "SDL2MIXER_DEPS_SHARED OFF" + "SDL2MIXER_SAMPLES OFF" + "SDL2MIXER_VENDORED ON" + "SDL2MIXER_FLAC ON" + "SDL2MIXER_FLAC_LIBFLAC OFF" + "SDL2MIXER_FLAC_DRFLAC ON" + "SDL2MIXER_MOD OFF" + "SDL2MIXER_MP3 ON" + "SDL2MIXER_MP3_DRMP3 ON" + "SDL2MIXER_MIDI ON" + "SDL2MIXER_OPUS OFF" + "SDL2MIXER_VORBIS STB" + "SDL2MIXER_WAVE ON" + ) +endif() + +if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}") + CPMAddPackage( + NAME ZLIB + VERSION 1.2.13 + URL "https://github.com/madler/zlib/archive/refs/tags/v1.2.13.zip" + EXCLUDE_FROM_ALL + OPTIONS + # The assembly optimizations are unmaintained and slated to be removed + "ASM686 Off" + "AMD64 Off" + "SKIP_INSTALL_ALL ON" + ) + file(MAKE_DIRECTORY "${zlib_BINARY_DIR}/include") + file(COPY "${zlib_SOURCE_DIR}/zlib.h" DESTINATION "${zlib_BINARY_DIR}/include") + file(COPY "${zlib_BINARY_DIR}/zconf.h" DESTINATION "${zlib_BINARY_DIR}/include") + # honestly this should probably be built like png is + set_target_properties(zlib PROPERTIES EXCLUDE_FROM_ALL ON) + set_target_properties(minigzip PROPERTIES EXCLUDE_FROM_ALL ON) + set_target_properties(example PROPERTIES EXCLUDE_FROM_ALL ON) + # zlib cmake also adds these 64 targets separately + if(HAVE_OFF64_T) + set_target_properties(minigzip64 PROPERTIES EXCLUDE_FROM_ALL ON) + set_target_properties(example64 PROPERTIES EXCLUDE_FROM_ALL ON) + endif() + target_include_directories(zlib INTERFACE "${zlib_BINARY_DIR}/include") + target_include_directories(zlibstatic INTERFACE "${zlib_BINARY_DIR}/include") + if(SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES) + add_library(ZLIB::ZLIB ALIAS zlib) + else() + add_library(ZLIB::ZLIB ALIAS zlibstatic) + endif() +endif() + +if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}") + CPMAddPackage( + NAME png + VERSION 1.6.38 + URL "https://github.com/glennrp/libpng/archive/refs/tags/v1.6.38.zip" + # png cmake build is broken on msys/mingw32 + DOWNLOAD_ONLY YES + ) + + if(png_ADDED) + # Since png's cmake build is broken, we're going to create a target manually + set( + PNG_SOURCES + + png.h + pngconf.h + + pngpriv.h + pngdebug.h + pnginfo.h + pngstruct.h + + png.c + pngerror.c + pngget.c + pngmem.c + pngpread.c + pngread.c + pngrio.c + pngrtran.c + pngrutil.c + pngset.c + pngtrans.c + pngwio.c + pngwrite.c + pngwtran.c + pngwutil.c + ) + list(TRANSFORM PNG_SOURCES PREPEND "${png_SOURCE_DIR}/") + + add_custom_command( + OUTPUT "${png_BINARY_DIR}/include/png.h" "${png_BINARY_DIR}/include/pngconf.h" + COMMAND ${CMAKE_COMMAND} -E copy "${png_SOURCE_DIR}/png.h" "${png_SOURCE_DIR}/pngconf.h" "${png_BINARY_DIR}/include" + DEPENDS "${png_SOURCE_DIR}/png.h" "${png_SOURCE_DIR}/pngconf.h" + VERBATIM + ) + add_custom_command( + OUTPUT "${png_BINARY_DIR}/include/pnglibconf.h" + COMMAND ${CMAKE_COMMAND} -E copy "${png_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt" "${png_BINARY_DIR}/include/pnglibconf.h" + DEPENDS "${png_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt" + VERBATIM + ) + list( + APPEND PNG_SOURCES + "${png_BINARY_DIR}/include/png.h" + "${png_BINARY_DIR}/include/pngconf.h" + "${png_BINARY_DIR}/include/pnglibconf.h" + ) + add_library(png "${SRB2_INTERNAL_LIBRARY_TYPE}" ${PNG_SOURCES}) + + # Disable ARM NEON since having it automatic breaks libpng external build on clang for some reason + target_compile_definitions(png PRIVATE -DPNG_ARM_NEON_OPT=0) + + # The png includes need to be available to consumers + target_include_directories(png PUBLIC "${png_BINARY_DIR}/include") + + # ... and these also need to be present only for png build + target_include_directories(png PRIVATE "${zlib_SOURCE_DIR}") + target_include_directories(png PRIVATE "${zlib_BINARY_DIR}") + target_include_directories(png PRIVATE "${png_BINARY_DIR}") + + target_link_libraries(png PRIVATE ZLIB::ZLIB) + add_library(PNG::PNG ALIAS png) + endif() +endif() + +if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}") + set( + internal_curl_options + + "BUILD_CURL_EXE OFF" + "BUILD_SHARED_LIBS ${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}" + "CURL_DISABLE_TESTS ON" + "HTTP_ONLY ON" + "CURL_DISABLE_CRYPTO_AUTH ON" + "CURL_DISABLE_NTLM ON" + "ENABLE_MANUAL OFF" + "ENABLE_THREADED_RESOLVER OFF" + "CURL_USE_LIBPSL OFF" + "CURL_USE_LIBSSH2 OFF" + "USE_LIBIDN2 OFF" + "CURL_ENABLE_EXPORT_TARGET OFF" + ) + if(${CMAKE_SYSTEM} MATCHES Windows) + list(APPEND internal_curl_options "CURL_USE_OPENSSL OFF") + list(APPEND internal_curl_options "CURL_USE_SCHANNEL ON") + endif() + if(${CMAKE_SYSTEM} MATCHES Darwin) + list(APPEND internal_curl_options "CURL_USE_OPENSSL OFF") + list(APPEND internal_curl_options "CURL_USE_SECTRANSP ON") + endif() + if(${CMAKE_SYSTEM} MATCHES Linux) + list(APPEND internal_curl_options "CURL_USE_OPENSSL ON") + endif() + + CPMAddPackage( + NAME curl + VERSION 7.86.0 + URL "https://github.com/curl/curl/archive/refs/tags/curl-7_86_0.zip" + EXCLUDE_FROM_ALL ON + OPTIONS ${internal_curl_options} + ) +endif() + +if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}") + CPMAddPackage( + NAME openmpt + VERSION 0.4.30 + URL "https://github.com/OpenMPT/openmpt/archive/refs/tags/libopenmpt-0.4.30.zip" + DOWNLOAD_ONLY ON + ) + + if(openmpt_ADDED) + set( + openmpt_SOURCES + + # minimp3 + # -DMPT_WITH_MINIMP3 + include/minimp3/minimp3.c + + common/mptStringParse.cpp + common/mptLibrary.cpp + common/Logging.cpp + common/Profiler.cpp + common/version.cpp + common/mptCPU.cpp + common/ComponentManager.cpp + common/mptOS.cpp + common/serialization_utils.cpp + common/mptStringFormat.cpp + common/FileReader.cpp + common/mptWine.cpp + common/mptPathString.cpp + common/mptAlloc.cpp + common/mptUUID.cpp + common/mptTime.cpp + common/mptString.cpp + common/mptFileIO.cpp + common/mptStringBuffer.cpp + common/mptRandom.cpp + common/mptIO.cpp + common/misc_util.cpp + + common/mptCRC.h + common/mptLibrary.h + common/mptIO.h + common/version.h + common/stdafx.h + common/ComponentManager.h + common/Endianness.h + common/mptStringFormat.h + common/mptMutex.h + common/mptUUID.h + common/mptExceptionText.h + common/BuildSettings.h + common/mptAlloc.h + common/mptTime.h + common/FileReaderFwd.h + common/Logging.h + common/mptException.h + common/mptWine.h + common/mptStringBuffer.h + common/misc_util.h + common/mptBaseMacros.h + common/mptMemory.h + common/mptFileIO.h + common/serialization_utils.h + common/mptSpan.h + common/mptThread.h + common/FlagSet.h + common/mptString.h + common/mptStringParse.h + common/mptBaseUtils.h + common/mptRandom.h + common/CompilerDetect.h + common/FileReader.h + common/mptAssert.h + common/mptPathString.h + common/Profiler.h + common/mptOS.h + common/mptBaseTypes.h + common/mptCPU.h + common/mptBufferIO.h + common/versionNumber.h + + soundlib/WAVTools.cpp + soundlib/ITTools.cpp + soundlib/AudioCriticalSection.cpp + soundlib/Load_stm.cpp + soundlib/MixerLoops.cpp + soundlib/Load_dbm.cpp + soundlib/ModChannel.cpp + soundlib/Load_gdm.cpp + soundlib/Snd_fx.cpp + soundlib/Load_mid.cpp + soundlib/mod_specifications.cpp + soundlib/Snd_flt.cpp + soundlib/Load_psm.cpp + soundlib/Load_far.cpp + soundlib/patternContainer.cpp + soundlib/Load_med.cpp + soundlib/Load_dmf.cpp + soundlib/Paula.cpp + soundlib/modcommand.cpp + soundlib/Message.cpp + soundlib/SoundFilePlayConfig.cpp + soundlib/Load_uax.cpp + soundlib/plugins/PlugInterface.cpp + soundlib/plugins/LFOPlugin.cpp + soundlib/plugins/PluginManager.cpp + soundlib/plugins/DigiBoosterEcho.cpp + soundlib/plugins/dmo/DMOPlugin.cpp + soundlib/plugins/dmo/Flanger.cpp + soundlib/plugins/dmo/Distortion.cpp + soundlib/plugins/dmo/ParamEq.cpp + soundlib/plugins/dmo/Gargle.cpp + soundlib/plugins/dmo/I3DL2Reverb.cpp + soundlib/plugins/dmo/Compressor.cpp + soundlib/plugins/dmo/WavesReverb.cpp + soundlib/plugins/dmo/Echo.cpp + soundlib/plugins/dmo/Chorus.cpp + soundlib/Load_ams.cpp + soundlib/tuningbase.cpp + soundlib/ContainerUMX.cpp + soundlib/Load_ptm.cpp + soundlib/ContainerXPK.cpp + soundlib/SampleFormatMP3.cpp + soundlib/tuning.cpp + soundlib/Sndfile.cpp + soundlib/ContainerMMCMP.cpp + soundlib/Load_amf.cpp + soundlib/Load_669.cpp + soundlib/modsmp_ctrl.cpp + soundlib/Load_mtm.cpp + soundlib/OggStream.cpp + soundlib/Load_plm.cpp + soundlib/Tables.cpp + soundlib/Load_c67.cpp + soundlib/Load_mod.cpp + soundlib/Load_sfx.cpp + soundlib/Sndmix.cpp + soundlib/load_j2b.cpp + soundlib/ModSequence.cpp + soundlib/SampleFormatFLAC.cpp + soundlib/ModInstrument.cpp + soundlib/Load_mo3.cpp + soundlib/ModSample.cpp + soundlib/Dlsbank.cpp + soundlib/Load_itp.cpp + soundlib/UpgradeModule.cpp + soundlib/MIDIMacros.cpp + soundlib/ContainerPP20.cpp + soundlib/RowVisitor.cpp + soundlib/Load_imf.cpp + soundlib/SampleFormatVorbis.cpp + soundlib/Load_dsm.cpp + soundlib/Load_mt2.cpp + soundlib/MixerSettings.cpp + soundlib/S3MTools.cpp + soundlib/Load_xm.cpp + soundlib/MIDIEvents.cpp + soundlib/pattern.cpp + soundlib/Load_digi.cpp + soundlib/Load_s3m.cpp + soundlib/tuningCollection.cpp + soundlib/SampleIO.cpp + soundlib/Dither.cpp + soundlib/Load_mdl.cpp + soundlib/OPL.cpp + soundlib/WindowedFIR.cpp + soundlib/SampleFormats.cpp + soundlib/Load_wav.cpp + soundlib/Load_it.cpp + soundlib/UMXTools.cpp + soundlib/Load_stp.cpp + soundlib/Load_okt.cpp + soundlib/Load_ult.cpp + soundlib/MixFuncTable.cpp + soundlib/SampleFormatOpus.cpp + soundlib/Fastmix.cpp + soundlib/Tagging.cpp + soundlib/ITCompression.cpp + soundlib/Load_dtm.cpp + soundlib/MPEGFrame.cpp + soundlib/XMTools.cpp + soundlib/SampleFormatMediaFoundation.cpp + soundlib/InstrumentExtensions.cpp + + soundlib/MixerInterface.h + soundlib/SoundFilePlayConfig.h + soundlib/ModSample.h + soundlib/MIDIEvents.h + soundlib/ModSampleCopy.h + soundlib/patternContainer.h + soundlib/ChunkReader.h + soundlib/ITCompression.h + soundlib/Dither.h + soundlib/S3MTools.h + soundlib/MPEGFrame.h + soundlib/WAVTools.h + soundlib/mod_specifications.h + soundlib/ITTools.h + soundlib/RowVisitor.h + soundlib/plugins/PluginMixBuffer.h + soundlib/plugins/PluginStructs.h + soundlib/plugins/LFOPlugin.h + soundlib/plugins/PlugInterface.h + soundlib/plugins/DigiBoosterEcho.h + soundlib/plugins/OpCodes.h + soundlib/plugins/dmo/Echo.h + soundlib/plugins/dmo/I3DL2Reverb.h + soundlib/plugins/dmo/WavesReverb.h + soundlib/plugins/dmo/ParamEq.h + soundlib/plugins/dmo/Gargle.h + soundlib/plugins/dmo/DMOPlugin.h + soundlib/plugins/dmo/Chorus.h + soundlib/plugins/dmo/Compressor.h + soundlib/plugins/dmo/Distortion.h + soundlib/plugins/dmo/Flanger.h + soundlib/plugins/PluginManager.h + soundlib/SampleIO.h + soundlib/Container.h + soundlib/ModSequence.h + soundlib/UMXTools.h + soundlib/Message.h + soundlib/modcommand.h + soundlib/XMTools.h + soundlib/Snd_defs.h + soundlib/MixFuncTable.h + soundlib/pattern.h + soundlib/modsmp_ctrl.h + soundlib/Tagging.h + soundlib/tuningcollection.h + soundlib/Mixer.h + soundlib/FloatMixer.h + soundlib/AudioCriticalSection.h + soundlib/Tables.h + soundlib/tuningbase.h + soundlib/WindowedFIR.h + soundlib/Sndfile.h + soundlib/Paula.h + soundlib/ModInstrument.h + soundlib/Dlsbank.h + soundlib/IntMixer.h + soundlib/OPL.h + soundlib/Resampler.h + soundlib/ModChannel.h + soundlib/MixerSettings.h + soundlib/AudioReadTarget.h + soundlib/MixerLoops.h + soundlib/tuning.h + soundlib/MIDIMacros.h + soundlib/OggStream.h + soundlib/Loaders.h + soundlib/BitReader.h + soundlib/opal.h + + sounddsp/AGC.cpp + sounddsp/EQ.cpp + sounddsp/DSP.cpp + sounddsp/Reverb.cpp + sounddsp/Reverb.h + sounddsp/EQ.h + sounddsp/DSP.h + sounddsp/AGC.h + + libopenmpt/libopenmpt_c.cpp + libopenmpt/libopenmpt_cxx.cpp + libopenmpt/libopenmpt_impl.cpp + libopenmpt/libopenmpt_ext_impl.cpp + ) + list(TRANSFORM openmpt_SOURCES PREPEND "${openmpt_SOURCE_DIR}/") + + # -DLIBOPENMPT_BUILD + configure_file("openmpt_svn_version.h" "svn_version.h") + add_library(openmpt "${SRB2_INTERNAL_LIBRARY_TYPE}" ${openmpt_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/svn_version.h) + if("${CMAKE_C_COMPILER_ID}" STREQUAL GNU OR "${CMAKE_C_COMPILER_ID}" STREQUAL Clang OR "${CMAKE_C_COMPILER_ID}" STREQUAL AppleClang) + target_compile_options(openmpt PRIVATE "-g0") + endif() + if("${CMAKE_SYSTEM_NAME}" STREQUAL Windows) + target_link_libraries(openmpt PRIVATE rpcrt4) + endif() + target_compile_features(openmpt PRIVATE cxx_std_11) + target_compile_definitions(openmpt PRIVATE -DLIBOPENMPT_BUILD) + + target_include_directories(openmpt PRIVATE "${openmpt_SOURCE_DIR}/common") + target_include_directories(openmpt PRIVATE "${openmpt_SOURCE_DIR}/src") + target_include_directories(openmpt PRIVATE "${openmpt_SOURCE_DIR}/include") + target_include_directories(openmpt PRIVATE "${openmpt_SOURCE_DIR}") + target_include_directories(openmpt PRIVATE "${CMAKE_CURRENT_BINARY_DIR}") + + # I wish this wasn't necessary, but it is + target_include_directories(openmpt PUBLIC "${openmpt_SOURCE_DIR}") + endif() +endif() + +if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}") + CPMAddPackage( + NAME libgme + VERSION 0.6.3 + URL "https://bitbucket.org/mpyne/game-music-emu/get/e76bdc0cb916e79aa540290e6edd0c445879d3ba.zip" + EXCLUDE_FROM_ALL ON + OPTIONS + "BUILD_SHARED_LIBS ${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}" + "ENABLE_UBSAN OFF" + ) + target_compile_features(gme PRIVATE cxx_std_11) + target_link_libraries(gme PRIVATE ZLIB::ZLIB) +endif() + +if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}") + CPMAddPackage( + NAME DiscordRPC + VERSION 3.4.0 + URL "https://github.com/discord/discord-rpc/archive/refs/tags/v3.4.0.zip" + EXCLUDE_FROM_ALL ON + OPTIONS + "BUILD_EXAMPLES OFF" + ) + target_include_directories(discord-rpc INTERFACE "${DiscordRPC_SOURCE_DIR}/include") + add_library(DiscordRPC::DiscordRPC ALIAS discord-rpc) +endif() diff --git a/thirdparty/openmpt_svn_version.h b/thirdparty/openmpt_svn_version.h new file mode 100644 index 000000000..a45ed9f22 --- /dev/null +++ b/thirdparty/openmpt_svn_version.h @@ -0,0 +1,10 @@ + +#pragma once +#define OPENMPT_VERSION_SVNVERSION "17963" +#define OPENMPT_VERSION_REVISION 17963 +#define OPENMPT_VERSION_DIRTY 0 +#define OPENMPT_VERSION_MIXEDREVISIONS 0 +#define OPENMPT_VERSION_URL "https://source.openmpt.org/svn/openmpt/tags/libopenmpt-0.4.32" +#define OPENMPT_VERSION_DATE "2022-09-25T14:19:05.052596Z" +#define OPENMPT_VERSION_IS_PACKAGE 1 +