Merge branch 'cmake-overhaul' into 'master'

cmake: Rollup of srb2-side changes

See merge request KartKrew/Kart!758
This commit is contained in:
Sal 2022-11-29 04:42:58 +00:00
commit 50a1dcf979
20 changed files with 1133 additions and 651 deletions

1
.gitignore vendored
View file

@ -21,3 +21,4 @@ Win32_LIB_ASM_Release
/assets/debian /assets/debian
/make /make
/bin /bin
/build

View file

@ -1,17 +1,15 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
# Enable CCache early if("${CMAKE_CURRENT_BINARY_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
set(SRB2_USE_CCACHE OFF CACHE BOOL "Use CCache") message(FATAL_ERROR "In-source builds are blocked. Please build from a separate directory.")
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()
endif() 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) file(STRINGS src/version.h SRB2_VERSION)
string(REGEX MATCH "[0-9]+\\.[0-9.]+" SRB2_VERSION ${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. # Version change is fine.
project(SRB2 project(SRB2
VERSION ${SRB2_VERSION} VERSION ${SRB2_VERSION}
LANGUAGES C) LANGUAGES C CXX)
if(${PROJECT_SOURCE_DIR} MATCHES ${PROJECT_BINARY_DIR}) if(APPLE)
message(FATAL_ERROR "In-source builds will bring you a world of pain. Please make a separate directory to invoke CMake from.") # DiscordRPC needs but does not properly specify ObjC
endif() enable_language(OBJC)
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}
$<TARGET_FILE_DIR:${target}>/${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)
endif() endif()
##### PACKAGE CONFIGURATION ##### ##### 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.") 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("${SRB2_CPACK_GENERATOR}" STREQUAL "")
if(${CMAKE_SYSTEM} MATCHES "Windows") if("${CMAKE_SYSTEM_NAME}" MATCHES "Windows")
set(SRB2_CPACK_GENERATOR "ZIP") set(SRB2_CPACK_GENERATOR "ZIP")
elseif(${CMAKE_SYSTEM} MATCHES "Linux") elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
set(SRB2_CPACK_GENERATOR "TGZ") set(SRB2_CPACK_GENERATOR "TGZ")
elseif(${CMAKE_SYSTEM} MATCHES "Darwin") elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
set(SRB2_CPACK_GENERATOR "TGZ") set(SRB2_CPACK_GENERATOR "TGZ")
endif() endif()
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_PACKAGE_INSTALL_DIRECTORY "CMake ${CMAKE_VERSION_MAJOR}.${CMAKE_VERSION_MINOR}")
SET(CPACK_OUTPUT_FILE_PREFIX package) SET(CPACK_OUTPUT_FILE_PREFIX package)
include(CPack) 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})

View file

