Skip to content

Commit

Permalink
Build everything as C++
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 committed Nov 3, 2023
1 parent 9e4b9e7 commit d2c6290
Show file tree
Hide file tree
Showing 83 changed files with 682 additions and 679 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++17
Standard: c++20
TabWidth: 4
UseCRLF: false
UseTab: ForIndentation
2 changes: 1 addition & 1 deletion .github/workflows/create-release-artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ jobs:
body: |
Please ensure that the four packages below work properly.
Once that's done, replace this text with the changelog, un-draft the release, and update the `release` branch.
By the way, if you forgot to update `include/version.h`, RGBASM's version test is gonna fail in the tag's regression testing! (Use `git push --delete origin <tag>` to delete it)
By the way, if you forgot to update `include/version.hpp`, RGBASM's version test is gonna fail in the tag's regression testing! (Use `git push --delete origin <tag>` to delete it)
draft: true # Don't publish the release quite yet...
prerelease: ${{ contains(github.ref, '-rc') }}
files: |
Expand Down
19 changes: 8 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)

project(rgbds
LANGUAGES C CXX)
LANGUAGES CXX)

# get real path of source and binary directories
get_filename_component(srcdir "${CMAKE_SOURCE_DIR}" REALPATH)
Expand All @@ -31,19 +31,16 @@ if(MSVC)
# "macro expansion producing 'defined' has undefined behavior"
add_compile_options(/MP /wd5105)
add_definitions(/D_CRT_SECURE_NO_WARNINGS)
# Also, CMake appears not to pass the C11-enabling flag, so we must add it manually... but only for C!
if(NOT CMAKE_C_FLAGS MATCHES "std:c11") # The flag may already have been injected by an earlier CMake invocation, so don't add it twice
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std:c11" CACHE STRING "Flags used by the C compiler during all build types." FORCE)
endif()

if(SANITIZERS)
set(SAN_FLAGS /fsanitize=address)
add_compile_options(${SAN_FLAGS})
add_link_options(${SAN_FLAGS})
endif()
else()
add_compile_options(-Wall -pedantic)
add_definitions(-D_POSIX_C_SOURCE=200809L -D_ISOC11_SOURCE)
# TODO: use -pedantic after non-C++ idioms are gone
add_compile_options(-Wall)
add_definitions(-D_POSIX_C_SOURCE=200809L)
if(SANITIZERS)
set(SAN_FLAGS -fsanitize=shift -fsanitize=integer-divide-by-zero
-fsanitize=unreachable -fsanitize=vla-bound
Expand All @@ -55,7 +52,6 @@ else()
add_definitions(-D_GLIBCXX_ASSERTIONS)
# A non-zero optimization level is desired in debug mode, but allow overriding it nonetheless
# TODO: this overrides anything previously set... that's a bit sloppy!
set(CMAKE_C_FLAGS_DEBUG "-g -Og -fno-omit-frame-pointer -fno-optimize-sibling-calls" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "-g -Og -fno-omit-frame-pointer -fno-optimize-sibling-calls" CACHE STRING "" FORCE)
endif()

Expand All @@ -71,6 +67,9 @@ else()
-Wno-type-limits -Wno-tautological-constant-out-of-range-compare
-Wvla # MSVC does not support VLAs
-Wno-unknown-warning-option) # Clang shouldn't diagnose unknown warnings
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Wno-c99-designator)
endif()
endif()
endif()

Expand Down Expand Up @@ -98,9 +97,7 @@ endif()

include_directories("${PROJECT_SOURCE_DIR}/include")

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED True)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)

add_subdirectory(src)
Expand Down
67 changes: 31 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#

.SUFFIXES:
.SUFFIXES: .h .y .c .cpp .o
.SUFFIXES: .hpp .cpp .y .o

.PHONY: all clean install checkcodebase checkpatch checkdiff develop debug mingw32 mingw64 wine-shim dist

Expand All @@ -29,19 +29,19 @@ PNGCFLAGS := `${PKG_CONFIG} --cflags libpng`
PNGLDFLAGS := `${PKG_CONFIG} --libs-only-L libpng`
PNGLDLIBS := `${PKG_CONFIG} --libs-only-l libpng`

