Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: Test compilation as C++20 on CI
Browse files Browse the repository at this point in the history
fastgltf uses many features of C++20 conditionally, and this now adds CI tests to verify their usage
spnda committed Feb 1, 2024
1 parent 4f4370f commit f705c05
Showing 5 changed files with 30 additions and 10 deletions.
19 changes: 13 additions & 6 deletions .github/workflows/ci_x64.yml
Original file line number Diff line number Diff line change
@@ -17,6 +17,9 @@ env:

jobs:
build_windows:
strategy:
matrix:
cpp20: [NO, YES]
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
@@ -38,13 +41,13 @@ jobs:
run: git clone https://github.com/KhronosGroup/glTF-Sample-Models ${{ github.workspace }}/${{ env.SAMPLE_MODELS_LOCATION }}

- name: Configure CMake
run: cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DFASTGLTF_ENABLE_TESTS=ON
run: cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DFASTGLTF_ENABLE_TESTS=ON -DFASTGLTF_COMPILE_AS_CPP20=${{ matrix.cpp20 }}

- name: Build (Windows)
run: cmake --build ${{ github.workspace }}/build --config ${{ env.BUILD_TYPE }} --target tests/fastgltf_tests --verbose

- name: Run tests
run: ${{ github.workspace }}\build\tests\Release\fastgltf_tests.exe -d yes --order lex [base64],[gltf-loader],[gltf-tools],[uri-tests],[vector-tests]
run: ${{ github.workspace }}\build\tests\Release\fastgltf_tests.exe -d yes --order lex ~[gltf-benchmark]

build_windows_deprecated_extensions:
runs-on: windows-latest
@@ -74,12 +77,16 @@ jobs:
run: cmake --build ${{ github.workspace }}/build --config ${{ env.BUILD_TYPE }} --target tests/fastgltf_tests --verbose

- name: Run tests
run: ${{ github.workspace }}\build\tests\Release\fastgltf_tests.exe -d yes --order lex [base64],[gltf-loader],[gltf-tools],[uri-tests],[vector-tests]
run: ${{ github.workspace }}\build\tests\Release\fastgltf_tests.exe -d yes --order lex ~[gltf-benchmark]

build_linux:
strategy:
matrix:
c_compiler: [gcc-9, gcc-10, clang-13]
cpp20: [NO, YES]
exclude:
- c_compiler: gcc-9
cpp20: YES
include:
- cxx_compiler: g++-9
c_compiler: gcc-9
@@ -116,13 +123,13 @@ jobs:
run: sudo apt-get install -y libxrandr-dev libxinerama-dev libx11-dev libxcursor-dev libxi-dev

- name: Configure CMake
run: cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DFASTGLTF_ENABLE_TESTS=ON
run: cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }} -DFASTGLTF_ENABLE_TESTS=ON -DFASTGLTF_COMPILE_AS_CPP20=${{ matrix.cpp20 }}

- name: Build
run: cmake --build ${{ github.workspace }}/build --config ${{ env.BUILD_TYPE }} --target fastgltf_tests --verbose

- name: Run tests
run: ${{ github.workspace }}/build/tests/fastgltf_tests -d yes --order lex [base64],[gltf-loader],[gltf-tools],[uri-tests],[vector-tests]
run: ${{ github.workspace }}/build/tests/fastgltf_tests -d yes --order lex ~[gltf-benchmark]

build_linux_deprecated_extensions:
strategy:
@@ -170,4 +177,4 @@ jobs:
run: cmake --build ${{ github.workspace }}/build --config ${{ env.BUILD_TYPE }} --target fastgltf_tests --verbose

