diff --git a/.circleci/config.yml b/.circleci/config.yml index 67a3b66b7..b3b97363e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,9 +1,9 @@ version: 2 jobs: build: - working_directory: /root/SRB2 + working_directory: /home/circleci/SRB2 docker: - - image: debian:stretch + - image: cimg/base:current environment: CC: ccache gcc -m32 PKG_CONFIG_LIBDIR: /usr/lib/i386-linux-gnu/pkgconfig @@ -11,7 +11,7 @@ jobs: LIBGME_LDFLAGS: -lgme CCACHE_COMPRESS: true WFLAGS: -Wno-unsuffixed-float-constants - GCC49: true + GCC81: true #- image: ubuntu:trusty # environment: # CC: ccache gcc -m32 @@ -21,54 +21,69 @@ jobs: # CCACHE_COMPRESS: true # WFLAGS: -Wno-unsuffixed-float-constants # GCC48: true + resource_class: large steps: - run: name: Add i386 arch - command: dpkg --add-architecture i386 + command: sudo dpkg --add-architecture i386 - run: name: Add STJr PPA command: | - apt-get -qq update - apt-get -qq -y install dirmngr - apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0B1702D71499D9C25F986507F240F4449D3B0EC6 - echo "deb http://ppa.launchpad.net/stjr/srb2/ubuntu trusty main" >> /etc/apt/sources.list + sudo apt-get -qq update + sudo apt-get -qq -y install dirmngr + sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0B1702D71499D9C25F986507F240F4449D3B0EC6 + echo "deb http://ppa.launchpad.net/stjr/srb2/ubuntu trusty main" | sudo tee -a /etc/apt/sources.list + - run: + name: Make APT cache folder + command: mkdir -p /home/circleci/.cache/apt/archives/partial + - run: + name: Make APT cache usage by _apt + command: sudo chown -Rv _apt:root /home/circleci/.cache/apt/archives/partial - run: name: Update APT listing - command: apt-get -qq update + command: sudo apt-get -qq update - run: name: Support S3 upload - command: apt-get -qq -y install ca-certificates + command: sudo apt-get -qq -y install ca-certificates - restore_cache: keys: - v1-SRB2-APT - run: - name: Install SDK - command: apt-get -qq -y --no-install-recommends install git build-essential nasm libpng-dev:i386 libsdl2-mixer-dev:i386 libgme-dev:i386 libcurl4-openssl-dev:i386 libopenmpt-dev:i386 gettext ccache wget gcc-multilib upx openssh-client - + name: Uninstall amd64 SDK + command: sudo apt-get -o Dir::Cache="/home/circleci/.cache/apt" -qq -y --no-install-recommends remove libcurl4-openssl-dev:amd64 + - run: + name: Install i386 SDK + command: sudo apt-get -o Dir::Cache="/home/circleci/.cache/apt" -qq -y --no-install-recommends install git build-essential libpng-dev:i386 libsdl2-mixer-dev:i386 libgme-dev:i386 libcurl4-openssl-dev:i386 libopenmpt-dev:i386 gettext ccache wget gcc-multilib upx openssh-client + - run: + name: make md5sum + command: sudo find /home/circleci/.cache/apt/archives -type f -print0 | sort -z | sudo xargs -r0 md5sum > /home/circleci/.cache/apt_archives.md5 - save_cache: - key: v1-SRB2-APT + key: v1-SRB2-APT-{{ checksum "/home/circleci/.cache/apt_archives.md5" }} paths: - - /var/cache/apt/archives + - /home/circleci/.cache/apt - checkout - run: name: Compile without network support - command: make -C src LINUX=1 ERRORMODE=1 -k NONET=1 + command: make -C src LINUX=1 ERRORMODE=1 -k NONET=1 -j4 - run: name: wipe build command: make -C src LINUX=1 cleandep - run: name: rebuild depend command: make -C src LINUX=1 clean + - run: + name: make master depend file + command: find make/linux/SDL/deps/ -type f -print0 | sort -z | xargs -r0 cat > make/linux/SDL.deps - restore_cache: keys: - - v1-SRB2-{{ .Branch }}-{{ checksum "objs/Linux/SDL/Release/depend.dep" }} + - v1-SRB2-{{ .Branch }}-{{ checksum "make/linux/SDL.deps" }} - run: name: Compile - command: make -C src LINUX=1 ERRORMODE=1 -k + command: make -C src LINUX=1 ERRORMODE=1 -k -j4 - store_artifacts: - path: /root/SRB2/bin/Linux/Release/ + path: /home/circleci/SRB2/bin/ destination: bin - save_cache: - key: v1-SRB2-{{ .Branch }}-{{ checksum "objs/Linux/SDL/Release/depend.dep" }} + key: v1-SRB2-{{ .Branch }}-{{ checksum "make/linux/SDL.deps" }} paths: - - /root/.ccache + - /home/circleci/.ccache diff --git a/.gitattributes b/.gitattributes index 7751149ac..c2e507352 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,15 +1,17 @@ #Source code +/Makefile text=auto /src/*.c text=auto /src/*.h text=auto /src/*.s text=auto /src/*.m text=auto /src/*.xpm text=auto /src/Makefile text=auto +/tools/Makefile text=auto /src/Make*.cfg text=auto /src/CMakeLists.txt text=auto +*.mk -whitespace text=auto # Windows EOL *.cs -crlf -whitespace -*.mk -crlf -whitespace *.bat -crlf -whitespace *.dev -crlf -whitespace *.dsp -crlf -whitespace diff --git a/.gitignore b/.gitignore index 7023aaa80..268e36329 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,6 @@ Win32_LIB_ASM_Release /assets/debian /make /bin +/build +/build/* +/CMakeUserPresets.json \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 000000000..b292bfc06 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,434 @@ +variables: + GIT_STRATEGY: clone + GIT_CLONE_PATH: $CI_BUILDS_DIR/$CI_CONCURRENT_ID/$CI_PROJECT_PATH + +default: + image: debian:stable-slim + + cache: + - key: ccache-$CI_PROJECT_PATH_SLUG-$CI_JOB_NAME_SLUG + fallback_keys: + - cache-$CI_PROJECT_PATH_SLUG-$CI_DEFAULT_BRANCH + - cache-$CI_PROJECT_PATH_SLUG-default + paths: + - ccache + - ccache_statslog + + - key: apt-$CI_JOB_IMAGE + paths: + - apt-cache + unprotect: true + + before_script: + - - | + # debconf + echo -e "\e[0Ksection_start:`date +%s`:debconf[collapsed=true]\r\e[0KSetup debconf's environment" + - export DEBIAN_FRONTEND="noninteractive" + - export DEBIAN_PRIORITY="low" + - export DEBCONF_NONINTERACTIVE_SEEN="true" + - | + # debconf + echo -e "\e[0Ksection_end:`date +%s`:debconf\r\e[0K" + - - | + # dpkg_aa + echo -e "\e[0Ksection_start:`date +%s`:dpkg_aa[collapsed=true]\r\e[0KAdding architectures to dpkg" + - dpkg --add-architecture i386 + - dpkg --add-architecture amd64 + - dpkg --add-architecture arm64 + - | + # dpkg_aa + echo -e "\e[0Ksection_end:`date +%s`:dpkg_aa\r\e[0K" + - - | + # apt_conf + echo -e "\e[0Ksection_start:`date +%s`:apt_conf[collapsed=true]\r\e[0KSetting up APT conf" + - export APT_CACHE_DIR=`pwd`/apt-cache + - mkdir --parents --verbose $APT_CACHE_DIR/partial/ + - touch /etc/apt/apt.conf.d/99build + - | + # apt.conf + echo Adding options to apt.conf':' + - | + # APT::Install-Recommends + echo APT::Install-Recommends "false"\; | tee --append /etc/apt/apt.conf.d/99build + - | + # quit + echo quiet "1"\; | tee --append /etc/apt/apt.conf.d/99build + - | + # APT::Get::Assume-Yes + echo APT::Get::Assume-Yes "true"\; | tee --append /etc/apt/apt.conf.d/99build + - | + # Dir::Cache::Archives + echo Dir::Cache::Archives "$APT_CACHE_DIR"\; | tee --append /etc/apt/apt.conf.d/99build + - | + # apt_conf + echo -e "\e[0Ksection_end:`date +%s`:apt_conf\r\e[0K" + - - | + # apt_update + echo -e "\e[0Ksection_start:`date +%s`:apt_update[collapsed=true]\r\e[0KUpdating APT listing" + - apt-get update + - | + # apt_update + echo -e "\e[0Ksection_end:`date +%s`:apt_update\r\e[0K" + + - - | + # apt_pre + echo -e "\e[0Ksection_start:`date +%s`:apt_pre[collapsed=true]\r\e[0KInstalling pre packages" + - apt-get install apt-utils + - | + # apt_pre + echo -e "\e[0Ksection_end:`date +%s`:apt_pre\r\e[0K" + + - - | + # apt_upgrade + echo -e "\e[0Ksection_start:`date +%s`:apt_upgrade[collapsed=true]\r\e[0KUpdating existing packages" + - apt-get upgrade + - | + # apt_update + echo -e "\e[0Ksection_end:`date +%s`:apt_upgrade\r\e[0K" + + - - | + # apt_common + echo -e "\e[0Ksection_start:`date +%s`:apt_common[collapsed=true]\r\e[0KInstalling common packages" + - apt-get install make git ccache nasm + - | + # apt_common + echo -e "\e[0Ksection_end:`date +%s`:apt_common\r\e[0K" + + - - | + # ccache_config + echo -e "\e[0Ksection_start:`date +%s`:ccache_config[collapsed=true]\r\e[0KSetting up ccache config" + - mkdir --parents --verbose ~/.ccache/ + - touch ~/.ccache/ccache.conf + - | + # cache.conf + echo Adding ccache configution option + - | + # base_dir + echo base_dir = $PWD | tee --append ~/.ccache/ccache.conf + - | + # cache_dir + echo cache_dir = $PWD/ccache | tee --append ~/.ccache/ccache.conf + - | + # compiler_check + echo compiler_check = content | tee --append ~/.ccache/ccache.conf + - | + # stats_log + echo stats_log = $PWD/ccache_statslog | tee --append ~/.ccache/ccache.conf + - | + # max_size + echo max_size = 50M | tee --append ~/.ccache/ccache.conf + - | + # ccache_config + echo -e "\e[0Ksection_end:`date +%s`:ccache_config\r\e[0K" + + - - | + # cache_reset + echo -e "\e[0Ksection_start:`date +%s`:ccache_reset[collapsed=true]\r\e[0KResetting ccache statistics" + - ccache --zero-stats + - ccache --show-stats + - | + # ccache_reset + echo -e "\e[0Ksection_end:`date +%s`:ccache_reset\r\e[0K" + + artifacts: + paths: + - "bin/" + - "src/comptime.h" + name: "$CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA-$CI_JOB_NAME_SLUG" + + after_script: + - - | + # apt_clean + echo -e "\e[0Ksection_start:`date +%s`:apt_clean[collapsed=true]\r\e[0KCleaning of unneeded APT packages" + - apt-get autoclean + - | + # apt_clean + echo -e "\e[0Ksection_end:`date +%s`:apt_clean\r\e[0K" + + - - | + # ccache_stats + echo -e "\e[0Ksection_start:`date +%s`:ccache_stats[collapsed=true]\r\e[0Kccache statistics:" + - ccache --show-stats --verbose + - ccache --show-log-stats --verbose + - | + # ccahe_stats + echo -e "\e[0Ksection_end:`date +%s`:ccache_stats\r\e[0K" + +stages: + - build + +Debian testing GCC: + stage: build + image: debian:testing-slim + + allow_failure: true + + artifacts: + name: "$CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA-testing-gcc" + + variables: + CC: gcc + LDFLAGS: -Wl,-fuse-ld=gold + + script: + - - | + # apt_toolchain + echo -e "\e[0Ksection_start:`date +%s`:apt_toolchain[collapsed=true]\r\e[0KInstalling toolchain packages" + - apt-get install gcc + - | + # apt_toolchain + echo -e "\e[0Ksection_end:`date +%s`:apt_toolchain\r\e[0K" + + - - | + # apt_development + echo -e "\e[0Ksection_start:`date +%s`:apt_development[collapsed=true]\r\e[0KInstalling development packages" + - apt-get install libsdl2-mixer-dev libpng-dev libcurl4-openssl-dev libgme-dev libopenmpt-dev + - | + # apt_development + echo -e "\e[0Ksection_end:`date +%s`:apt_development\r\e[0K" + + - - | + # make + echo -e "\e[0Ksection_start:`date +%s`:make[collapsed=false]\r\e[0KCompiling SRB2" + - make --directory=src --keep-going CCACHE=1 ERRORMODE=1 NONX86=1 || make --directory=src --keep-going CCACHE=1 ERRORMODE=1 NONX86=1 + - | + # make + echo -e "\e[0Ksection_end:`date +%s`:make\r\e[0K" + +Windows x86: + stage: build + + artifacts: + paths: + - "bin/" + - "src/comptime.h" + expose_as: "Win32" + name: "$CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA-Win32" + + variables: + PREFIX: i686-w64-mingw32 + + script: + - - | + # apt_toolchain + echo -e "\e[0Ksection_start:`date +%s`:apt_toolchain[collapsed=true]\r\e[0KInstalling toolchain packages" + - apt-get install gcc-mingw-w64-i686-win32 + - | + # apt_toolchain + echo -e "\e[0Ksection_end:`date +%s`:apt_toolchain\r\e[0K" + + - - | + # make + echo -e "\e[0Ksection_start:`date +%s`:make[collapsed=false]\r\e[0KCompiling SRB2" + - make --directory=src --keep-going CCACHE=1 ERRORMODE=1 MINGW=1 SDL=1 || make --directory=src --keep-going CCACHE=1 ERRORMODE=1 MINGW=1 SDL=1 + - | + # make + echo -e "\e[0Ksection_end:`date +%s`:make\r\e[0K" + +Debian stable:amd64: + stage: build + + artifacts: + paths: + - "bin/" + - "src/comptime.h" + expose_as: "Debian amd64" + name: "$CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA-x86-64" + + variables: + CC: x86_64-linux-gnu-gcc + LDFLAGS: -Wl,-fuse-ld=gold + OBJCOPY: x86_64-linux-gnu-objcopy + OBJDUMP: x86_64-linux-gnu-objdump + PKG_CONFIG_PATH: /usr/lib/x86_64-linux-gnu/pkgconfig + + script: + - - | + # apt_toolchain + echo -e "\e[0Ksection_start:`date +%s`:apt_toolchain[collapsed=true]\r\e[0KInstalling toolchain packages" + - apt-get install gcc-x86-64-linux-gnu || apt-get install gcc + - | + # apt_toolchain + echo -e "\e[0Ksection_end:`date +%s`:apt_toolchain\r\e[0K" + + - - | + # apt_development + echo -e "\e[0Ksection_start:`date +%s`:apt_development[collapsed=true]\r\e[0KInstalling development packages" + - apt-get install libsdl2-mixer-dev:amd64 libpng-dev:amd64 libcurl4-openssl-dev:amd64 libgme-dev:amd64 libopenmpt-dev:amd64 + - | + # apt_development + echo -e "\e[0Ksection_end:`date +%s`:apt_development\r\e[0K" + + - - | + # make + echo -e "\e[0Ksection_start:`date +%s`:make[collapsed=false]\r\e[0KCompiling SRB2" + - make --directory=src --keep-going CCACHE=1 ERRORMODE=1 LINUX64=1 || make --directory=src --keep-going CCACHE=1 ERRORMODE=1 LINUX64=1 + - | + # make + echo -e "\e[0Ksection_end:`date +%s`:make\r\e[0K" + +Debian stable:i386: + stage: build + + artifacts: + paths: + - "bin/" + - "src/comptime.h" + expose_as: "Debian i386" + name: "$CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA-i686" + + variables: + CC: i686-linux-gnu-gcc + OBJCOPY: i686-linux-gnu-objcopy + OBJDUMP: i686-linux-gnu-objdump + PKG_CONFIG_PATH: /usr/lib/i386-linux-gnu/pkgconfig + + script: + - - | + # apt_toolchain + echo -e "\e[0Ksection_start:`date +%s`:apt_toolchain[collapsed=true]\r\e[0KInstalling toolchain packages" + - apt-get install gcc-i686-linux-gnu || apt-get install gcc + - | + # apt_toolchain + echo -e "\e[0Ksection_end:`date +%s`:apt_toolchain\r\e[0K" + + - - | + # apt_development + echo -e "\e[0Ksection_start:`date +%s`:apt_development[collapsed=true]\r\e[0KInstalling development packages" + - apt-get install libsdl2-mixer-dev:i386 libpng-dev:i386 libcurl4-openssl-dev:i386 libgme-dev:i386 libopenmpt-dev:i386 + - | + # apt_development + echo -e "\e[0Ksection_end:`date +%s`:apt_development\r\e[0K" + + - - | + # make + echo -e "\e[0Ksection_start:`date +%s`:make[collapsed=false]\r\e[0KCompiling SRB2" + - make --directory=src --keep-going CCACHE=1 ERRORMODE=1 LINUX=1 || make --directory=src --keep-going CCACHE=1 ERRORMODE=1 LINUX=1 + - | + # make + echo -e "\e[0Ksection_end:`date +%s`:make\r\e[0K" + +Debian stable:arm64: + stage: build + + artifacts: + paths: + - "bin/" + - "src/comptime.h" + expose_as: "Debian arm64" + name: "$CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA-aarch64" + + variables: + CC: aarch64-linux-gnu-gcc + LDFLAGS: -Wl,-fuse-ld=gold + OBJCOPY: aarch64-linux-gnu-objcopy + OBJDUMP: aarch64-linux-gnu-objdump + PKG_CONFIG_PATH: /usr/lib/aarch64-linux-gnu/pkgconfig + + script: + - - | + # apt_toolchain + echo -e "\e[0Ksection_start:`date +%s`:apt_toolchain[collapsed=true]\r\e[0KInstalling toolchain packages" + - apt-get install gcc-aarch64-linux-gnu || apt-get install gcc + - | + # apt_toolchain + echo -e "\e[0Ksection_end:`date +%s`:apt_toolchain\r\e[0K" + + - - | + # apt_development + echo -e "\e[0Ksection_start:`date +%s`:apt_development[collapsed=true]\r\e[0KInstalling development packages" + - apt-get install libsdl2-mixer-dev:arm64 libpng-dev:arm64 libcurl4-openssl-dev:arm64 libgme-dev:arm64 libopenmpt-dev:arm64 + - | + # apt_development + echo -e "\e[0Ksection_end:`date +%s`:apt_development\r\e[0K" + + - - | + # make + echo -e "\e[0Ksection_start:`date +%s`:make[collapsed=false]\r\e[0KCompiling SRB2" + - make --directory=src --keep-going CCACHE=1 ERRORMODE=1 LINUX64=1 ERRORMODE=1 NONX86=1 || make --directory=src --keep-going CCACHE=1 ERRORMODE=1 LINUX64=1 NONX86=1 + - | + # make + echo -e "\e[0Ksection_end:`date +%s`:make\r\e[0K" + +Windows x64: + stage: build + + artifacts: + paths: + - "bin/" + - "src/comptime.h" + expose_as: "Win64" + name: "$CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA-Win64" + + variables: + PREFIX: x86_64-w64-mingw32 + + script: + - - | + # apt_toolchain + echo -e "\e[0Ksection_start:`date +%s`:apt_toolchain[collapsed=true]\r\e[0KInstalling toolchain packages" + - apt-get install gcc-mingw-w64-x86-64-win32 + - | + # apt_toolchain + echo -e "\e[0Ksection_end:`date +%s`:apt_toolchain\r\e[0K" + + - - | + # make + echo -e "\e[0Ksection_start:`date +%s`:make[collapsed=false]\r\e[0KCompiling SRB2" + - make --directory=src --keep-going CCACHE=1 ERRORMODE=1 MINGW64=1 SDL=1 || make --directory=src --keep-going CCACHE=1 ERRORMODE=1 MINGW64=1 SDL=1 + - | + # make + echo -e "\e[0Ksection_end:`date +%s`:make\r\e[0K" + +Debian stable Clang: + stage: build + + allow_failure: true + + artifacts: + name: "$CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA-clang" + + variables: + CC: clang + WFLAGS: -Wno-cast-align + CFLAGS: -Wno-cast-align + LDFLAGS: -Wl,-fuse-ld=gold + + script: + - - | + # apt_toolchain + echo -e "\e[0Ksection_start:`date +%s`:apt_toolchain[collapsed=true]\r\e[0KInstalling toolchain packages" + - apt-get install clang + - | + # apt_toolchain + echo -e "\e[0Ksection_end:`date +%s`:apt_toolchain\r\e[0K" + + - - | + # apt_development + echo -e "\e[0Ksection_start:`date +%s`:apt_development[collapsed=true]\r\e[0KInstalling development packages" + - apt-get install libsdl2-mixer-dev libpng-dev libcurl4-openssl-dev libgme-dev libopenmpt-dev + - | + # apt_development + echo -e "\e[0Ksection_end:`date +%s`:apt_development\r\e[0K" + + - - | + # make + echo -e "\e[0Ksection_start:`date +%s`:make[collapsed=false]\r\e[0KCompiling SRB2" + - make --directory=src --keep-going CCACHE=1 ERRORMODE=1 NONX86=1 || make --directory=src --keep-going CCACHE=1 ERRORMODE=1 NONX86=1 + - | + # make + echo -e "\e[0Ksection_end:`date +%s`:make\r\e[0K" + +Debian testing Clang: + extends: Debian stable Clang + + image: debian:testing-slim + + artifacts: + name: "$CI_PROJECT_PATH_SLUG-$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA-testing-clang" + + variables: + CC: clang + WFLAGS: -Wno-cast-align -Wno-deprecated-non-prototype + CFLAGS: -Wno-cast-align -Wno-deprecated-non-prototype + LDFLAGS: -Wl,-fuse-ld=gold diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f901d3d7..80a3bdcd6 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,127 +17,18 @@ string(REGEX MATCH "[0-9]+\\.[0-9.]+" SRB2_VERSION ${SRB2_VERSION}) # Version change is fine. project(SRB2 VERSION ${SRB2_VERSION} - LANGUAGES C) - -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 srb2 CACHE STRING "Executable binary output name") - -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}") -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) + LANGUAGES C CXX) ##### PACKAGE CONFIGURATION ##### set(SRB2_CPACK_GENERATOR "" CACHE STRING "Generator to use for making a package. E.g., ZIP, TGZ, DragNDrop (OSX only). Leave blank for default generator.") if("${SRB2_CPACK_GENERATOR}" STREQUAL "") - if(${CMAKE_SYSTEM} 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() @@ -155,3 +44,166 @@ 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() + +# Clang tidy options will be ignored if CMAKE__CLANG_TIDY are set. +option(SRB2_CONFIG_ENABLE_CLANG_TIDY_C "Enable default clang-tidy check configuration for C" OFF) +option(SRB2_CONFIG_ENABLE_CLANG_TIDY_CXX "Enable default clang-tidy check configuration for C++" OFF) +option( + SRB2_CONFIG_SYSTEM_LIBRARIES + "Link dependencies using CMake's find_package and do not use internal builds" + ${SRB2_CONFIG_SYSTEM_LIBRARIES_DEFAULT} +) +option(SRB2_CONFIG_ENABLE_TESTS "Build the test suite" ON) +# 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.") + +if(SRB2_CONFIG_ENABLE_TESTS) + # https://github.com/catchorg/Catch2 + CPMAddPackage( + NAME Catch2 + VERSION 3.4.0 + GITHUB_REPOSITORY catchorg/Catch2 + OPTIONS + "CATCH_INSTALL_DOCS OFF" + ) + list(APPEND CMAKE_MODULE_PATH "${Catch2_SOURCE_DIR}/extras") + include(CTest) + include(Catch) + add_executable(srb2tests) + # To add tests, use target_sources to add individual test files to the target in subdirs. + target_link_libraries(srb2tests PRIVATE Catch2::Catch2 Catch2::Catch2WithMain) + target_compile_features(srb2tests PRIVATE c_std_11 cxx_std_17) + catch_discover_tests(srb2tests) +endif() + +# Enable CCache +# (Set USE_CCACHE=ON to use, CCACHE_OPTIONS for options) +if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL Windows) + option(USE_CCACHE "Enable ccache support" OFF) + + if(USE_CCACHE) + find_program(CCACHE_TOOL_PATH ccache) + if(CCACHE_TOOL_PATH) + set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_TOOL_PATH} CACHE STRING "" FORCE) + set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_TOOL_PATH} CACHE STRING "" FORCE) + else() + message(WARNING "USE_CCACHE was set but ccache is not found (set CCACHE_TOOL_PATH)") + endif() + endif() +else() + 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) + + # libgme defaults to "Nuked" YM2612 emulator, which is + # very SLOW. The system library probably uses the + # default so just always build it. + #find_package(GME 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() + +# 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 "" CACHE STRING "Override executable binary output name") +set(SRB2_SDL2_EXE_SUFFIX "" CACHE STRING "Optional executable suffix, separated by an underscore") + +include_directories(${CMAKE_CURRENT_BINARY_DIR}/src) + +add_subdirectory(src) +add_subdirectory(assets) + + +set(GIT_EXECUTABLE "git" CACHE FILEPATH "Path to git binary") +include(GitUtilities) + +if("${SRB2_SDL2_EXE_NAME}" STREQUAL "") + # cause a reconfigure if the branch changes + get_git_dir(SRB2_GIT_DIR) + configure_file("${SRB2_GIT_DIR}/HEAD" HEAD COPYONLY) + + git_current_branch(SRB2_GIT_REVISION) + + if("${SRB2_GIT_REVISION}" STREQUAL "") + # use abbreviated commit hash if on detached HEAD + git_latest_commit(SRB2_GIT_REVISION) + endif() + + if("${CMAKE_SYSTEM_NAME}" MATCHES "Windows") + list(APPEND EXE_NAME_PARTS "srb2win") + elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Linux") + list(APPEND EXE_NAME_PARTS "lsdlsrb2") + else() + list(APPEND EXE_NAME_PARTS "srb2") + endif() + + if(NOT "${SRB2_GIT_REVISION}" STREQUAL "master") + list(APPEND EXE_NAME_PARTS ${SRB2_GIT_REVISION}) + endif() +else() + list(APPEND EXE_NAME_PARTS ${SRB2_SDL2_EXE_NAME}) +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/CMakePresets.json b/CMakePresets.json new file mode 100644 index 000000000..7713bb385 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,29 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "default", + "description": "Build using default generator", + "binaryDir": "build", + "cacheVariables": { + "CMAKE_C_FLAGS": "-fdiagnostics-color", + "CMAKE_CXX_FLAGS": "-fdiagnostics-color", + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } + }, + { + "name": "debug", + "description": "Build for development (no optimizations)", + "inherits": "default", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + } + ], + "buildPresets": [ + { + "name": "default", + "configurePreset": "default" + } + ] +} diff --git a/README.md b/README.md index 49a3cc36d..56ff2d02d 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ [Sonic Robo Blast 2](https://srb2.org/) is a 3D Sonic the Hedgehog fangame based on a modified version of [Doom Legacy](http://doomlegacy.sourceforge.net/). ## Dependencies -- NASM (x86 builds only) - SDL2 (Linux/OS X only) - SDL2-Mixer (Linux/OS X only) - libupnp (Linux/OS X only) diff --git a/SRB2.cbp b/SRB2.cbp index 2a1eb87b8..9e887bf85 100644 --- a/SRB2.cbp +++ b/SRB2.cbp @@ -1992,24 +1992,6 @@ HW3SOUND for 3D hardware sound support