@ -1,75 +1,53 @@
## Assets Target Configuration ## ## Assets Target Configuration ##
# For prepending the current source path, later if(${CMAKE_SYSTEM} MATCHES Linux)
FUNCTION(PREPEND var prefix) # Asset installation isn't part of the Linux target
SET(listVar "") return()
FOREACH(f ${ARGN}) endif()
LIST(APPEND listVar "${prefix}/${f}")
ENDFOREACH(f)
SET(${var} "${listVar}" PARENT_SCOPE)
ENDFUNCTION(PREPEND)
set(SRB2_ASSET_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/installer" if("${SRB2_CONFIG_ASSET_DIRECTORY}" STREQUAL "")
CACHE STRING "Path to directory that contains all asset files for the installer.") message(WARNING "SRB2_CONFIG_ASSET_DIRECTORY is not set, so installation will not contain data files.")
return()
endif()
set(SRB2_ASSET_INSTALL ON get_filename_component(SRB2_ASSET_DIRECTORY_ABSOLUTE "${SRB2_CONFIG_ASSET_DIRECTORY}" ABSOLUTE)
CACHE BOOL "Insert asset files into the install directory or package.")
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! # POST-V2.2 NOTE: Do not forget to add patch.pk3 to the end of this list!
#################### ####################
set(SRB2_ASSET_HASHED set(SRB2_ASSETS_GAME
"main.kart;\ "main.kart"
gfx.pk3;\ "gfx.pk3"
textures.pk3;\ "textures.pk3"
chars.pk3;\ "chars.pk3"
maps.pk3;\ "maps.pk3"
patch.pk3" "followers.pk3"
CACHE STRING "Asset filenames to apply MD5 checks. No spaces between entries!" "patch.pk3"
) )
list(TRANSFORM SRB2_ASSETS_GAME PREPEND "/")
list(TRANSFORM SRB2_ASSETS_GAME PREPEND "${SRB2_ASSET_DIRECTORY_ABSOLUTE}")
set(SRB2_ASSET_DOCS set(SRB2_ASSETS ${SRB2_ASSET_DOCS} ${SRB2_ASSETS_GAME})
"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()
# Installation # Installation
if(${CMAKE_SYSTEM} MATCHES Darwin) if(${CMAKE_SYSTEM} MATCHES Darwin)
get_target_property(outname SRB2SDL2 OUTPUT_NAME) get_target_property(outname SRB2SDL2 OUTPUT_NAME)
if(${SRB2_ASSET_INSTALL}) install(FILES ${SRB2_ASSETS} DESTINATION "${outname}.app/Contents/Resources")
install(DIRECTORY "${SRB2_ASSET_DIRECTORY}/" install(DIRECTORY "${SRB2_ASSET_DIRECTORY_ABSOLUTE}/models" DESTINATION "${outname}.app/Contents/Resources")
DESTINATION "${outname}.app/Contents/Resources" install(FILES ${SRB2_ASSETS_DOCS} DESTINATION .)
)
endif()
# Always install the doc files, even in non-asset packages.
install(FILES ${SRB2_ASSET_DOCS}
DESTINATION .
OPTIONAL
)
else() else()
if(${SRB2_ASSET_INSTALL}) install(FILES ${SRB2_ASSETS} DESTINATION .)
install(DIRECTORY "${SRB2_ASSET_DIRECTORY}/" install(DIRECTORY "${SRB2_ASSET_DIRECTORY_ABSOLUTE}/models" DESTINATION .)
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()
endif() endif()

21
cmake/CPM.cmake Normal file
View file

@ -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})

View file

