Skip to content

Commit

Permalink
Workflows: Quick, Medium, and Full Builds (#129)
Browse files Browse the repository at this point in the history
* Windows: Full and Medium Builds

* Disable tests on Windows. CMake minimum version 3.14

* Fix definitions for cmake

* Fix CMake definitions in clang

* Warning when can't build tests

* Fix: fl::null in g++-12

* Documentation: building Catch2

* Fix: Fetch Catch2 if not found in system
  • Loading branch information
jcrada committed Jan 17, 2024
1 parent f698f96 commit 1291ae6
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 45 deletions.
39 changes: 30 additions & 9 deletions .github/workflows/LinuxFullBuild.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: FuzzyLite (Linux)
name: Linux Full Build

on:
push:
branches: [ "main" ]
branches: [ "build/*" ]

jobs:
build:
build-clang:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
compiler_version: [ "13", "14", "15"]
build_type: [ "release", "debug" ]
use_cxx: [ "clang++", "g++" ]
use_cpp98: [ "OFF", "ON" ]
use_float: [ "OFF", "ON" ]

Expand All @@ -22,10 +22,31 @@ jobs:
- name: Building FuzzyLite
working-directory: fuzzylite
env:
FL_CPP98: ${{ matrix.use_cpp98 }}
FL_USE_FLOAT: ${{ matrix.use_float }}
CXX: ${{ matrix.use_cxx }}
FL_BUILD_TESTS: "OFF"
CXX: clang++-${{ matrix.compiler_version }}
run: |
cmake -B build/${{ matrix.build_type }} -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} .
cmake -B build/${{ matrix.build_type }} -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DFL_CPP98=${{ matrix.use_cpp98 }} -DFL_USE_FLOAT=${{ matrix.use_float }} .
cmake --build build/${{ matrix.build_type }} --parallel
ctest --test-dir build/${{ matrix.build_type }}
build-gcc:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
compiler_version: [ "9", "10", "11", "12", "13" ]
build_type: [ "release" ]
use_cpp98: [ "OFF", "ON" ]
use_float: [ "OFF", "ON" ]

steps:
- uses: actions/checkout@v4

- name: Building FuzzyLite
working-directory: fuzzylite
env:
CXX: g++-${{ matrix.compiler_version }}
run: |
cmake -B build/${{ matrix.build_type }} -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DFL_CPP98=${{ matrix.use_cpp98 }} -DFL_USE_FLOAT=${{ matrix.use_float }} .
cmake --build build/${{ matrix.build_type }} --parallel
ctest --test-dir build/${{ matrix.build_type }}
29 changes: 29 additions & 0 deletions .github/workflows/LinuxMediumBuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Linux Medium Build

on:
push:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
build_type: [ "release", "debug" ]
use_cxx: [ "clang++-15", "g++-13" ]
use_cpp98: [ "OFF", "ON" ]
use_float: [ "OFF", "ON" ]

steps:
- uses: actions/checkout@v4

- name: Building FuzzyLite
working-directory: fuzzylite
env:
CXX: ${{ matrix.use_cxx }}
run: |
cmake -B build/${{ matrix.build_type }} -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DFL_CPP98=${{ matrix.use_cpp98 }} -DFL_USE_FLOAT=${{ matrix.use_float }} .
cmake --build build/${{ matrix.build_type }} --parallel
ctest --test-dir build/${{ matrix.build_type }}
3 changes: 2 additions & 1 deletion .github/workflows/LinuxQuickBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
build_type: [ "release" ]
use_cxx: [ "clang++", "g++" ]
use_cxx: [ "clang++-15" ]

steps:
- uses: actions/checkout@v4
Expand All @@ -24,3 +24,4 @@ jobs:
run: |
cmake -B build/${{ matrix.build_type }} -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} .
cmake --build build/${{ matrix.build_type }} --parallel
ctest --test-dir build/${{ matrix.build_type }}
16 changes: 6 additions & 10 deletions .github/workflows/WindowsFullBuild.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
name: FuzzyLite (Windows)
name: Windows Full Build

on:
push:
branches: [ "main" ]
branches: [ "build/*" ]

jobs:
build:
runs-on: windows-latest
name: Windows-VisualStudio-${{matrix.platform}}

strategy:
fail-fast: false
matrix:
platform: [ 'x64', 'win32' ]
platform: [ "x64", "win32" ]
build_type: [ "release", "debug" ]
use_cpp98: [ "OFF", "ON" ]
use_float: [ "OFF", "ON" ]

steps:
- uses: actions/checkout@v4
- uses: ilammy/msvc-dev-cmd@v1

- name: Building FuzzyLite
working-directory: fuzzylite
shell: cmd
env:
FL_CPP98: ${{ matrix.use_cpp98 }}
FL_USE_FLOAT: ${{ matrix.use_float }}
FL_BUILD_TESTS: "OFF"
run: |
cmake -B build/${{ matrix.build_type }} -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} .
cmake -B build/${{ matrix.build_type }} -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DFL_CPP98=${{ matrix.use_cpp98 }} -DFL_USE_FLOAT=${{ matrix.use_float }} -DFL_BUILD_TESTS=OFF .
cmake --build build/${{ matrix.build_type }} --parallel
ctest --test-dir build/${{ matrix.build_type }}
28 changes: 28 additions & 0 deletions .github/workflows/WindowsMediumBuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Windows Medium Build