- name: Run tests
run: ${{ github.workspace }}/build/tests/fastgltf_tests -d yes --order lex [base64],[gltf-loader],[gltf-tools],[uri-tests],[vector-tests]
run: ${{ github.workspace }}/build/tests/fastgltf_tests -d yes --order lex ~[gltf-benchmark]
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -17,6 +17,13 @@ option(FASTGLTF_ENABLE_ASSIMP "Enables the benchmark usage of assimp" OFF)
option(FASTGLTF_ENABLE_DEPRECATED_EXT "Enables support for deprecated extensions" OFF)
option(FASTGLTF_DISABLE_CUSTOM_MEMORY_POOL "Disables the memory allocation algorithm based on polymorphic resources" OFF)
option(FASTGLTF_USE_64BIT_FLOAT "Default to 64-bit double precision floats for everything" OFF)
option(FASTGLTF_COMPILE_AS_CPP20 "Have the library compile as C++20" OFF)

if (FASTGLTF_COMPILE_AS_CPP20)
set(FASTGLTF_COMPILE_TARGET cxx_std_20)
else()
set(FASTGLTF_COMPILE_TARGET cxx_std_17)
endif()

include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/add_source_directory.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/compiler_flags.cmake)
@@ -29,7 +36,7 @@ add_library(fastgltf::fastgltf ALIAS fastgltf)

fastgltf_compiler_flags(fastgltf)
fastgltf_enable_debug_inlining(fastgltf)
target_compile_features(fastgltf PUBLIC cxx_std_17)
target_compile_features(fastgltf PUBLIC ${FASTGLTF_COMPILE_TARGET})
target_include_directories(fastgltf PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include> $<INSTALL_INTERFACE:include>)

set_target_properties(fastgltf PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS YES)
6 changes: 6 additions & 0 deletions docs/options.rst
Original file line number Diff line number Diff line change
@@ -73,6 +73,12 @@ When this ``BOOL`` option is set to ``YES`` fastgltf will use `corrosion`_, whic
to link against the `gltf-rs`_ Rust library for comparison within the benchmarks.
Note that this option has no effect when ``FASTGLTF_ENABLE_TESTS`` is set to ``NO``.

``FASTGLTF_COMPILE_AS_CPP20``
-----------------------------

This ``BOOL`` option controls the C++ standard the library is compiled as. When ``NO`` fastgltf is always compiled as C++17.
When ``YES`` fastgltf is compiled as C++20, including the tests.


Parsing options
===============
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL TRUE)
add_executable(fastgltf_tests EXCLUDE_FROM_ALL
"base64_tests.cpp" "basic_test.cpp" "benchmarks.cpp" "glb_tests.cpp" "gltf_path.hpp"
"vector_tests.cpp" "uri_tests.cpp" "extension_tests.cpp" "accessor_tests.cpp" "write_tests.cpp")
target_compile_features(fastgltf_tests PRIVATE cxx_std_17)
target_compile_features(fastgltf_tests PRIVATE ${FASTGLTF_COMPILE_TARGET})
target_link_libraries(fastgltf_tests PRIVATE fastgltf)
target_link_libraries(fastgltf_tests PRIVATE glm::glm Catch2::Catch2WithMain)
fastgltf_compiler_flags(fastgltf_tests)
4 changes: 2 additions & 2 deletions tests/basic_test.cpp
Original file line number Diff line number Diff line change
@@ -578,9 +578,9 @@ TEST_CASE("Test unicode characters", "[gltf-loader]") {
REQUIRE(fastgltf::validate(asset.get()) == fastgltf::Error::None);

REQUIRE(!asset->materials.empty());
REQUIRE(asset->materials[0].name == u8"Unicode❤♻Material");
REQUIRE(asset->materials[0].name == reinterpret_cast<const char*>(u8"Unicode❤♻Material"));

REQUIRE(!asset->buffers.empty());
auto bufferUri = std::get<fastgltf::sources::URI>(asset->buffers[0].data);
REQUIRE(bufferUri.uri.path() == u8"Unicode❤♻Binary.bin");
REQUIRE(bufferUri.uri.path() == reinterpret_cast<const char*>(u8"Unicode❤♻Binary.bin"));
}

0 comments on commit f705c05

Please sign in to comment.