diff --git a/.github/scripts/install_deps.sh b/.github/scripts/install_deps.sh index 708ac6cd0..1fca339e9 100755 --- a/.github/scripts/install_deps.sh +++ b/.github/scripts/install_deps.sh @@ -13,6 +13,9 @@ case "${1%-*}" in export PATH="/opt/homebrew/opt/bison/bin:$PATH" printf 'PATH=%s\n' "$PATH" >>"$GITHUB_ENV" # Make it available to later CI steps too ;; + freebsd) + pkg install -y bash bison cmake git png + ;; *) echo "WARNING: Cannot install deps for OS '$1'" ;; diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index adfb18295..70ba52d7c 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -376,14 +376,9 @@ jobs: release: "14.3" usesh: true prepare: | - pkg install -y \ - bash \ - bison \ - cmake \ - git \ - png + .github/scripts/install_deps.sh freebsd run: | # FreeBSD `c++` compiler does not support `make develop` sanitizers ASan or UBSan - cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=c++ -DUSE_EXTERNAL_TESTS=OFF -DOS=bsd + cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_COMPILER=c++ -DUSE_EXTERNAL_TESTS=OFF -DTESTS_OS_NAME=bsd cmake --build build -j4 --verbose cmake --install build --verbose cmake --build build --target test diff --git a/.gitignore b/.gitignore index fdb7c9f83..e78169b0c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ CMakeCache.txt CMakeFiles/ cmake_install.cmake +CMakeUserPresets.json build/ *.dSYM/ callgrind.out.* diff --git a/CMakeLists.txt b/CMakeLists.txt index 25852c02f..855833e81 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,12 @@ -# SPDX-License-Identifier: MIT +## SPDX-License-Identifier: MIT -# 3.9 required for LTO checks -# 3.17 optional for CMAKE_CTEST_ARGUMENTS -cmake_minimum_required(VERSION 3.9..3.17 FATAL_ERROR) +# 3.17 required for LTO checks messages +cmake_minimum_required(VERSION 3.17...4.2 FATAL_ERROR) project(rgbds - LANGUAGES CXX) + LANGUAGES CXX + DESCRIPTION "Game Boy assembly toolchain" + HOMEPAGE_URL "https://rgbds.gbdev.io") include(CTest) @@ -20,31 +21,33 @@ if(srcdir STREQUAL bindir) message(FATAL_ERROR "Terminating configuration") endif() -option(SANITIZERS "Build with sanitizers enabled" OFF) # Ignored on MSVC -option(MORE_WARNINGS "Turn on more warnings" OFF) # Ignored on MSVC +include(CMakeDependentOption) +option(SANITIZERS "Build with sanitizers enabled" OFF) +cmake_dependent_option(MORE_WARNINGS "Turn on more warnings" OFF !MSVC OFF) if(MSVC) - # MSVC's own standard library triggers warning C5105, - # "macro expansion producing 'defined' has undefined behavior". - # Warning C5030 is about unknown attributes (`[[gnu::ATTR]]`), none of ours being load-bearing. - # Warning C4996 is about using POSIX names, which we want to do for portability. - # We also opt into the C++20-conformant preprocessor. - add_compile_options(/MP /wd5105 /wd5030 /wd4996 /Zc:preprocessor) + add_compile_options( + /MP # Build multiple files in parallel. +# /wd5105 # MSVC's own standard library triggers warning C5105, "macro expansion producing 'defined' has undefined behavior". + /wd5030 # Warning C5030 is about unknown attributes (`[[gnu::ATTR]]`), none of ours being load-bearing. + /wd4996 # Warning C4996 is about using POSIX names, which we want to do for portability. + /Zc:preprocessor # Opt into the C++20-conformant preprocessor. + ) add_definitions(/D_CRT_SECURE_NO_WARNINGS) if(SANITIZERS) + message(STATUS "ASan enabled") set(SAN_FLAGS /fsanitize=address) add_compile_options(${SAN_FLAGS}) add_link_options(${SAN_FLAGS}) endif() else() - add_compile_options(-Wall -pedantic) - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # C++20 allows macros to take zero variadic arguments, but Clang (aka AppleClang on macOS) - # does not recognize this yet. - add_compile_options(-Wno-gnu-zero-variadic-macro-arguments) - endif() + add_compile_options(-Wall -pedantic + # C++20 allows macros to take zero variadic arguments. + # Some versions of Clang don't recognize this, and treat them as a GNU extension. + -Wno-gnu-zero-variadic-macro-arguments) if(SANITIZERS) + message(STATUS "ASan and UBSan enabled") set(SAN_FLAGS -fsanitize=address -fsanitize=undefined -fsanitize=float-divide-by-zero) add_compile_options(${SAN_FLAGS}) @@ -102,8 +105,6 @@ add_subdirectory(src) set(CMAKE_CTEST_ARGUMENTS "--verbose") add_subdirectory(test) -# By default, build in Release mode; Debug mode must be explicitly requested -# (You may want to augment it with the options above) if(CMAKE_BUILD_TYPE STREQUAL "Release") message(CHECK_START "Checking if LTO is supported") include(CheckIPOSupported) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 26d9dd4dc..2eb2fbfec 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,7 +2,7 @@ configure_file(version.cpp _version.cpp ESCAPE_QUOTES) -set(common_src +add_library(common OBJECT "extern/getopt.cpp" "cli.cpp" "diagnostics.cpp" @@ -10,7 +10,7 @@ set(common_src "usage.cpp" "util.cpp" "_version.cpp" - ) +) find_package(BISON 3.0.0 REQUIRED) set(BISON_FLAGS "-Wall -Dlr.type=ielr") @@ -31,15 +31,8 @@ BISON_TARGET(ASM_PARSER "asm/parser.y" "${PROJECT_SOURCE_DIR}/src/asm/parser.cpp" COMPILE_FLAGS "${BISON_FLAGS}" DEFINES_FILE "${PROJECT_SOURCE_DIR}/src/asm/parser.hpp" - ) - -BISON_TARGET(LINKER_SCRIPT_PARSER "link/script.y" - "${PROJECT_SOURCE_DIR}/src/link/script.cpp" - COMPILE_FLAGS "${BISON_FLAGS}" - DEFINES_FILE "${PROJECT_SOURCE_DIR}/src/link/script.hpp" - ) - -set(rgbasm_src +) +add_executable(rgbasm $ "${BISON_ASM_PARSER_OUTPUT_SOURCE}" "asm/actions.cpp" "asm/charmap.cpp" @@ -60,9 +53,14 @@ set(rgbasm_src "linkdefs.cpp" "opmath.cpp" "verbosity.cpp" - ) +) -set(rgblink_src +BISON_TARGET(LINKER_SCRIPT_PARSER "link/script.y" + "${PROJECT_SOURCE_DIR}/src/link/script.cpp" + COMPILE_FLAGS "${BISON_FLAGS}" + DEFINES_FILE "${PROJECT_SOURCE_DIR}/src/link/script.hpp" +) +add_executable(rgblink $ "${BISON_LINKER_SCRIPT_PARSER_OUTPUT_SOURCE}" "link/assign.cpp" "link/fstack.cpp" @@ -81,16 +79,16 @@ set(rgblink_src "linkdefs.cpp" "opmath.cpp" "verbosity.cpp" - ) +) -set(rgbfix_src +add_executable(rgbfix $ "fix/fix.cpp" "fix/main.cpp" "fix/mbc.cpp" "fix/warning.cpp" - ) +) -set(rgbgfx_src +add_executable(rgbgfx $ "gfx/color_set.cpp" "gfx/main.cpp" "gfx/pal_packing.cpp" @@ -103,19 +101,13 @@ set(rgbgfx_src "gfx/rgba.cpp" "gfx/warning.cpp" "verbosity.cpp" - ) +) -foreach(PROG "asm" "fix" "gfx" "link") - add_executable(rgb${PROG} - ${rgb${PROG}_src} - ${common_src} - ) - install(TARGETS rgb${PROG} RUNTIME DESTINATION bin) - # Required to run tests - set_target_properties(rgb${PROG} PROPERTIES - # hack for MSVC: no-op generator expression to stop generation of "per-configuration subdirectory" - RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}>) -endforeach() +install(TARGETS rgbasm rgblink rgbfix rgbgfx RUNTIME DESTINATION bin) +# Required to run tests +set_target_properties(rgbasm rgblink rgbfix rgbgfx PROPERTIES +# hack for MSVC: no-op generator expression to stop generation of "per-configuration subdirectory" + RUNTIME_OUTPUT_DIRECTORY $<1:${CMAKE_SOURCE_DIR}>) if(LIBPNG_FOUND) # pkg-config target_include_directories(rgbgfx PRIVATE ${LIBPNG_INCLUDE_DIRS}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b054f5861..d93311ecd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,16 +2,11 @@ option(USE_NONFREE_TESTS "run tests that build nonfree codebases" ON) option(USE_EXTERNAL_TESTS "run tests that build external codebases" ON) +set(TESTS_OS_NAME "" CACHE STRING "skip running tests known to fail on this OS") -if(NOT USE_NONFREE_TESTS) - set(ONLY_FREE "--only-free") -endif() -if(NOT USE_EXTERNAL_TESTS) - set(ONLY_INTERNAL "--only-internal") -endif() -if(DEFINED OS) - set(OS_NAME "--os" "${OS}") -endif() +set(ONLY_FREE $,,--only-free>) +set(ONLY_INTERNAL $,,--only-internal>) +set(OS_NAME "$,,--os;${TESTS_OS_NAME}>") add_executable(randtilegen gfx/randtilegen.cpp) add_executable(rgbgfx_test gfx/rgbgfx_test.cpp) diff --git a/test/fetch-test-deps.sh b/test/fetch-test-deps.sh index 4cfcfae15..507446f9e 100755 --- a/test/fetch-test-deps.sh +++ b/test/fetch-test-deps.sh @@ -4,14 +4,16 @@ set -euo pipefail cd "$(dirname "$0")" usage() { - echo "Downloads source code of Game Boy programs used as RGBDS test cases." - echo "Options:" - echo " -h, --help show this help message" - echo " --only-free download only freely licensed codebases" - echo " --only-internal do not download any codebases" - echo " --get-deps install programs' own dependencies instead of themselves" - echo " --get-hash print programs' commit hashes instead of downloading them" - echo " --get-paths print programs' GitHub paths instead of downloading them" + cat <<"EOF" +Downloads source code of Game Boy programs used as RGBDS test cases. +Options: + -h, --help show this help message + --only-free download only freely licensed codebases + --only-internal do not download any codebases + --get-deps install programs' own dependencies instead of themselves + --get-hash print programs' commit hashes instead of downloading them + --get-paths print programs' GitHub paths instead of downloading them +EOF } # Parse options in pure Bash because macOS `getopt` is stuck diff --git a/test/run-tests.sh b/test/run-tests.sh index 495956e0f..c648faf49 100755 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -9,14 +9,17 @@ export SOURCE_DATE_EPOCH=609165296 cd "$(dirname "$0")" usage() { - echo "Runs regression tests on RGBDS." - echo "Options:" - echo " -h, --help show this help message" - echo " --only-internal only run tests that build local examples" - echo " --only-external only run tests that build external codebases" - echo " --only-free skip tests that build nonfree codebases" - echo " --installed-rgbds use the system installed RGBDS" - echo " (only compatible with external codebases)" + cat <<"EOF" +Runs regression tests on RGBDS. +Options: + -h, --help show this help message + --only-internal only run tests that build local examples + --only-external only run tests that build external codebases + --only-free skip tests that build nonfree codebases + --os skip tests known to fail on (e.g. `macos-14`) + --installed-rgbds use the system installed RGBDS + (only compatible with external codebases) +EOF } # Parse options in pure Bash because macOS `getopt` is stuck @@ -57,7 +60,7 @@ while [[ $# -gt 0 ]]; do break ;; *) - echo "$(basename "$0"): internal error" + echo "$(basename "$0"): unknown option '$1'" exit 1 ;; esac @@ -134,6 +137,7 @@ test_downstream pinobatch libbet all libbet.gb f117089aa056600e2d404bbcbac test_downstream LIJI32 SameBoy bootroms build/bin/BootROMs/cgb_boot.bin 113903775a9d34b798c2f8076672da6626815a91 # gb-starter kit fails with any `make` on Windows: https://codeberg.org/ISSOtm/gb-starter-kit/issues/1 # gb-starter-kit fails with macOS/BSD `make`: https://codeberg.org/ISSOtm/gb-starter-kit/issues/29 -if [[ "${osname%-*}" != "windows" && "${osname%-*}" != "macos" && "${osname%-*}" != "bsd" ]]; then - test_downstream ISSOtm gb-starter-kit all bin/boilerplate.gb b4f130169ba73284e0d0e71b53e7baa4eca2f7fe -fi +case "${osname%%-*}" in + windows | macos | bsd) ;; + *) test_downstream ISSOtm gb-starter-kit all bin/boilerplate.gb b4f130169ba73284e0d0e71b53e7baa4eca2f7fe;; +esac