mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-12-24 08:52:33 +00:00
Merge branch 'enable-cxx' into 'master'
Enable C++17 additionally with Catch2 unit testing See merge request KartKrew/Kart!807
This commit is contained in:
commit
aa29ac5ada
7 changed files with 101 additions and 36 deletions
|
|
@ -63,6 +63,7 @@ option(
|
|||
"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
|
||||
|
|
@ -81,6 +82,25 @@ option(SRB2_CONFIG_ZDEBUG "Compile with ZDEBUG defined." OFF)
|
|||
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.1.1
|
||||
GITHUB_REPOSITORY catchorg/Catch2
|
||||
OPTIONS
|
||||
"CATCH_INSTALL_DOCS OFF"
|
||||
)
|
||||
list(APPEND CMAKE_MODULE_PATH "${Catch2_SOURCE_DIR}/extras")
|
||||
include(CTest)
|
||||
include(Catch)
|
||||
add_executable(srb2tests)
|
||||
# To add tests, use target_sources to add individual test files to the target in subdirs.
|
||||
target_link_libraries(srb2tests PRIVATE Catch2::Catch2 Catch2::Catch2WithMain)
|
||||
target_compile_features(srb2tests PRIVATE c_std_11 cxx_std_17)
|
||||
catch_discover_tests(srb2tests)
|
||||
endif()
|
||||
|
||||
# Enable CCache
|
||||
# (Set USE_CCACHE=ON to use, CCACHE_OPTIONS for options)
|
||||
if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL Windows)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ if("${CMAKE_COMPILER_IS_GNUCC}" AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows" AND
|
|||
target_link_options(SRB2SDL2 PRIVATE "-static")
|
||||
endif()
|
||||
|
||||
set_property(TARGET SRB2SDL2 PROPERTY C_STANDARD 11)
|
||||
target_compile_features(SRB2SDL2 PRIVATE c_std_11 cxx_std_17)
|
||||
|
||||
# Core sources
|
||||
target_sourcefile(c)
|
||||
|
|
@ -370,6 +370,7 @@ endif()
|
|||
|
||||
add_subdirectory(sdl)
|
||||
add_subdirectory(objects)
|
||||
add_subdirectory(tests)
|
||||
|
||||
# strip debug symbols into separate file when using gcc.
|
||||
# to be consistent with Makefile, don't generate for OS X.
|
||||
|
|
|
|||
37
src/cxxutil.hpp
Normal file
37
src/cxxutil.hpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef __SRB2_CXXUTIL_HPP__
|
||||
#define __SRB2_CXXUTIL_HPP__
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
namespace srb2 {
|
||||
|
||||
template <class F>
|
||||
class Finally {
|
||||
public:
|
||||
explicit Finally(const F& f) noexcept : f_(f) {}
|
||||
explicit Finally(F&& f) noexcept : f_(f) {}
|
||||
|
||||
Finally(Finally&& from) noexcept : f_(std::move(from.f_)), call_(std::exchange(from.call_, false)) {}
|
||||
|
||||
Finally(const Finally& from) = delete;
|
||||
void operator=(const Finally& from) = delete;
|
||||
void operator=(Finally&& from) = delete;
|
||||
|
||||
~Finally() noexcept {
|
||||
f_();
|
||||
}
|
||||
|
||||
private:
|
||||
F f_;
|
||||
bool call_ = true;
|
||||
};
|
||||
|
||||
template <class F>
|
||||
Finally<std::decay_t<F>> finally(F&& f) noexcept {
|
||||
return Finally {std::forward<F>(f)};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // __SRB2_CXXUTIL_HPP__
|
||||
|
|
@ -126,10 +126,10 @@ extern char logfilename[1024];
|
|||
// VERSIONSTRING_RC is for the resource-definition script used by windows builds
|
||||
#else
|
||||
#ifdef BETAVERSION
|
||||
#define VERSIONSTRING "v"SRB2VERSION" "BETAVERSION
|
||||
#define VERSIONSTRING "v" SRB2VERSION " " BETAVERSION
|
||||
#define VERSIONSTRING_RC SRB2VERSION " " BETAVERSION "\0"
|
||||
#else
|
||||
#define VERSIONSTRING "v"SRB2VERSION
|
||||
#define VERSIONSTRING "v" SRB2VERSION
|
||||
#define VERSIONSTRING_RC SRB2VERSION "\0"
|
||||
#endif
|
||||
// Hey! If you change this, add 1 to the MODVERSION below!
|
||||
|
|
@ -614,12 +614,14 @@ UINT32 quickncasehash (const char *p, size_t n)
|
|||
return x;
|
||||
}
|
||||
|
||||
#ifndef __cplusplus
|
||||
#ifndef min // Double-Check with WATTCP-32's cdefs.h
|
||||
#define min(x, y) (((x) < (y)) ? (x) : (y))
|
||||
#endif
|
||||
#ifndef max // Double-Check with WATTCP-32's cdefs.h
|
||||
#define max(x, y) (((x) > (y)) ? (x) : (y))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Max gamepad/joysticks that can be detected/used.
|
||||
#define MAX_JOYSTICKS 4
|
||||
|
|
|
|||
|
|
@ -17,6 +17,10 @@
|
|||
#ifndef __DOOMTYPE__
|
||||
#define __DOOMTYPE__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
//#define WIN32_LEAN_AND_MEAN
|
||||
#define RPC_NO_WINDOWS_H
|
||||
|
|
@ -88,7 +92,9 @@ typedef long ssize_t;
|
|||
#endif
|
||||
#define strncasecmp strnicmp
|
||||
#define strcasecmp stricmp
|
||||
#ifndef __cplusplus
|
||||
#define inline __inline
|
||||
#endif
|
||||
#elif defined (__WATCOMC__)
|
||||
#include <dos.h>
|
||||
#include <sys\types.h>
|
||||
|
|
@ -107,24 +113,6 @@ typedef long ssize_t;
|
|||
char *strcasestr(const char *in, const char *what);
|
||||
#define stristr strcasestr
|
||||
|
||||
#if defined (macintosh) //|| defined (__APPLE__) //skip all boolean/Boolean crap
|
||||
#define true 1
|
||||
#define false 0
|
||||
#define min(x,y) (((x)<(y)) ? (x) : (y))
|
||||
#define max(x,y) (((x)>(y)) ? (x) : (y))
|
||||
|
||||
#ifdef macintosh
|
||||
#define stricmp strcmp
|
||||
#define strnicmp strncmp
|
||||
#endif
|
||||
|
||||
#define boolean INT32
|
||||
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
#endif //macintosh
|
||||
|
||||
#if defined (PC_DOS) || defined (_WIN32) || defined (__HAIKU__)
|
||||
#define HAVE_DOSSTR_FUNCS
|
||||
#endif
|
||||
|
|
@ -151,22 +139,24 @@ size_t strlcpy(char *dst, const char *src, size_t siz);
|
|||
|
||||
/* Boolean type definition */
|
||||
|
||||
// \note __BYTEBOOL__ used to be set above if "macintosh" was defined,
|
||||
// if macintosh's version of boolean type isn't needed anymore, then isn't this macro pointless now?
|
||||
#ifndef __BYTEBOOL__
|
||||
#define __BYTEBOOL__
|
||||
// Note: C++ bool and C99/C11 _Bool are NOT compatible.
|
||||
// Historically, boolean was win32 BOOL on Windows. For equivalence, it's now
|
||||
// int32_t. "true" and "false" are only declared for C code; in C++, conversion
|
||||
// between "bool" and "int32_t" takes over.
|
||||
#ifndef _WIN32
|
||||
typedef int32_t boolean;
|
||||
#else
|
||||
#define BOOL boolean
|
||||
#endif
|
||||
|
||||
//faB: clean that up !!
|
||||
#if defined( _MSC_VER) && (_MSC_VER >= 1800) // MSVC 2013 and forward
|
||||
#include "stdbool.h"
|
||||
#elif defined (_WIN32)
|
||||
#define false FALSE // use windows types
|
||||
#define true TRUE
|
||||
#define boolean BOOL
|
||||
#else
|
||||
typedef enum {false, true} boolean;
|
||||
#endif
|
||||
#endif // __BYTEBOOL__
|
||||
#ifndef __cplusplus
|
||||
#ifndef _WIN32
|
||||
enum {false = 0, true = 1};
|
||||
#else
|
||||
#define false FALSE
|
||||
#define true TRUE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* 7.18.2.1 Limits of exact-width integer types */
|
||||
|
||||
|
|
@ -408,4 +398,8 @@ typedef UINT64 precise_t;
|
|||
|
||||
#include "typedef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
#endif //__DOOMTYPE__
|
||||
|
|
|
|||
3
src/tests/CMakeLists.txt
Normal file
3
src/tests/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
target_sources(srb2tests PRIVATE
|
||||
boolcompat.cpp
|
||||
)
|
||||
8
src/tests/boolcompat.cpp
Normal file
8
src/tests/boolcompat.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "../doomtype.h"
|
||||
|
||||
TEST_CASE("C++ bool is convertible to doomtype.h boolean") {
|
||||
REQUIRE(static_cast<boolean>(true) == 1);
|
||||
REQUIRE(static_cast<boolean>(false) == 0);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue