diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml
new file mode 100644
index 0000000..e0b569f
--- /dev/null
+++ b/.github/workflows/cmake-multi-platform.yml
@@ -0,0 +1,68 @@
+name: CMake on multiple platforms
+
+on:
+ push:
+ branches: [ "master" ]
+ pull_request:
+ branches: [ "master" ]
+
+jobs:
+ build:
+ runs-on: ${{ matrix.os }}
+
+ strategy:
+ # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
+ fail-fast: false
+
+ # Set up a matrix to run the following 3 configurations:
+ matrix:
+ os: [ubuntu-latest, windows-latest]
+ build_type: [Release]
+ c_compiler: [gcc, clang, cl]
+ include:
+ - os: windows-latest
+ c_compiler: cl
+ cpp_compiler: cl
+ - os: ubuntu-latest
+ c_compiler: gcc
+ cpp_compiler: g++
+ - os: ubuntu-latest
+ c_compiler: clang
+ cpp_compiler: clang++
+ exclude:
+ - os: windows-latest
+ c_compiler: gcc
+ - os: windows-latest
+ c_compiler: clang
+ - os: ubuntu-latest
+ c_compiler: cl
+
+ steps:
+ - uses: actions/checkout@v4
+
+ - name: Set reusable strings
+ # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
+ id: strings
+ shell: bash
+ run: |
+ echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
+
+ - name: Configure CMake
+ # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
+ # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
+ # Building with `SORTING_NETWORK_CPP_BUILD_BENCHMARK=ON` to ensure that the benchmarks can be built
+ run: >
+ cmake -B ${{ steps.strings.outputs.build-output-dir }}
+ -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
+ -DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
+ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
+ -DSORTING_NETWORK_CPP_BUILD_TESTS=ON
+ -DSORTING_NETWORK_CPP_BUILD_BENCHMARK=ON
+ -S ${{ github.workspace }}
+
+ - name: Build
+ run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --parallel
+
+ - name: Test
+ working-directory: ${{ steps.strings.outputs.build-output-dir }}
+ run: ctest --build-config ${{ matrix.build_type }}
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e820e05..5858731 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -48,6 +48,10 @@ if(SORTING_NETWORK_CPP_BUILD_TESTS)
CPMAddPackage("gh:brunocodutra/metal#v2.1.4")
CPMAddPackage("gh:google/googletest#release-1.12.0")
+ include(GoogleTest)
+
+ enable_testing()
+
set(SN_TESTS_EXECUTABLE_NAME ${PROJECT_NAME}_tests)
add_executable(${SN_TESTS_EXECUTABLE_NAME}
@@ -60,4 +64,5 @@ if(SORTING_NETWORK_CPP_BUILD_TESTS)
"test/test_size_optimized_sort.cpp"
)
target_link_libraries(${SN_TESTS_EXECUTABLE_NAME} GTest::gtest GTest::gmock GTest::gtest_main Metal project_options sorting_network_cpp)
+ gtest_discover_tests(${SN_TESTS_EXECUTABLE_NAME})
endif()
diff --git a/src/util.h b/src/util.h
index 47e627a..c932d65 100644
--- a/src/util.h
+++ b/src/util.h
@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
+#include
#include
#include
#include
@@ -101,9 +102,9 @@ namespace quxflux
}
template
- constexpr std::string_view to_string()
+ std::string_view to_string()
{
- static std::unordered_map name_map{
+ const std::unordered_map name_map{
std::pair{std::type_index(typeid(int16_t)), "int16_t"}, //
std::pair{std::type_index(typeid(int32_t)), "int32_t"}, //
std::pair{std::type_index(typeid(int64_t)), "int64_t"}, //
@@ -121,11 +122,11 @@ namespace quxflux
}
template
- constexpr std::string_view to_string()
+ std::string_view to_string()
{
using SN = quxflux::sorting_net::type;
- static std::unordered_map name_map{
+ const std::unordered_map name_map{
std::pair{SN::bubble_sort, "SN::bubble_sort"}, //
std::pair{SN::insertion_sort, "SN::insertion_sort"}, //
std::pair{SN::batcher_odd_even_merge_sort, "SN::batcher_odd_even_merge_sort"}, //
@@ -237,16 +238,16 @@ namespace quxflux
#define IMPL_BENCHMARK(T) \
template<> \
- void detail::benchmark_impl<##T>::operator()(std::set& benchmark_results) const \
+ void detail::benchmark_impl::operator()(std::set& benchmark_results) const \
{ \
- benchmark_all_with_size_and_type<1, ##T>(benchmark_results); \
- benchmark_all_with_size_and_type<2, ##T>(benchmark_results); \
- benchmark_all_with_size_and_type<4, ##T>(benchmark_results); \
- benchmark_all_with_size_and_type<8, ##T>(benchmark_results); \
- benchmark_all_with_size_and_type<16, ##T>(benchmark_results); \
- benchmark_all_with_size_and_type<32, ##T>(benchmark_results); \
- benchmark_all_with_size_and_type<64, ##T>(benchmark_results); \
- benchmark_all_with_size_and_type<128, ##T>(benchmark_results); \
+ benchmark_all_with_size_and_type<1, T>(benchmark_results); \
+ benchmark_all_with_size_and_type<2, T>(benchmark_results); \
+ benchmark_all_with_size_and_type<4, T>(benchmark_results); \
+ benchmark_all_with_size_and_type<8, T>(benchmark_results); \
+ benchmark_all_with_size_and_type<16, T>(benchmark_results); \
+ benchmark_all_with_size_and_type<32, T>(benchmark_results); \
+ benchmark_all_with_size_and_type<64, T>(benchmark_results); \
+ benchmark_all_with_size_and_type<128, T>(benchmark_results); \
\
std::clog << '\n'; \
} \