on:
push:
branches: [ "main" ]

jobs:
build:
runs-on: windows-latest

strategy:
fail-fast: false
matrix:
build_type: [ "release", "debug" ]
platform: [ "x64", "win32" ]

steps:
- uses: actions/checkout@v4

- uses: ilammy/msvc-dev-cmd@v1

- name: Building FuzzyLite
working-directory: fuzzylite
shell: cmd
run: |
cmake -B build/${{ matrix.build_type }} -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DFL_BUILD_TESTS=OFF .
cmake --build build/${{ matrix.build_type }} --parallel
ctest --test-dir build/${{ matrix.build_type }}
5 changes: 3 additions & 2 deletions .github/workflows/WindowsQuickBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
build_type: [ "release" ]
platform: [ 'x64', 'win32' ]
platform: [ "x64" ]

steps:
- uses: actions/checkout@v4
Expand All @@ -23,5 +23,6 @@ jobs:
working-directory: fuzzylite
shell: cmd
run: |
cmake -B build/${{ matrix.build_type }} -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} .
cmake -B build/${{ matrix.build_type }} -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DFL_BUILD_TESTS=OFF .
cmake --build build/${{ matrix.build_type }} --parallel
ctest --test-dir build/${{ matrix.build_type }}
62 changes: 40 additions & 22 deletions fuzzylite/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0.2)
cmake_minimum_required(VERSION 3.13)

cmake_policy(SET CMP0048 NEW)
set(FL_VERSION 7.0.0)
Expand Down Expand Up @@ -227,42 +227,60 @@ if(FL_BUILD_BINARY)
list(APPEND fl-targets fl-bin)
endif(FL_BUILD_BINARY)

if(FL_BUILD_TESTS)
# https://github.com/catchorg/Catch2/blob/v2.x/docs/cmake-integration.md
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.10
)
FetchContent_MakeAvailable(Catch2)
if(FL_BUILD_TESTS AND FL_CPP98)
message(WARNING "Skipping tests: tests require C++11 or later, but using FL_CPP98=${FL_CPP98}.")

elseif(FL_BUILD_TESTS)
message(CHECK_START "Detecting Catch2 library in system")
if (CMAKE_VERSION VERSION_LESS "3.14")
find_package(Catch2 2 REQUIRED)
else()
find_package(Catch2 2 QUIET)
endif()


if (Catch2_FOUND)
message(CHECK_PASS "found at ${Catch2}")
else()
message(CHECK_FAIL "not found")
# You can install it manually: |
# git clone -b v2.x https://github.com/catchorg/Catch2.git lib/Catch2
# cd lib/Catch2
# cmake -B build -DCATCH_ENABLE_WERROR=OFF .
# cmake --build build --parallel --target install

message(CHECK_START "Fetching Catch2 v2.13.10 library from https://github.com/catchorg/Catch2.git")
# But we are going to try to fetch it:
# see https://github.com/catchorg/Catch2/blob/v2.x/docs/cmake-integration.md
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v2.13.10
)
FetchContent_MakeAvailable(Catch2)
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/contrib)
message(CHECK_PASS "fetched")
endif()

add_executable(fl-test ${fl-headers} ${fl-tests})
set_target_properties(fl-test PROPERTIES OUTPUT_NAME fuzzylite-tests)
set_target_properties(fl-test PROPERTIES OUTPUT_NAME fuzzylite-tests IMPORT_PREFIX tmp-) #To prevent LNK1149 in Windows
set_target_properties(fl-test PROPERTIES DEBUG_POSTFIX -debug)

target_compile_definitions(fl-test PRIVATE FL_IMPORT_LIBRARY)
if (FL_CPP98)
target_compile_definitions(fl-test PRIVATE CATCH_CONFIG_NO_CPP11)
endif()

if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
#Ignore QuickTest macro expansion comparison: CHECK(xstr(4+10) == "4+10")
target_compile_options(fl-test PRIVATE -Wno-address)
endif()
if (MSVC)
target_compile_options(fl-test PRIVATE /wd4130)
endif()

target_link_libraries(fl-test fl-shared ${FL_LIBS} Catch2::Catch2)

include(CTest)
include(Catch)
catch_discover_tests(fl-test)

enable_testing()
add_test(NAME RunTests COMMAND fl-test)
# add_test(NAME ListTests COMMAND fl-test --list-tests)
# set_tests_properties(ListTests PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ test case")
# add_test(NAME ListTags COMMAND fl-test --list-tags)
# set_tests_properties(ListTags PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ tag")
endif()

###INSTALL SECTION
Expand Down
19 changes: 18 additions & 1 deletion fuzzylite/fl/fuzzylite.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,24 @@ namespace fl {
Represents the `C++11` or `C++98` null pointer depending on whether the
compilation flag `-DFL_CPP98` is set
*/
const long null = 0L;
// https://stackoverflow.com/questions/44517556/how-to-define-our-own-nullptr-in-c98
const class nullptr_t {
public:
template <class T> /* convertible to any type of null non-member pointer */
operator T*() const {
return 0;
}

template <class C, class T> /* or any type of null member pointer */
operator T C::*() const {
return 0;
}

private:
void operator&() const; /* Can't take address of nullptr */

} null = {};

#define FL_unique_ptr std::auto_ptr
#define FL_move_ptr(x) x

Expand Down

0 comments on commit 1291ae6

Please sign in to comment.