@ -21,3 +21,13 @@ find_library(DISCORDRPC_LIBRARY
set(DISCORDRPC_PROCESS_INCLUDES DISCORDRPC_INCLUDE_DIR) set(DISCORDRPC_PROCESS_INCLUDES DISCORDRPC_INCLUDE_DIR)
set(DISCORDRPC_PROCESS_LIBS DISCORDRPC_LIBRARY) set(DISCORDRPC_PROCESS_LIBS DISCORDRPC_LIBRARY)
libfind_process(DISCORDRPC) 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()

View file

@ -21,3 +21,13 @@ find_library(GME_LIBRARY
set(GME_PROCESS_INCLUDES GME_INCLUDE_DIR) set(GME_PROCESS_INCLUDES GME_INCLUDE_DIR)
set(GME_PROCESS_LIBS GME_LIBRARY) set(GME_PROCESS_LIBS GME_LIBRARY)
libfind_process(GME) 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()

View file

@ -21,3 +21,13 @@ find_library(OPENMPT_LIBRARY
set(OPENMPT_PROCESS_INCLUDES OPENMPT_INCLUDE_DIR) set(OPENMPT_PROCESS_INCLUDES OPENMPT_INCLUDE_DIR)
set(OPENMPT_PROCESS_LIBS OPENMPT_LIBRARY) set(OPENMPT_PROCESS_LIBS OPENMPT_LIBRARY)
libfind_process(OPENMPT) 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()

View file

@ -31,3 +31,13 @@ find_library(SDL2_LIBRARY
set(SDL2_PROCESS_INCLUDES SDL2_INCLUDE_DIR) set(SDL2_PROCESS_INCLUDES SDL2_INCLUDE_DIR)
set(SDL2_PROCESS_LIBS SDL2_LIBRARY) set(SDL2_PROCESS_LIBS SDL2_LIBRARY)
libfind_process(SDL2) 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()

View file

@ -32,3 +32,13 @@ find_library(SDL2_MIXER_LIBRARY
set(SDL2_MIXER_PROCESS_INCLUDES SDL2_MIXER_INCLUDE_DIR) set(SDL2_MIXER_PROCESS_INCLUDES SDL2_MIXER_INCLUDE_DIR)
set(SDL2_MIXER_PROCESS_LIBS SDL2_MIXER_LIBRARY) set(SDL2_MIXER_PROCESS_LIBS SDL2_MIXER_LIBRARY)
libfind_process(SDL2_MIXER) 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()

View file

@ -1,3 +0,0 @@
#!/bin/sh
export CCACHE_CPP2=true
exec "${RULE_LAUNCH_COMPILE}" "${CMAKE_C_COMPILER}" "$@"

View file

@ -1,3 +0,0 @@
#!/bin/sh
export CCACHE_CPP2=true
exec "${RULE_LAUNCH_COMPILE}" "${CMAKE_C_COMPILER}" "$@"

View file

@ -1,7 +1,12 @@
# SRB2 Core
add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32) 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 # Core sources
target_sourcefile(c) target_sourcefile(c)
target_sources(SRB2SDL2 PRIVATE comptime.c md5.c config.h.in) 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) set(SRB2_NASM_SOURCES tmap_mmx.nas tmap.nas)
### Configuration ### 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 set(SRB2_CONFIG_USEASM OFF CACHE BOOL
"Enable NASM tmap implementation for software mode speedup.") "Enable NASM tmap implementation for software mode speedup.")
set(SRB2_CONFIG_YASM OFF CACHE BOOL set(SRB2_CONFIG_YASM OFF CACHE BOOL
"Use YASM in place of NASM.") "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 set(SRB2_CONFIG_DEV_BUILD OFF CACHE BOOL
"Compile a development build of SRB2Kart.") "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) add_subdirectory(blua)
if(${SRB2_CONFIG_HAVE_GME}) # OS macros
if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) if (UNIX)
set(GME_FOUND ON) target_compile_definitions(SRB2SDL2 PRIVATE -DUNIXCOMMON)
set(GME_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/gme/include) 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) if(${SRB2_SYSTEM_BITS} EQUAL 64)
set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win64 -lgme") target_compile_definitions(SRB2SDL2 PRIVATE -DLINUX64)
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.")
endif() endif()
endif() endif()
if(${SRB2_CONFIG_HAVE_OPENMPT}) if("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) target_compile_definitions(SRB2SDL2 PRIVATE -DMACOSX)
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()
endif() endif()
if(${SRB2_CONFIG_HAVE_MIXERX}) target_link_libraries(SRB2SDL2 PRIVATE gme)
if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_GME)
set(MIXERX_FOUND ON) if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}")
set(MIXERX_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/SDLMixerX/i686-w64-mingw32/include/SDL2) # this sucks but gme doesn't use modern cmake to delineate public headers
if(${SRB2_SYSTEM_BITS} EQUAL 64) target_include_directories(SRB2SDL2 PRIVATE "${libgme_SOURCE_DIR}")
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()
endif() 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_HAVE_DISCORDRPC})
if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES})
set(DISCORDRPC_FOUND ON) set(DISCORDRPC_FOUND ON)
@ -182,49 +133,32 @@ if(${SRB2_CONFIG_HAVE_PNG} AND ${SRB2_CONFIG_HAVE_ZLIB})
endif() endif()
endif() endif()
if(${SRB2_CONFIG_HAVE_CURL}) if("${SRB2_CONFIG_HWRENDER}")
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})
target_compile_definitions(SRB2SDL2 PRIVATE -DHWRENDER) target_compile_definitions(SRB2SDL2 PRIVATE -DHWRENDER)
add_subdirectory(hardware) add_subdirectory(hardware)
endif()
if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) if("${SRB2_CONFIG_STATIC_OPENGL}")
find_package(OpenGL) find_package(OpenGL)
if(${OPENGL_FOUND}) if(${OPENGL_FOUND})
target_compile_definitions(SRB2SDL2 PRIVATE -DHWRENDER)
target_compile_definitions(SRB2SDL2 PRIVATE -DSTATIC_OPENGL) target_compile_definitions(SRB2SDL2 PRIVATE -DSTATIC_OPENGL)
else() else()
message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.") message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.")
endif() endif()
endif()
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() endif()
if(${SRB2_CONFIG_USEASM}) if(${SRB2_CONFIG_USEASM})
#SRB2_ASM_FLAGS can be used to pass flags to either nasm or yasm. #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}") set(SRB2_ASM_FLAGS "-DLINUX ${SRB2_ASM_FLAGS}")
endif() endif()
@ -240,7 +174,7 @@ if(${SRB2_CONFIG_USEASM})
set(SRB2_USEASM ON) set(SRB2_USEASM ON)
target_compile_definitions(SRB2SDL2 PRIVATE -DUSEASM) 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} target_sources(SRB2SDL2 PRIVATE ${SRB2_ASM_SOURCES}
${SRB2_NASM_SOURCES}) ${SRB2_NASM_SOURCES})
@ -253,7 +187,7 @@ endif()
# If using CCACHE, then force it. # If using CCACHE, then force it.
# https://github.com/Cockatrice/Cockatrice/pull/3052/files # 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) get_property(RULE_LAUNCH_COMPILE GLOBAL PROPERTY RULE_LAUNCH_COMPILE)
if(RULE_LAUNCH_COMPILE) if(RULE_LAUNCH_COMPILE)
MESSAGE(STATUS "Force enabling CCache usage under macOS") MESSAGE(STATUS "Force enabling CCache usage under macOS")
@ -275,35 +209,171 @@ endif()
# Compatibility flag with later versions of GCC # Compatibility flag with later versions of GCC
# We should really fix our code to not need this # We should really fix our code to not need this
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") 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() endif()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Compiler warnings configuration
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-absolute-value) target_compile_options(SRB2SDL2 PRIVATE
# Using generator expressions to handle per-language compile options
# C, GNU
# This is a direct translation from versions.mk
$<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:GNU>>:
-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
$<$<VERSION_LESS:$<C_COMPILER_VERSION>,2.9.5>:
-Wno-div-by-zero
-Wendif-labels
-Wdisabled-optimization
>
$<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,4.0.0>:
-Wold-style-definition
-Wmissing-field-initializers
>
$<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,4.1.0>:
-Wshadow
>
$<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,4.3.0>:
-funit-at-a-time
-Wlogical-op
>
$<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,4.5.0>:
-Wlogical-op
-Wno-error=array-bounds
>
$<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,4.6.0>:
-Wno-suggest-attribute=noreturn
-Wno-error=suggest-attribute=noreturn
>
$<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,5.4.0>:
-Wno-logical-op
-Wno-error=logical-op
>
$<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,6.1.0>:
-Wno-tautological-compare
-Wno-error=tautological-compare
>
$<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,7.1.0>:
-Wno-error=format-overflow=2
-Wimplicit-fallthrough=4
>
$<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,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
>
$<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,9.1.0>:
-Wno-error=address-of-packed-member
>
>
# C, Clang and Apple Clang
$<$<AND:$<COMPILE_LANGUAGE:C>,$<OR:$<C_COMPILER_ID:AppleClang>,$<C_COMPILER_ID: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
$<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID: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
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<OR:$<C_COMPILER_ID:GNU>,$<C_COMPILER_ID:AppleClang>,$<C_COMPILER_ID:Clang>>>:
-Wall
>
# C++, MSVC
$<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:MSVC>>:
/Wv:19.20.27004.0
>
)
if(SRB2_CONFIG_ERRORMODE)
target_compile_options(SRB2SDL2 PRIVATE
$<$<OR:$<C_COMPILER_ID:GNU>,$<C_COMPILER_ID:AppleClang>,$<C_COMPILER_ID:Clang>>:
-Werror
>
$<$<C_COMPILER_ID:MSVC>:
/WX
>
)
endif() endif()
# Link warnings configuration
target_link_options(SRB2SDL2 PRIVATE
$<$<C_COMPILER_ID:GNU>:
# -Wl,--as-needed - Was controlled by NOLDWARNING
>
)
if(${SRB2_CONFIG_DEV_BUILD}) if(${SRB2_CONFIG_DEV_BUILD})
target_compile_definitions(SRB2SDL2 PRIVATE -DDEVELOP) target_compile_definitions(SRB2SDL2 PRIVATE -DDEVELOP)
endif() endif()
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-trigraphs)
target_compile_definitions(SRB2SDL2 PRIVATE -DCMAKECONFIG) target_compile_definitions(SRB2SDL2 PRIVATE -DCMAKECONFIG)
#add_library(SRB2Core STATIC # Misc. build options from Makefiles
# ${SRB2_CORE_SOURCES} if(SRB2_CONFIG_DEBUGMODE)
# ${SRB2_CORE_HEADERS} target_compile_definitions(SRB2SDL2 PRIVATE -DZDEBUG -DPARANOIA -DRANGECHECK -DPACKETDROP)
# ${SRB2_CORE_RENDER_SOURCES} endif()
# ${SRB2_CORE_GAME_SOURCES} if(SRB2_CONFIG_MOBJCONSISTANCY)
# ${SRB2_LUA_SOURCES} target_compile_definitions(SRB2SDL2 PRIVATE -DMOBJCONSISTANCY)
# ${SRB2_LUA_HEADERS} endif()
# ${SRB2_BLUA_SOURCES} if(SRB2_CONFIG_PACKETDROP)
# ${SRB2_BLUA_HEADERS} 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. add_subdirectory(sdl)
## to be consistent with Makefile, don't generate for OS X. add_subdirectory(objects)
if((CMAKE_COMPILER_IS_GNUCC) AND NOT (${CMAKE_SYSTEM} MATCHES Darwin))
# 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) OR (${CMAKE_BUILD_TYPE} MATCHES RelWithDebInfo))
if(${CMAKE_BUILD_TYPE} MATCHES Debug) if(${CMAKE_BUILD_TYPE} MATCHES Debug)
set(OBJCOPY_ONLY_KEEP_DEBUG "--only-keep-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()
endif() endif()
add_subdirectory(sdl) # copy DLLs to bin/ directory if building internal shared on windows
add_subdirectory(objects) 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
$<TARGET_RUNTIME_DLLS:SRB2SDL2>
${ADDITIONAL_DLLS}
if(NOT ${SRB2_SDL2_AVAILABLE}) $<TARGET_FILE_DIR:SRB2SDL2>
message(FATAL_ERROR "There are no targets available to build an SRB2Kart executable. :(") COMMAND_EXPAND_LISTS
COMMENT "Copying runtime DLLs"
)
endif() endif()