# Note: if this comes up empty, `version.c` will automatically fall back to last release number
# Note: if this comes up empty, `version.cpp` will automatically fall back to last release number
VERSION_STRING := `git describe --tags --dirty --always 2>/dev/null`

WARNFLAGS := -Wall -pedantic
# TODO: use -pedantic after non-C++ idioms are gone
WARNFLAGS := -Wall
ifeq ($(CXX),clang++)
WARNFLAGS += -Wno-c99-designator
endif

# Overridable CFLAGS
CFLAGS ?= -O3 -flto -DNDEBUG
# Overridable CXXFLAGS
CXXFLAGS ?= -O3 -flto -DNDEBUG
# Non-overridable CFLAGS
# _ISOC11_SOURCE is required on certain platforms to get C11 on top of the C99-based POSIX 2008
REALCFLAGS := ${CFLAGS} ${WARNFLAGS} -std=gnu11 -I include \
-D_POSIX_C_SOURCE=200809L -D_ISOC11_SOURCE
REALCXXFLAGS := ${CXXFLAGS} ${WARNFLAGS} -std=c++17 -I include \
# Non-overridable CXXFLAGS
REALCXXFLAGS := ${CXXFLAGS} ${WARNFLAGS} -x c++ -std=c++2a -I include \
-D_POSIX_C_SOURCE=200809L -fno-exceptions -fno-rtti
# Overridable LDFLAGS
LDFLAGS ?=
Expand Down Expand Up @@ -84,7 +84,7 @@ rgbasm_obj := \
src/linkdefs.o \
src/opmath.o

src/asm/lexer.o src/asm/main.o: src/asm/parser.h
src/asm/lexer.o src/asm/main.o: src/asm/parser.hpp

rgblink_obj := \
src/link/assign.o \
Expand Down Expand Up @@ -121,19 +121,19 @@ rgbgfx_obj := \
src/error.o

rgbasm: ${rgbasm_obj}
$Q${CC} ${REALLDFLAGS} -o $@ ${rgbasm_obj} ${REALCFLAGS} src/version.c -lm
$Q${CXX} ${REALLDFLAGS} -o $@ ${rgbasm_obj} ${REALCXXFLAGS} src/version.cpp -lm

rgblink: ${rgblink_obj}
$Q${CC} ${REALLDFLAGS} -o $@ ${rgblink_obj} ${REALCFLAGS} src/version.c
$Q${CXX} ${REALLDFLAGS} -o $@ ${rgblink_obj} ${REALCXXFLAGS} src/version.cpp

rgbfix: ${rgbfix_obj}
$Q${CC} ${REALLDFLAGS} -o $@ ${rgbfix_obj} ${REALCFLAGS} src/version.c
$Q${CXX} ${REALLDFLAGS} -o $@ ${rgbfix_obj} ${REALCXXFLAGS} src/version.cpp

rgbgfx: ${rgbgfx_obj}
$Q${CXX} ${REALLDFLAGS} ${PNGLDFLAGS} -o $@ ${rgbgfx_obj} ${REALCXXFLAGS} ${PNGLDLIBS} -x c++ src/version.c
$Q${CXX} ${REALLDFLAGS} ${PNGLDFLAGS} -o $@ ${rgbgfx_obj} ${REALCXXFLAGS} ${PNGLDLIBS} src/version.cpp

test/gfx/randtilegen: test/gfx/randtilegen.c
$Q${CC} ${REALLDFLAGS} ${PNGLDFLAGS} -o $@ $^ ${REALCFLAGS} ${PNGCFLAGS} ${PNGLDLIBS}
test/gfx/randtilegen: test/gfx/randtilegen.cpp
$Q${CXX} ${REALLDFLAGS} ${PNGLDFLAGS} -o $@ $^ ${REALCXXFLAGS} ${PNGCFLAGS} ${PNGLDLIBS}

