Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 68 additions & 25 deletions .github/workflows/ci_pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
std: [14, 20, 23]
compiler: [gcc, clang]
compiler: [gcc, clang, msvc]
exclude:
# macOS: Apple Clang only
# Linux: [gcc, clang]
- os: ubuntu-latest
compiler: msvc
# MacOS: [clang]
- os: macos-latest
compiler: gcc
# Windows: use MSVC only
- os: macos-latest
compiler: msvc

# Windows: [msvc]
- os: windows-latest
compiler: gcc
- os: windows-latest
Expand All @@ -30,10 +36,12 @@ jobs:
- uses: actions/checkout@v4
- uses: seanmiddleditch/gha-setup-ninja@v5

- name: Setup compiler
- name: Setup compiler (Linux/macOS)
if: runner.os != 'Windows'
shell: bash
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
if [[ "${{ matrix.compiler }}" == "gcc" ]]; then
if [ "${{ runner.os }}" = "Linux" ]; then
if [ "${{ matrix.compiler }}" = "gcc" ]; then
sudo apt update -y
sudo apt install -y g++-11
echo "CXX=g++-11" >> $GITHUB_ENV
Expand All @@ -42,50 +50,85 @@ jobs:
sudo apt install -y clang-15
echo "CXX=clang++-15" >> $GITHUB_ENV
fi
elif [[ "${{ runner.os }}" == "macOS" ]]; then
# Apple Clang is preinstalled and modern (LLVM-based)
echo "CXX=clang++" >> $GITHUB_ENV
else
# Windows automatically uses MSVC via CMake
echo "Using MSVC on Windows"
echo "CXX=clang++" >> $GITHUB_ENV
fi

- name: Print compiler info
if: runner.os != 'Windows'
shell: bash
run: |
cmake --version
if [[ "${{ runner.os }}" == "Windows" ]]; then
cl
else
$CXX --version
fi
$CXX --version

- name: Configure
if: runner.os != 'Windows'
shell: bash
run: |
if [[ "${{ matrix.compiler }}" == "gcc" ]]; then
if [ "${{ matrix.compiler }}" = "gcc" ]; then
CMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic -Werror -Wno-array-bounds"
else
CMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic -Werror"
fi
cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=${{ matrix.std }} \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DBUILD_TESTING=ON \
-DEXAMPLES=ON \
-DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS"
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=${{ matrix.std }} \
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
-DBUILD_TESTING=ON \
-DEXAMPLES=ON \
-DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS"

- name: Build
if: runner.os != 'Windows'
shell: bash
run: cmake --build build --parallel

- name: Run tests
if: runner.os != 'Windows'
shell: bash
run: ctest --test-dir build --output-on-failure

- name: Run examples
- name: Run examples (Linux only)
if: runner.os == 'Linux'
shell: bash
run: |
if [ -d build/examples ]; then
echo "Running examples..."
find build/examples -maxdepth 1 -type f -executable -print -exec {} \;
else
echo "No examples directory found."
fi
fi

- name: Setup MSVC
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1

- name: Print compiler info (MSVC)
if: runner.os == 'Windows'
shell: cmd
run: |
cmake --version
cl

- name: Configure (MSVC)
if: runner.os == 'Windows'
shell: cmd
run: |
cmake -S . -B build -G "Ninja" ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_CXX_STANDARD=${{ matrix.std }} ^
-DCMAKE_CXX_STANDARD_REQUIRED=ON ^
-DBUILD_TESTING=ON ^
-DEXAMPLES=ON ^
-DCMAKE_CXX_FLAGS="/W4 /WX /EHsc"

- name: Build (MSVC)
if: runner.os == 'Windows'
shell: cmd
run: cmake --build build --parallel

- name: Run tests (MSVC)
if: runner.os == 'Windows'
shell: cmd
run: ctest --test-dir build --output-on-failure

18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ include(GNUInstallDirs)
set(library_name accessor)
add_library(${library_name} INTERFACE)
target_include_directories(${library_name} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

install(TARGETS accessor EXPORT ${library_name}Config
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) # For Windows
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) # For Windows

install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp*")
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp*")

install(EXPORT ${library_name}Config DESTINATION share/${library_name}/cmake)

Expand All @@ -28,15 +28,19 @@ if(${EXAMPLES})

add_executable(accessFunctions examples/access_function.cpp)
target_link_libraries(accessFunctions accessor)
set_target_properties(accessFunctions PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)

add_executable(accessMembers examples/access_member.cpp)
target_link_libraries(accessMembers accessor)
set_target_properties(accessMembers PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)

add_executable(accessColletion examples/multiple_instances.cpp)
target_link_libraries(accessColletion accessor)
set_target_properties(accessColletion PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)

add_executable(accessNoMacro examples/no_macro.cpp)
target_link_libraries(accessNoMacro accessor)
set_target_properties(accessNoMacro PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples)
endif()

#TESTS
Expand Down