Refactor CMake build system (#119)

* Remove 'SCRATCH' file

* cmake: move as much as variable assignments after project()

* Embed version in dethrace executable

* Allow installing DethRace + create binary archive

* Use ashutoshvarma/setup-ninja github action for getting ninja

* cmake: group user configurable options

* cmake: building in debug mode will add -g

* cmake: provide dethrace_werror interface target + DETHRACE_WERROR cmake option

* Update SDL2 to latest release

* Rename dethrace_werror target to compile_with_werror

* Also add -Werror to dethrace
This commit is contained in:
Anonymous Maarten 2022-09-05 04:22:59 +02:00 committed by GitHub
parent 8a2167920e
commit 519671f9e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 440 additions and 102 deletions

View File

@ -15,7 +15,7 @@ sudo apt-get update -qq > /dev/null
sudo apt-get install -qq -y libsdl2-dev > /dev/null
# build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON -B build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON -DDETHRACE_WERROR=ON -B build
cmake --build build -- -j 4
# package artifact

View File

@ -5,8 +5,8 @@ set -e
brew install SDL2
# build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON -B build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON -DDETHRACE_WERROR=ON -B build
cmake --build build -- -j 4
# package artifact
tar -czvf darwin-amd64.tar.gz build/dethrace
tar -czvf darwin-amd64.tar.gz build/dethrace

View File

@ -28,7 +28,7 @@ if test -z "$MSYSTEM"; then
$CXX --verbose
# build
cmake -DCMAKE_SYSTEM_NAME=Windows -DSDL2_ROOT_DIR=/tmp/SDL2-$SDL2_VERSION/$sdl_path -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON -B build -DCMAKE_EXE_LINKER_FLAGS_INIT=-lssp
cmake -DCMAKE_SYSTEM_NAME=Windows -DSDL2_ROOT_DIR=/tmp/SDL2-$SDL2_VERSION/$sdl_path -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON -DDETHRACE_WERROR=ON -B build -DCMAKE_EXE_LINKER_FLAGS_INIT=-lssp
cmake --build build -- -j 4
# package artifact

View File

@ -4,15 +4,11 @@ if ($($Env:MATRIX_PLATFORM) -eq "x86") {
$sdl_path = "x64"
}
$sdl2_version = "2.0.18"
$ninja_version = "1.10.2"
$sdl2_version = "2.24.0"
# install deps
Invoke-WebRequest -Uri https://www.libsdl.org/release/SDL2-devel-$sdl2_version-VC.zip -OutFile $Env:TEMP\SDL2-devel.zip
Invoke-WebRequest -Uri https://github.com/ninja-build/ninja/releases/download/v$ninja_version/ninja-win.zip -OutFile $Env:TEMP\ninja-win.zip
Expand-Archive $Env:TEMP\SDL2-devel.zip -DestinationPath $Env:TEMP
Expand-Archive $Env:TEMP\ninja-win.zip -DestinationPath $Env:TEMP\ninja
echo "$Env:TEMP\ninja" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
# build
cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON "-DSDL2_ROOT_DIR=$($Env:TEMP)\SDL2-$sdl2_version" -B build

View File

@ -14,6 +14,10 @@ jobs:
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup Ninja
uses: ashutoshvarma/setup-ninja@master
with:
version: 1.10.2
- name: Build
env:
CC: ${{ steps.vars.outputs.cc }}
@ -38,6 +42,10 @@ jobs:
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup Ninja
uses: ashutoshvarma/setup-ninja@master
with:
version: 1.10.2
- name: Build
run: |
.github/scripts/build-macos.sh
@ -62,6 +70,10 @@ jobs:
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup Ninja
uses: ashutoshvarma/setup-ninja@master
with:
version: 1.10.2
- uses: ilammy/msvc-dev-cmd@v1.4.1
with:
arch: ${{ matrix.platform }}

View File

@ -1,21 +1,33 @@
cmake_minimum_required(VERSION 3.10)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo" FORCE)
endif()
set(DETHRACE_IDE_ARGUMENTS "" CACHE STRING "DethRace arguments (only used by MSVC when debugging")
set(DETHRACE_IDE_ROOT_DIR "" CACHE PATH "DethRace rootdir (only used by MSVC when debugging)")
project(dethrace C)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
option(BUILD_TESTS "Build unit tests." OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")
include(GNUInstallDirs)
include(TestBigEndian)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION")
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" DETHRACE_VERSION)
string(STRIP "${DETHRACE_VERSION}" DETHRACE_VERSION)
else()
include(GetGitRevisionDescription)
git_describe(DETHRACE_VERSION)
endif()
message(STATUS "DethRace version ${DETHRACE_VERSION}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
set(DETHRACE_IDE_ARGUMENTS "" CACHE STRING "DethRace arguments (only used by MSVC when debugging")
set(DETHRACE_IDE_ROOT_DIR "" CACHE PATH "DethRace rootdir (only used by MSVC when debugging)")
option(BUILD_TESTS "Build unit tests." OFF)
option(DETHRACE_INSTALL "Add install target" OFF)
option(DETHRACE_WERROR "Treat warnings as errors")
test_big_endian(IS_BIGENDIAN)
find_package(SDL2 REQUIRED)
@ -24,6 +36,15 @@ add_subdirectory(lib/libsmacker)
add_subdirectory(lib/glad)
add_subdirectory(lib/miniaudio)
add_library(compile_with_werror INTERFACE)
if(DETHRACE_WERROR)
if(MSVC)
target_compile_options(compile_with_werror INTERFACE /WX)
else()
target_compile_options(compile_with_werror INTERFACE -Werror)
endif()
endif()
add_subdirectory(src/harness)
add_subdirectory(src/S3)
add_subdirectory(src/BRSRC13)
@ -33,3 +54,41 @@ if(BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()
if(DETHRACE_INSTALL)
install(FILES LICENSE
DESTINATION "${CMAKE_INSTALL_DOCDIR}"
)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^([xX]86|[xX]86_64|[iI].86|AMD64)$")
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(DETHRACE_ARCH x86)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(DETHRACE_ARCH amd64)
else()
message(SEND_ERROR "Unknown CMAKE_SIZEOF_VOID_P (${CMAKE_SIZEOF_VOID_P})")
endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(ARM|arm|ARM64|aarch64)$")
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(DETHRACE_ARCH arm)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(DETHRACE_ARCH aarch64)
else()
message(SEND_ERROR "Unknown CMAKE_SIZEOF_VOID_P (${CMAKE_SIZEOF_VOID_P})")
endif()
else()
message(SEND_ERROR "Unknown CMAKE_SYSTEM_PROCESSOR (${CMAKE_SYSTEM_PROCESSOR})")
endif()
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VERSION "${DETHRACE_VERSION}")
string(TOLOWER "${CMAKE_SYSTEM_NAME}-${DETHRACE_ARCH}" CPACK_SYSTEM_NAME)
set(CPACK_PACKAGE_DIRECTORY dist)
if(MSVC)
set(CPACK_GENERATOR ZIP)
else()
set(CPACK_GENERATOR TGZ)
endif()
include(CPack)
endif()

72
SCRATCH
View File

@ -1,72 +0,0 @@
// SCRATCH
// gRender_screen = DRPixelmapAllocateSub(gBack_screen, pX_offset, pY_offset, pWidth, pHeight);
render background(sky) to gRender_screen(back screen)
render 3d scene
render foreground to gBack_screen(cockpit, headups etc)
swap buffers
render background(sky) to gRender_screen(back screen)
- harness_renderscreen
render 3d scene
- clear back screen to black
- do opengl rendering
render foreground to gBack_screen(cockpit, headups etc)
- ignore any black pixels
swap buffers
0053A250
- 0x53A43C gKey_array
005505F4 dword_5505F4 //joy?
005507C0
- 005507e0 gJoy_array
005507E0
- 005508EC gKey_mapping
005505F4 offset in cyclepollkeys to gJoy_array
- diff is 115 ints
0x550428
/ DOS
00136444 gKey_array
001363A0 gJoy_array
0x1361D4 offset in cyclepollkeys to gJoy_array
- diff is 115 ints
[DEBUG] ShiftBoundGrooveFunks bound funk 0 : 0x0
[DEBUG] ShiftBoundGrooveFunks bound funk 1 : 0x1008c897c
[DEBUG] ShiftBoundGrooveFunks bound funk 2 : 0x1008c8a04
[DEBUG] ShiftBoundGrooveFunks bound funk 3 : 0x1008c8828
[DEBUG] ShiftBoundGrooveFunks bound funk 4 : 0x1008c88b0
[DEBUG] ShiftBoundGrooveFunks bound funk 5 : 0x1008c8938
[DEBUG] ShiftBoundGrooveFunks bound funk 6 : 0x1008c89c0
[DEBUG] ShiftBoundGrooveFunks bound funk 7 : 0x1008c886c
[DEBUG] ShiftBoundGrooveFunks bound funk 8 : 0x1008c88f4
[DEBUG] ShiftBoundGrooveFunks bound funk 9 : 0x1008c8a8c
[DEBUG] ShiftBoundGrooveFunks bound funk 10 : 0x1008c8b14
[DEBUG] ShiftBoundGrooveFunks bound funk 0 : 0x0
[DEBUG] ShiftBoundGrooveFunks bound funk 1 : 0x10389837c
[DEBUG] ShiftBoundGrooveFunks bound funk 2 : 0x103898404
[DEBUG] ShiftBoundGrooveFunks bound funk 3 : 0x103898228
[DEBUG] ShiftBoundGrooveFunks bound funk 4 : 0x1038982b0
[DEBUG] ShiftBoundGrooveFunks bound funk 5 : 0x103898338
[DEBUG] ShiftBoundGrooveFunks bound funk 6 : 0x1038983c0
[DEBUG] ShiftBoundGrooveFunks bound funk 7 : 0x10389826c
[DEBUG] ShiftBoundGrooveFunks bound funk 8 : 0x1038982f4
[DEBUG] ShiftBoundGrooveFunks bound funk 9 : 0x10389848c
[DEBUG] ShiftBoundGrooveFunks bound funk 10 : 0x103898514
sometimes selfcentre is called multiple times per frame
applyphysicstocars always is within time_step
acc_force is not dropping down fast enough
ts2 8.015344638012678e-11,
acc 5.92524658203125e2, revs 1.16219453125e4 v160 2.962623291015625e2, v118 1.703537831632129e-11, speed 0.0 max_force_rear 7.437321662902832, v135 1.481311645507812e2, limit 1 ts2 3.074372708797455e-1, acc 4.121511840820312e2, revs 7.6736416015625e3 v160 2.05921875e2, v118 3.127531499558245e-6, speed 0.0 max_force_rear 7.437321662902832, v135 1.029609375e2, limit 1 ts2 3.450555503368378e-1, acc 2.825576171875e2, revs 5.08019775390625e3 v160 1.411062774658203e2, v118 3.965127234550891e-6, speed 2.803576358087277 max_force_rear 8.247367858886719, v135 7.055313873291016e1, limit 1 ts2 3.663769066333771e-1, acc 1.920951385498047e2, revs 3.416863525390625e3 v160 9.58643798828125e1, v118 4.987010015611304e-6, speed 4.356438601662044 max_force_rear 8.737387657165527, v135 4.793218994140625e1, limit 1 ts2 3.764173984527588e-1, acc 1.30189453125e2, revs 2.38487939453125e3 v160 6.490651702880859e1, v118 3.554842805897351e-6, speed 5.955295815963242 max_force_rear 9.003288269042969, v135 3.24532585144043e1, limit 1 ts2 3.783531486988068e-1, acc 8.838812255859375e1, revs 1.777574462890625e3 v160 4.40048828125e1, v118 - 5.434078630059958e-4, speed 5.955295815963242 max_force_rear 9.125821113586426, v135 2.200244140625e1, limit 1 ts2 3.753950297832489e-1, acc 6.089559936523438e1, revs 1.454000854492188e3 v160 3.026010131835938e1, v118 - 1.982751418836415e-4, speed 9.13116980073459 max_force_rear 9.149258613586426, v135 1.513005065917969e1, limit 1 ts2 3.73871237039566e-1, acc 4.246442031860352e1, revs 1.315802001953125e3 v160 2.104527473449707e1, v118 1.181649276986718e-4, speed 9.13116980073459 max_force_rear 9.113421440124512, v135 1.052263736724854e1, limit 1 ts2 3.743874132633209e-1, acc 3.010890197753906e1, revs 1.3012431640625e3 v160 1.48672571182251e1, v118 - 4.263391747372225e-5, speed 1.228963766974154e1 max_force_rear 9.094904899597168, v135 7.433628559112549, limit 1 ts2 3.726563155651093e-1, acc 2.178503227233887e1, revs 1.369130737304688e3 v160 1.07061882019043e1, v118 - 1.312031417910475e-5, speed 1.228963766974154e1 max_force_rear 9.101181030273438, v135 5.353094100952148, limit 1 ts2 3.762767016887665e-1, acc 1.618281555175781e1, revs 1.492148193359375e3 v160 7.903269290924072, v118 - 1.101096768252319e-5, speed 1.548429768039707e1 max_force_rear 9.08011531829834, v135 3.951634645462036, limit 0

View File

@ -0,0 +1,284 @@
# - Returns a version string from Git
#
# These functions force a re-configure on each git commit so that you can
# trust the values of the variables in your build system.
#
# get_git_head_revision(<refspecvar> <hashvar> [ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR])
#
# Returns the refspec and sha hash of the current head revision
#
# git_describe(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe on the source tree, and adjusting
# the output so that it tests false if an error occurs.
#
# git_describe_working_tree(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe on the working tree (--dirty option),
# and adjusting the output so that it tests false if an error occurs.
#
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
#
# Returns the results of git describe --exact-match on the source tree,
# and adjusting the output so that it tests false if there was no exact
# matching tag.
#
# git_local_changes(<var>)
#
# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
# Uses the return code of "git diff-index --quiet HEAD --".
# Does not regard untracked files.
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2020 Ryan Pavlik <ryan.pavlik@gmail.com> <abiryan@ryand.net>
# http://academic.cleardefinition.com
#
# Copyright 2009-2013, Iowa State University.
# Copyright 2013-2020, Ryan Pavlik
# Copyright 2013-2020, Contributors
# SPDX-License-Identifier: BSL-1.0
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
if(__get_git_revision_description)
return()
endif()
set(__get_git_revision_description YES)
# We must run the following at "include" time, not at function call time,
# to find the path to this module rather than the path to a calling list file
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
# Function _git_find_closest_git_dir finds the next closest .git directory
# that is part of any directory in the path defined by _start_dir.
# The result is returned in the parent scope variable whose name is passed
# as variable _git_dir_var. If no .git directory can be found, the
# function returns an empty string via _git_dir_var.
#
# Example: Given a path C:/bla/foo/bar and assuming C:/bla/.git exists and
# neither foo nor bar contain a file/directory .git. This wil return
# C:/bla/.git
#
function(_git_find_closest_git_dir _start_dir _git_dir_var)
set(cur_dir "${_start_dir}")
set(git_dir "${_start_dir}/.git")
while(NOT EXISTS "${git_dir}")
# .git dir not found, search parent directories
set(git_previous_parent "${cur_dir}")
get_filename_component(cur_dir "${cur_dir}" DIRECTORY)
if(cur_dir STREQUAL git_previous_parent)
# We have reached the root directory, we are not in git
set(${_git_dir_var}
""
PARENT_SCOPE)
return()
endif()
set(git_dir "${cur_dir}/.git")
endwhile()
set(${_git_dir_var}
"${git_dir}"
PARENT_SCOPE)
endfunction()
function(get_git_head_revision _refspecvar _hashvar)
_git_find_closest_git_dir("${CMAKE_CURRENT_SOURCE_DIR}" GIT_DIR)
if("${ARGN}" STREQUAL "ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR")
set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR TRUE)
else()
set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR FALSE)
endif()
if(NOT "${GIT_DIR}" STREQUAL "")
file(RELATIVE_PATH _relative_to_source_dir "${CMAKE_SOURCE_DIR}"
"${GIT_DIR}")
if("${_relative_to_source_dir}" MATCHES "[.][.]" AND NOT ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR)
# We've gone above the CMake root dir.
set(GIT_DIR "")
endif()
endif()
if("${GIT_DIR}" STREQUAL "")
set(${_refspecvar}
"GITDIR-NOTFOUND"
PARENT_SCOPE)
set(${_hashvar}
"GITDIR-NOTFOUND"
PARENT_SCOPE)
return()
endif()
# Check if the current source dir is a git submodule or a worktree.
# In both cases .git is a file instead of a directory.
#
if(NOT IS_DIRECTORY ${GIT_DIR})
# The following git command will return a non empty string that
# points to the super project working tree if the current
# source dir is inside a git submodule.
# Otherwise the command will return an empty string.
#
execute_process(
COMMAND "${GIT_EXECUTABLE}" rev-parse
--show-superproject-working-tree
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE out
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT "${out}" STREQUAL "")
# If out is empty, GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a submodule
file(READ ${GIT_DIR} submodule)
string(REGEX REPLACE "gitdir: (.*)$" "\\1" GIT_DIR_RELATIVE
${submodule})
string(STRIP ${GIT_DIR_RELATIVE} GIT_DIR_RELATIVE)
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE}
ABSOLUTE)
set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD")
else()
# GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a worktree
file(READ ${GIT_DIR} worktree_ref)
# The .git directory contains a path to the worktree information directory
# inside the parent git repo of the worktree.
#
string(REGEX REPLACE "gitdir: (.*)$" "\\1" git_worktree_dir
${worktree_ref})
string(STRIP ${git_worktree_dir} git_worktree_dir)
_git_find_closest_git_dir("${git_worktree_dir}" GIT_DIR)
set(HEAD_SOURCE_FILE "${git_worktree_dir}/HEAD")
endif()
else()
set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD")
endif()
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
if(NOT EXISTS "${GIT_DATA}")
file(MAKE_DIRECTORY "${GIT_DATA}")
endif()
if(NOT EXISTS "${HEAD_SOURCE_FILE}")
return()
endif()
set(HEAD_FILE "${GIT_DATA}/HEAD")
configure_file("${HEAD_SOURCE_FILE}" "${HEAD_FILE}" COPYONLY)
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
"${GIT_DATA}/grabRef.cmake" @ONLY)
include("${GIT_DATA}/grabRef.cmake")
set(${_refspecvar}
"${HEAD_REF}"
PARENT_SCOPE)
set(${_hashvar}
"${HEAD_HASH}"
PARENT_SCOPE)
endfunction()
function(git_describe _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var}
"GIT-NOTFOUND"
PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var}
"HEAD-HASH-NOTFOUND"
PARENT_SCOPE)
return()
endif()
# TODO sanitize
#if((${ARGN}" MATCHES "&&") OR
# (ARGN MATCHES "||") OR
# (ARGN MATCHES "\\;"))
# message("Please report the following error to the project!")
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
#endif()
#message(STATUS "Arguments to execute_process: ${ARGN}")
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --tags --always ${hash} ${ARGN}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE res
OUTPUT_VARIABLE out
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()
set(${_var}
"${out}"
PARENT_SCOPE)
endfunction()
function(git_describe_working_tree _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
if(NOT GIT_FOUND)
set(${_var}
"GIT-NOTFOUND"
PARENT_SCOPE)
return()
endif()
execute_process(
COMMAND "${GIT_EXECUTABLE}" describe --dirty ${ARGN}
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE res
OUTPUT_VARIABLE out
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT res EQUAL 0)
set(out "${out}-${res}-NOTFOUND")
endif()
set(${_var}
"${out}"
PARENT_SCOPE)
endfunction()
function(git_get_exact_tag _var)
git_describe(out --exact-match ${ARGN})
set(${_var}
"${out}"
PARENT_SCOPE)
endfunction()
function(git_local_changes _var)
if(NOT GIT_FOUND)
find_package(Git QUIET)
endif()
get_git_head_revision(refspec hash)
if(NOT GIT_FOUND)
set(${_var}
"GIT-NOTFOUND"
PARENT_SCOPE)
return()
endif()
if(NOT hash)
set(${_var}
"HEAD-HASH-NOTFOUND"
PARENT_SCOPE)
return()
endif()
execute_process(
COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD --
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE res
OUTPUT_VARIABLE out
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(res EQUAL 0)
set(${_var}
"CLEAN"
PARENT_SCOPE)
else()
set(${_var}
"DIRTY"
PARENT_SCOPE)
endif()
endfunction()

View File

@ -0,0 +1,43 @@
#
# Internal file for GetGitRevisionDescription.cmake
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC
#
# Copyright 2009-2012, Iowa State University
# Copyright 2011-2015, Contributors
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
# SPDX-License-Identifier: BSL-1.0
set(HEAD_HASH)
file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
if(HEAD_CONTENTS MATCHES "ref")
# named branch
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
else()
configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
set(HEAD_HASH "${CMAKE_MATCH_1}")
endif()
endif()
else()
# detached HEAD
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
endif()
if(NOT HEAD_HASH)
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
string(STRIP "${HEAD_HASH}" HEAD_HASH)
endif()

View File

@ -10,13 +10,11 @@ target_include_directories(brender
include
)
target_link_libraries(brender PRIVATE harness)
target_link_libraries(brender PRIVATE harness compile_with_werror)
if(NOT MSVC)
target_compile_options(brender PRIVATE
-g
-Wall
-Werror
-Wno-return-type
-Wno-unused-variable
-Wno-unused-parameter

View File

@ -14,7 +14,6 @@ target_link_libraries(dethrace_obj PUBLIC SDL2::SDL2 smacker harness brender s3)
if (CMAKE_C_COMPILER_ID MATCHES "Clang")
target_compile_options(dethrace_obj PRIVATE
-g
-Wall
-Wno-return-type
-Wno-unused-variable
@ -24,7 +23,6 @@ if (CMAKE_C_COMPILER_ID MATCHES "Clang")
)
elseif (CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(dethrace_obj PRIVATE
-g
-Wall
-Wno-return-type
-Wno-unused-variable
@ -164,7 +162,7 @@ target_sources(dethrace_obj PRIVATE
# Create our main game binary.
add_executable(dethrace)
target_link_libraries(dethrace PRIVATE glad dethrace_obj)
target_link_libraries(dethrace PRIVATE glad dethrace_obj compile_with_werror)
target_sources(dethrace PRIVATE main.c)
if(NOT MSVC)
@ -198,3 +196,15 @@ if(DETHRACE_IDE_ARGUMENTS)
VS_DEBUGGER_COMMAND_ARGUMENTS "${DETHRACE_IDE_ARGUMENTS}"
)
endif()
if (DETHRACE_INSTALL)
install(TARGETS dethrace
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
if(MSVC)
INSTALL(FILES $<TARGET_PDB_FILE:dethrace>
DESTINATION "${CMAKE_INSTALL_BINDIR}"
OPTIONAL
)
endif()
endif()

View File

@ -7,13 +7,9 @@ target_include_directories(s3
${CMAKE_SOURCE_DIR}
)
target_link_libraries(s3 PRIVATE brender SDL2::SDL2 harness miniaudio)
target_link_libraries(s3 PRIVATE brender SDL2::SDL2 harness miniaudio compile_with_werror)
if(NOT MSVC)
target_compile_options(s3 PRIVATE
-g
-Werror
)
target_link_libraries(s3 PUBLIC pthread m)
else()
target_compile_definitions(s3 PRIVATE -D_CRT_SECURE_NO_WARNINGS)

View File

@ -1,3 +1,5 @@
configure_file(version.h.in version.h @ONLY)
add_library(harness STATIC)
if (NOT DEFINED IO_PLATFORM)
@ -9,11 +11,12 @@ target_include_directories(harness
.
${CMAKE_SOURCE_DIR}
${CMAKE_SOURCE_DIR}/src/DETHRACE
"${CMAKE_CURRENT_BINARY_DIR}"
PUBLIC
include
)
target_link_libraries(harness PRIVATE brender)
target_link_libraries(harness PRIVATE brender compile_with_werror)
if(WIN32)
target_link_libraries(harness PRIVATE dbghelp)
@ -23,7 +26,6 @@ if(NOT MSVC)
target_compile_options(harness PRIVATE
-Wall
-Wextra
-Werror
-Wno-unused-parameter
)
else()
@ -54,6 +56,7 @@ target_sources(harness PRIVATE
brender_emu/renderer_impl.h
sound/sound.c
sound/sound.h
"${CMAKE_CURRENT_BINARY_DIR}/version.h"
)
if (IO_PLATFORM STREQUAL "SDL_OpenGL")

View File

@ -5,6 +5,7 @@
#include "io_platforms/io_platform.h"
#include "renderers/null.h"
#include "sound/sound.h"
#include "version.h"
#include <errno.h>
#include <stdio.h>
@ -175,6 +176,8 @@ void Harness_DetectGameMode() {
void Harness_Init(int* argc, char* argv[]) {
int result;
LOG_INFO("DethRace version " DETHRACE_VERSION);
// disable the original CD check code
harness_game_config.disable_cd_check = 1;
// original physics time step. Lower values seem to work better at 30+ fps

6
src/harness/version.h.in Normal file
View File

@ -0,0 +1,6 @@
#ifndef HARNESS_VERSION_H
#define HARNESS_VERSION_H
#cmakedefine DETHRACE_VERSION "@DETHRACE_VERSION@"
#endif