test/gfx/rgbgfx_test: test/gfx/rgbgfx_test.cpp
$Q${CXX} ${REALLDFLAGS} ${PNGLDFLAGS} -o $@ $^ ${REALCXXFLAGS} ${PNGLDLIBS}
Expand All @@ -144,10 +144,10 @@ test/gfx/rgbgfx_test: test/gfx/rgbgfx_test.cpp
.y.o:

# Bison-generated C files have an accompanying header
src/asm/parser.h: src/asm/parser.c
src/asm/parser.hpp: src/asm/parser.cpp
$Qtouch $@

src/asm/parser.c: src/asm/parser.y
src/asm/parser.cpp: src/asm/parser.y
$QDEFS=; \
add_flag(){ \
if src/check_bison_ver.sh $$1 $$2; then \
Expand All @@ -164,24 +164,21 @@ src/asm/parser.c: src/asm/parser.y

# Only RGBGFX uses libpng (POSIX make doesn't support pattern rules to cover all these)
src/gfx/main.o: src/gfx/main.cpp
$Q${CXX} ${REALCXXFLAGS} -c -o $@ $<
$Q${CXX} ${REALCXXFLAGS} ${PNGCFLAGS} -c -o $@ $<
src/gfx/pal_packing.o: src/gfx/pal_packing.cpp
$Q${CXX} ${REALCXXFLAGS} -c -o $@ $<
$Q${CXX} ${REALCXXFLAGS} ${PNGCFLAGS} -c -o $@ $<
src/gfx/pal_sorting.o: src/gfx/pal_sorting.cpp
$Q${CXX} ${REALCXXFLAGS} -c -o $@ $<
$Q${CXX} ${REALCXXFLAGS} ${PNGCFLAGS} -c -o $@ $<
src/gfx/pal_spec.o: src/gfx/pal_spec.cpp
$Q${CXX} ${REALCXXFLAGS} -c -o $@ $<
$Q${CXX} ${REALCXXFLAGS} ${PNGCFLAGS} -c -o $@ $<
src/gfx/process.o: src/gfx/process.cpp
$Q${CXX} ${REALCXXFLAGS} -c -o $@ $<
$Q${CXX} ${REALCXXFLAGS} ${PNGCFLAGS} -c -o $@ $<
src/gfx/proto_palette.o: src/gfx/proto_palette.cpp
$Q${CXX} ${REALCXXFLAGS} -c -o $@ $<
$Q${CXX} ${REALCXXFLAGS} ${PNGCFLAGS} -c -o $@ $<
src/gfx/reverse.o: src/gfx/reverse.cpp
$Q${CXX} ${REALCXXFLAGS} -c -o $@ $<
$Q${CXX} ${REALCXXFLAGS} ${PNGCFLAGS} -c -o $@ $<
src/gfx/rgba.o: src/gfx/rgba.cpp
$Q${CXX} ${REALCXXFLAGS} -c -o $@ $<

.c.o:
$Q${CC} ${REALCFLAGS} -c -o $@ $<
$Q${CXX} ${REALCXXFLAGS} ${PNGCFLAGS} -c -o $@ $<

.cpp.o:
$Q${CXX} ${REALCXXFLAGS} -c -o $@ $<
Expand All @@ -195,7 +192,7 @@ clean:
$Q${RM} rgbgfx rgbgfx.exe
$Qfind src/ -name "*.o" -exec rm {} \;
$Q${RM} rgbshim.sh
$Q${RM} src/asm/parser.c src/asm/parser.h
$Q${RM} src/asm/parser.cpp src/asm/parser.hpp
$Q${RM} test/gfx/randtilegen test/gfx/rgbgfx_test

# Target used to install the binaries and man pages.
Expand All @@ -213,7 +210,7 @@ install: all
# `.y` files aren't checked, unfortunately...

checkcodebase:
$Qfor file in `git ls-files | grep -E '(\.c|\.h)$$' | grep -Ev '(src|include)/extern/'`; do \
$Qfor file in `git ls-files | grep -E '(\.cpp|\.hpp)$$' | grep -Ev '(src|include)/extern/'`; do \
${CHECKPATCH} -f "$$file"; \
done

Expand Down Expand Up @@ -258,14 +255,12 @@ develop:
-fsanitize=signed-integer-overflow -fsanitize=bounds \
-fsanitize=object-size -fsanitize=bool -fsanitize=enum \
-fsanitize=alignment -fsanitize=null -fsanitize=address" \
CFLAGS="-ggdb3 -Og -fno-omit-frame-pointer -fno-optimize-sibling-calls" \
CXXFLAGS="-ggdb3 -Og -fno-omit-frame-pointer -fno-optimize-sibling-calls"

# This target is used during development in order to more easily debug with gdb.

debug:
$Qenv ${MAKE} \
CFLAGS="-ggdb3 -Og -fno-omit-frame-pointer -fno-optimize-sibling-calls" \
CXXFLAGS="-ggdb3 -Og -fno-omit-frame-pointer -fno-optimize-sibling-calls"

# Targets for the project maintainer to easily create Windows exes.
Expand All @@ -275,12 +270,12 @@ debug:

mingw32:
$Q${MAKE} all test/gfx/randtilegen test/gfx/rgbgfx_test \
CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ \
CXX=i686-w64-mingw32-g++ \
BISON=bison PKG_CONFIG="PKG_CONFIG_SYSROOT_DIR=/usr/i686-w64-mingw32 pkg-config"

mingw64:
$Q${MAKE} all test/gfx/randtilegen test/gfx/rgbgfx_test \
CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ \
CXX=x86_64-w64-mingw32-g++ \
BISON=bison PKG_CONFIG="PKG_CONFIG_SYSROOT_DIR=/usr/x86_64-w64-mingw32 pkg-config"

wine-shim:
Expand Down
4 changes: 2 additions & 2 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Releasing
This describes for the maintainers of RGBDS how to publish a new release on
GitHub.

1. Update, commit, and push `include/version.h <include/version.h>`__ with
1. Update, commit, and push `include/version.hpp <include/version.hpp>`__ with
values for ``PACKAGE_VERSION_MAJOR``, ``PACKAGE_VERSION_MINOR``,
``PACKAGE_VERSION_PATCH``, and ``PACKAGE_VERSION_RC``. Only define
``PACKAGE_VERSION_RC`` if you are publishing a release candidate! You can
Expand All @@ -13,7 +13,7 @@ GitHub.
2. Create a Git tag formatted as ``v<MAJOR>.<MINOR>.<PATCH>``, or
``v<MAJOR>.<MINOR>.<PATCH>-rc<RC>`` for a release candidate. ``MAJOR``,
``MINOR``, ``PATCH``, and ``RC`` should match their values from
`include/version.h <include/version.h>`__. You can use ``git tag <tag>``.
`include/version.hpp <include/version.hpp>`__. You can use ``git tag <tag>``.

3. Push the tag to GitHub. You can use ``git push origin <tag>``.

Expand Down
38 changes: 19 additions & 19 deletions contrib/checkdiff.bash
Original file line number Diff line number Diff line change
Expand Up @@ -40,46 +40,46 @@ dependency () {
# Pull requests that edit the first file without the second may be correct,
# but are suspicious enough to require review.

dependency include/linkdefs.h man/rgbds.5 \
dependency include/linkdefs.hpp man/rgbds.5 \
"Was the object file format changed?"

dependency src/asm/parser.y man/rgbasm.5 \
dependency src/asm/parser.y man/rgbasm.5 \
"Was the rgbasm grammar changed?"

dependency include/asm/warning.h man/rgbasm.1 \
dependency include/asm/warning.hpp man/rgbasm.1 \
"Were the rgbasm warnings changed?"

dependency src/asm/object.c include/linkdefs.h \
dependency src/asm/object.cpp include/linkdefs.hpp \
"Should the object file revision be bumped?"
dependency src/link/object.c include/linkdefs.h \
dependency src/link/object.cpp include/linkdefs.hpp \
"Should the object file revision be bumped?"

dependency Makefile CMakeLists.txt \
dependency Makefile CMakeLists.txt \
"Did the build process change?"
dependency Makefile src/CMakeLists.txt \
dependency Makefile src/CMakeLists.txt \
"Did the build process change?"

dependency src/asm/main.c man/rgbasm.1 \
dependency src/asm/main.cpp man/rgbasm.1 \
"Did the rgbasm CLI change?"
dependency src/asm/main.c contrib/zsh_compl/_rgbasm \
dependency src/asm/main.cpp contrib/zsh_compl/_rgbasm \
"Did the rgbasm CLI change?"
dependency src/asm/main.c contrib/bash_compl/_rgbasm.bash \
dependency src/asm/main.cpp contrib/bash_compl/_rgbasm.bash \
"Did the rgbasm CLI change?"
dependency src/link/main.c man/rgblink.1 \
dependency src/link/main.cpp man/rgblink.1 \
"Did the rgblink CLI change?"
dependency src/link/main.c contrib/zsh_compl/_rgblink \
dependency src/link/main.cpp contrib/zsh_compl/_rgblink \
"Did the rgblink CLI change?"
dependency src/link/main.c contrib/bash_compl/_rgblink.bash \
dependency src/link/main.cpp contrib/bash_compl/_rgblink.bash \
"Did the rgblink CLI change?"
dependency src/fix/main.c man/rgbfix.1 \
dependency src/fix/main.cpp man/rgbfix.1 \
"Did the rgbfix CLI change?"
dependency src/fix/main.c contrib/zsh_compl/_rgbfix \
dependency src/fix/main.cpp contrib/zsh_compl/_rgbfix \
"Did the rgbfix CLI change?"
dependency src/fix/main.c contrib/bash_compl/_rgbfix.bash \
dependency src/fix/main.cpp contrib/bash_compl/_rgbfix.bash \
"Did the rgbfix CLI change?"
dependency src/gfx/main.cpp man/rgbgfx.1 \
dependency src/gfx/main.cpp man/rgbgfx.1 \
"Did the rgbgfx CLI change?"
dependency src/gfx/main.cpp contrib/zsh_compl/_rgbgfx \
dependency src/gfx/main.cpp contrib/zsh_compl/_rgbgfx \
"Did the rgbgfx CLI change?"
dependency src/gfx/main.cpp contrib/bash_compl/_rgbgfx.bash \
dependency src/gfx/main.cpp contrib/bash_compl/_rgbgfx.bash \
"Did the rgbgfx CLI change?"
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 8 additions & 6 deletions include/asm/fstack.h → include/asm/fstack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@
#include <stdint.h>
#include <stdio.h>

#include "asm/lexer.h"
#include "asm/lexer.hpp"


enum FileStackNodeType {
NODE_REPT,
NODE_FILE,
NODE_MACRO,
};

struct FileStackNode {
struct FileStackNode *parent; // Pointer to parent node, for error reporting
// Line at which the parent context was exited; meaningless for the root level
Expand All @@ -27,11 +33,7 @@ struct FileStackNode {
bool referenced; // If referenced, don't free!
uint32_t ID; // Set only if referenced: ID within the object file, -1 if not output yet

enum {
NODE_REPT,
NODE_FILE,
NODE_MACRO,
} type;
enum FileStackNodeType type;
};

struct FileStackReptNode { // NODE_REPT
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions include/asm/macro.h → include/asm/macro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#include <stdbool.h>
#include <stdlib.h>

#include "asm/warning.h"
#include "asm/warning.hpp"

#include "helpers.h"
#include "helpers.hpp"

struct MacroArgs;

Expand Down
2 changes: 1 addition & 1 deletion include/asm/main.h → include/asm/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <stdint.h>
#include <stdio.h>

#include "helpers.h"
#include "helpers.hpp"

extern bool haltnop;
extern bool warnOnHaltNop;
Expand Down
4 changes: 2 additions & 2 deletions include/asm/opt.h → include/asm/opt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ void opt_G(char const chars[4]);
void opt_P(uint8_t padByte);
void opt_Q(uint8_t precision);
void opt_L(bool optimize);
void opt_W(char const *flag);
void opt_Parse(char const *option);
void opt_W(char *flag);
void opt_Parse(char *option);

void opt_Push(void);
void opt_Pop(void);
Expand Down
Loading

0 comments on commit d2c6290

Please sign in to comment.