Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support macos builds #66

Closed
Closed
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
48 changes: 25 additions & 23 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,31 @@ jobs:
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest]
platform: [ubuntu-24.04, macos-15]
compiler:
- cpp: g++
c: gcc
- cpp: clang++
c: clang
- cpp: g++-14
c: gcc-14
- cpp: clang++-18
c: clang-18
cpp_version: [17, 20, 23, 26]
ClausKlein marked this conversation as resolved.
Show resolved Hide resolved
cmake_args:
- description: "Default"
args: ""
- description: "TSan"
args: "-DCMAKE_CXX_FLAGS=-fsanitize=thread"
args: "-DCMAKE_CXX_FLAGS=-fsanitize=thread"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
args: "-DCMAKE_CXX_FLAGS=-fsanitize=thread"
args: "-DCMAKE_CXX_FLAGS=-fsanitize=thread"

- description: "ASan"
args: "-DCMAKE_CXX_FLAGS='-fsanitize=address -fsanitize=undefined'"
args: "-DCMAKE_CXX_FLAGS='-fsanitize=address -fsanitize=undefined'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
args: "-DCMAKE_CXX_FLAGS='-fsanitize=address -fsanitize=undefined'"
args: "-DCMAKE_CXX_FLAGS='-fsanitize=address -fsanitize=undefined'"

include:
- platform: ubuntu-latest
- platform: ubuntu-22.04
compiler:
cpp: g++
c: gcc
cpp_version: 17
cmake_args:
description: "Werror"
args: "-DCMAKE_CXX_FLAGS='-Werror=all -Werror=extra'"
- platform: ubuntu-latest
compiler:
cpp: g++
c: gcc
cpp_version: 17
cmake_args:
description: "Dynamic"
args: "-DBUILD_SHARED_LIBS=on"
- description: "Werror"
args: "-DCMAKE_CXX_FLAGS='-Werror=all -Werror=extra'"

name: "Bulid & Test: ${{ matrix.compiler.c }} ${{ matrix.cpp_version }} ${{ matrix.cmake_args.description }}"
name: "${{ matrix.platform }}: ${{ matrix.compiler.c }} ${{ matrix.cpp_version }} ${{ matrix.cmake_args.description }}"
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
Expand All @@ -74,30 +66,40 @@ jobs:
ninjaVersion: "^1.11.1"
- name: Print installed softwares
run: |
wusatosi marked this conversation as resolved.
Show resolved Hide resolved
clang++ --version
g++ --version
${{ matrix.compiler.cpp }} --version || echo ignored
${{ matrix.compiler.c }} --version || echo ignored
cmake --version
ninja --version

- name: Configure CMake on macos with clang
if: startsWith(matrix.compiler.c, 'clang') && startsWith(matrix.platform, 'macos')
run: |
CC=$(brew --prefix llvm@18)/bin/clang CXX=$(brew --prefix llvm@18)/bin/clang++ cmake -B build -S . -DCMAKE_CXX_STANDARD=${{ matrix.cpp_version }} ${{ matrix.cmake_args.args }}
env:
CMAKE_GENERATOR: "Ninja Multi-Config"

- name: Configure CMake
if: ( startsWith(matrix.compiler.c, 'gcc') || startsWith(matrix.platform, 'ubuntu') ) || ( startsWith(matrix.compiler.c, 'gcc') && startsWith(matrix.platform, 'macos') )
run: |
cmake -B build -S . -DCMAKE_CXX_STANDARD=${{ matrix.cpp_version }} ${{ matrix.cmake_args.args }}
env:
CC: ${{ matrix.compiler.c }}
CXX: ${{ matrix.compiler.cpp }}
CMAKE_GENERATOR: "Ninja Multi-Config"

- name: Build Release
run: |
cmake --build build --config Release --verbose
cmake --build build --config Release --target all_verify_interface_header_sets
cmake --install build --config Release --prefix /opt/beman.exemplar
sudo cmake --install build --config Release --prefix /opt/beman.exemplar
find /opt/beman.exemplar -type f
- name: Test Release
run: ctest --test-dir build --build-config Release
- name: Build Debug
run: |
cmake --build build --config Debug --verbose
cmake --build build --config Debug --target all_verify_interface_header_sets
cmake --install build --config Debug --prefix /opt/beman.exemplar
sudo cmake --install build --config Debug --prefix /opt/beman.exemplar
find /opt/beman.exemplar -type f
- name: Test Debug
run: ctest --test-dir build --build-config Debug
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
ClausKlein marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
/compile_commands.json
#
# prevent in source build!
#
/CMakeCache.txt
/CMakeFiles/
/CMakeUserPresets.json
/build
/stagedir
21 changes: 14 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

cmake_minimum_required(VERSION 3.25)
cmake_minimum_required(VERSION 3.25...3.31)

project(
beman.exemplar # CMake Project Name, which is also the name of the top-level
Expand All @@ -9,9 +9,17 @@ project(
LANGUAGES CXX
)

include(CTest)
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "In-source builds are not allowed!")
endif()

include(CPack)
ClausKlein marked this conversation as resolved.
Show resolved Hide resolved
include(FetchContent)
include(GNUInstallDirs)

add_subdirectory(src/beman/exemplar)

option(BUILD_TESTING "build tests too" ${PROJECT_IS_TOP_LEVEL})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recommended pattern for options is to include the name of the project, so that projects can compose. Defaulting to is top level is the right thing, but we wouldn't want to build the tests of beman_interface if we included that.
Was going to come back to fix, but if we're touching this, might as well.

This comment was marked as resolved.

if(BUILD_TESTING)
enable_testing()

Expand All @@ -26,14 +34,13 @@ if(BUILD_TESTING)
block()
set(INSTALL_GTEST OFF) # Disable GoogleTest installation
set(BUILD_TESTING OFF) # Disable GoogleTest tests
set(BUILD_GMOCK OFF)
FetchContent_MakeAvailable(googletest)
endblock()
endif()

add_subdirectory(src/beman/exemplar)

if(BUILD_TESTING)
add_subdirectory(tests/beman/exemplar)
endif()

add_subdirectory(examples)
if(PROJECT_IS_TOP_LEVEL)
add_subdirectory(examples)
endif()
14 changes: 11 additions & 3 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_CXX_FLAGS": "-fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=leak -fsanitize=undefined"
"CMAKE_CXX_FLAGS": "-fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=undefined"
ClausKlein marked this conversation as resolved.
Show resolved Hide resolved
}
},
{
Expand Down Expand Up @@ -52,11 +52,19 @@
"buildPresets": [
{
"name": "gcc-debug",
"configurePreset": "gcc-debug"
"configurePreset": "gcc-debug",
"targets": [
"all_verify_interface_header_sets",
"all"
]
},
{
"name": "gcc-release",
"configurePreset": "gcc-release"
"configurePreset": "gcc-release",
"targets": [
"all_verify_interface_header_sets",
"all"
]
ClausKlein marked this conversation as resolved.
Show resolved Hide resolved
}
],
"testPresets": [
Expand Down
4 changes: 1 addition & 3 deletions src/beman/exemplar/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

add_library(beman.exemplar STATIC)
add_library(beman.exemplar INTERFACE)
ClausKlein marked this conversation as resolved.
Show resolved Hide resolved
add_library(beman::exemplar ALIAS beman.exemplar)

target_sources(beman.exemplar PRIVATE identity.cpp)

target_sources(
beman.exemplar
PUBLIC
Expand Down
Loading