View file

@ -11,15 +11,6 @@
#ifdef CMAKECONFIG #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_REVISION "${SRB2_COMP_REVISION}"
#define SRB2_COMP_BRANCH "${SRB2_COMP_BRANCH}" #define SRB2_COMP_BRANCH "${SRB2_COMP_BRANCH}"
// This is done with configure_file instead of defines in order to avoid // This is done with configure_file instead of defines in order to avoid
@ -29,9 +20,7 @@
#define COMPVERSION_UNCOMMITTED #define COMPVERSION_UNCOMMITTED
#endif #endif
#define CMAKE_ASSETS_DIR "${CMAKE_SOURCE_DIR}/assets" #endif
#else
/* Manually defined asset hashes for non-CMake builds /* Manually defined asset hashes for non-CMake builds
* Last updated 2019 / 01 / 18 - Kart v1.0.2 - Main assets * Last updated 2019 / 01 / 18 - Kart v1.0.2 - Main assets
@ -48,4 +37,3 @@
#endif #endif
#endif #endif
#endif

View file

@ -15,7 +15,7 @@
#ifdef HAVE_DISCORDRPC #ifdef HAVE_DISCORDRPC
#include "discord_rpc.h" #include <discord_rpc.h>
extern consvar_t cv_discordrp; extern consvar_t cv_discordrp;
extern consvar_t cv_discordstreamer; extern consvar_t cv_discordstreamer;

View file

@ -1,72 +1,25 @@
# Declare SDL2 interface sources # Declare SDL2 interface sources
if(NOT ${SRB2_CONFIG_HAVE_MIXERX}) target_sources(SRB2SDL2 PRIVATE mixer_sound.c)
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_sourcefile(c) target_sourcefile(c)
target_sources(SRB2SDL2 PRIVATE ogl_sdl.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)
endif()
# Dependency if(${SRB2_USEASM})
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)
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 LANGUAGE C)
set_source_files_properties(${SRB2_ASM_SOURCES} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp") set_source_files_properties(${SRB2_ASM_SOURCES} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
endif() endif()
if(${CMAKE_SYSTEM} MATCHES Windows) if("${CMAKE_SYSTEM_NAME}" MATCHES Windows)
target_sources(SRB2SDL2 PRIVATE target_sources(SRB2SDL2 PRIVATE
../win32/win_dbg.c ../win32/win_dbg.c
../win32/Srb2win.rc) ../win32/Srb2win.rc)
endif() endif()
if(${CMAKE_SYSTEM} MATCHES Darwin) if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin)
set(MACOSX_BUNDLE_ICON_FILE Srb2mac.icns) set(MACOSX_BUNDLE_ICON_FILE Srb2mac.icns)
set_source_files_properties(macosx/Srb2mac.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") set_source_files_properties(macosx/Srb2mac.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
target_sources(SRB2SDL2 PRIVATE target_sources(SRB2SDL2 PRIVATE
@ -76,59 +29,39 @@ if(${SDL2_FOUND})
macosx/mac_resources.h macosx/mac_resources.h
macosx/Srb2mac.icns macosx/Srb2mac.icns
) )
endif() endif()
set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME ringracers) if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin)
find_library(CORE_FOUNDATION_LIBRARY "CoreFoundation")
if(${CMAKE_SYSTEM} MATCHES Darwin)
find_library(CORE_LIB CoreFoundation)
target_link_libraries(SRB2SDL2 PRIVATE target_link_libraries(SRB2SDL2 PRIVATE
${CORE_LIB} ${CORE_FOUNDATION_LIBRARY}
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}")
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}
)
if(${CMAKE_SYSTEM} MATCHES Linux)
target_link_libraries(SRB2SDL2 PRIVATE
m
rt
)
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) #target_link_libraries(SRB2SDL2 PRIVATE SRB2Core)
set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME "${CPACK_PACKAGE_DESCRIPTION_SUMMARY}")
if(${SRB2_USEASM}) # 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()
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(${SRB2_USEASM})
if(${SRB2_CONFIG_YASM}) if(${SRB2_CONFIG_YASM})
set(ASM_ASSEMBLER_TEMP ${CMAKE_ASM_YASM_COMPILER}) set(ASM_ASSEMBLER_TEMP ${CMAKE_ASM_YASM_COMPILER})
set(ASM_ASSEMBLER_OBJFORMAT ${CMAKE_ASM_YASM_OBJECT_FORMAT}) set(ASM_ASSEMBLER_OBJFORMAT ${CMAKE_ASM_YASM_OBJECT_FORMAT})
@ -138,47 +71,27 @@ if(${SDL2_FOUND})
set(ASM_ASSEMBLER_OBJFORMAT ${CMAKE_ASM_NASM_OBJECT_FORMAT}) set(ASM_ASSEMBLER_OBJFORMAT ${CMAKE_ASM_NASM_OBJECT_FORMAT})
set_source_files_properties(${SRB2_NASM_SOURCES} LANGUAGE ASM_NASM) set_source_files_properties(${SRB2_NASM_SOURCES} LANGUAGE ASM_NASM)
endif() endif()
endif() endif()
set_target_properties(SRB2SDL2 PROPERTIES VERSION ${SRB2_VERSION}) if("${CMAKE_SYSTEM_NAME}" MATCHES Windows)
if(${CMAKE_SYSTEM} MATCHES Windows)
target_link_libraries(SRB2SDL2 PRIVATE target_link_libraries(SRB2SDL2 PRIVATE
ws2_32 ws2_32
) )
target_compile_options(SRB2SDL2 PRIVATE target_compile_options(SRB2SDL2 PRIVATE
-U_WINDOWS -U_WINDOWS
) )
endif() endif()
target_include_directories(SRB2SDL2 PRIVATE target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_MIXER -DSOUND=SOUND_MIXER)
${SDL2_INCLUDE_DIRS} target_compile_definitions(SRB2SDL2 PRIVATE -DDIRECTFULLSCREEN -DHAVE_SDL)
${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})) #### Installation ####
target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_MIXER -DSOUND=SOUND_MIXER) if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin)
endif()
target_compile_definitions(SRB2SDL2 PRIVATE
-DDIRECTFULLSCREEN -DHAVE_SDL
-DHAVE_THREADS
)
#### Installation ####
if(${CMAKE_SYSTEM} MATCHES Darwin)
install(TARGETS SRB2SDL2 install(TARGETS SRB2SDL2
BUNDLE DESTINATION . BUNDLE DESTINATION .
) )
else() set_property(TARGET SRB2SDL2 PROPERTY INSTALL_RPATH_USE_LINK_PATH ON)
else()
install(TARGETS SRB2SDL2 SRB2SDL2 install(TARGETS SRB2SDL2 SRB2SDL2
RUNTIME DESTINATION . RUNTIME DESTINATION .
) )
@ -191,102 +104,19 @@ if(${SDL2_FOUND})
) )
endif() endif()
endif() endif()
endif() endif()
if(${CMAKE_SYSTEM} MATCHES Windows) # Mac bundle fixup
set(win_extra_dll_list "") # HACK: THIS IS IMPORTANT! See the escaped \${CMAKE_INSTALL_PREFIX}? This
macro(getwinlib dllname defaultname) # makes it so that var is evaluated LATER during cpack, not right now!
if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) # This fixes the quirk where the bundled libraries don't land in the final package
if (${CMAKE_GENERATOR} STREQUAL "MinGW Makefiles") # https://cmake.org/pipermail/cmake/2011-March/043532.html
if(${SRB2_SYSTEM_BITS} EQUAL 64) #
find_library(SRB2_SDL2_DLL_${dllname} "${defaultname}" # HOWEVER: ${CPACK_PACKAGE_DESCRIPTION_SUMMARY} is NOT escaped, because that var
HINTS ${CMAKE_SOURCE_DIR}/libs/dll-binaries/x86_64 # is only available to us at this step. Read the link: ${CMAKE_INSTALL_PREFIX} at
HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2/x86_64-w64-mingw32/bin # this current step points to the CMAKE build folder, NOT the folder that CPACK uses.
HINTS ${CMAKE_SOURCE_DIR}/libs/SDL2_mixer/x86_64-w64-mingw32/bin # Therefore, it makes sense to escape that var, but not the other.
HINTS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/bin/x86_64/mingw if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin)
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 " install(CODE "
include(BundleUtilities) include(BundleUtilities)
fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${CPACK_PACKAGE_DESCRIPTION_SUMMARY}.app\" fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/${CPACK_PACKAGE_DESCRIPTION_SUMMARY}.app\"
@ -294,10 +124,6 @@ if(${SDL2_FOUND})
/Library/Frameworks /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() endif()
set(SRB2_SDL2_AVAILABLE YES PARENT_SCOPE)

View file

@ -66,7 +66,7 @@ char logfilename[1024];
#endif #endif
#if defined (_WIN32) #if defined (_WIN32)
#include "exchndl.h" #include <exchndl.h>
#endif #endif
#if defined (_WIN32) #if defined (_WIN32)

View file

@ -2273,18 +2273,6 @@ static const char *locateWad(void)
} }
#endif #endif
#ifdef CMAKECONFIG
#ifndef NDEBUG
I_OutputMsg(","CMAKE_ASSETS_DIR);
strcpy(returnWadPath, CMAKE_ASSETS_DIR);
if (isWadPathOk(returnWadPath))
{
return returnWadPath;
}
#endif
#endif
#ifdef __APPLE__ #ifdef __APPLE__
OSX_GetResourcesPath(returnWadPath); OSX_GetResourcesPath(returnWadPath);
I_OutputMsg(",%s", returnWadPath); I_OutputMsg(",%s", returnWadPath);

View file

@ -80,7 +80,7 @@ write netcode into the sound code, OKAY?
#endif #endif
#ifdef HAVE_GME #ifdef HAVE_GME
#include "gme/gme.h" #include <gme/gme.h>
#define GME_TREBLE 5.0f #define GME_TREBLE 5.0f
#define GME_BASS 1.0f #define GME_BASS 1.0f
#endif // HAVE_GME #endif // HAVE_GME

518
thirdparty/CMakeLists.txt vendored Normal file
View file

@ -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()

10
thirdparty/openmpt_svn_version.h vendored Normal file
View file

@ -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