Skip to content

Commit

Permalink
Add support to build on OSX with clang-18 or newer
Browse files Browse the repository at this point in the history
This is an interface library (header only)

Prevent in source build

Fix macos CI build

Use all_verify_interface_header_sets on CI too.

Co-authored-by: Darius Neațu <[email protected]>

Co-authored-by: River <[email protected]>
  • Loading branch information
ClausKlein and wusatosi committed Nov 10, 2024
1 parent 2393743 commit cb30b2b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 36 deletions.
48 changes: 25 additions & 23 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ 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]
cmake_args:
- description: "Default"
Expand All @@ -46,24 +46,16 @@ jobs:
- description: "ASan"
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,31 +66,41 @@ jobs:
ninjaVersion: "^1.11.1"
- name: Print installed softwares
run: |
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
find /opt/beman.exemplar -type f
cmake --install build --config Release --prefix /tmp/beman.exemplar
find /tmp/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
find /opt/beman.exemplar -type f
cmake --install build --config Debug --prefix /tmp/beman.exemplar
find /tmp/beman.exemplar -type f
- name: Test Debug
run: ctest --test-dir build --build-config Debug

Expand Down
8 changes: 7 additions & 1 deletion .gitignore
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
22 changes: 15 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)
include(FetchContent)
include(GNUInstallDirs)

add_subdirectory(src/beman/exemplar)

option(BUILD_TESTING "build tests too" ${PROJECT_IS_TOP_LEVEL})
if(BUILD_TESTING)
enable_testing()

Expand All @@ -26,14 +34,14 @@ if(BUILD_TESTING)
block()
set(INSTALL_GTEST OFF) # Disable GoogleTest installation
set(BUILD_TESTING OFF) # Disable GoogleTest tests
set(BUILD_GMOCK OFF)
set(CMAKE_CXX_FLAGS) # FIXME: Do not use our project settings!
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()
8 changes: 6 additions & 2 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"
}
},
{
Expand Down Expand Up @@ -56,7 +56,11 @@
},
{
"name": "gcc-release",
"configurePreset": "gcc-release"
"configurePreset": "gcc-release",
"targets": [
"all_verify_interface_header_sets",
"all"
]
}
],
"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)
add_library(beman::exemplar ALIAS beman.exemplar)

target_sources(beman.exemplar PRIVATE identity.cpp)

target_sources(
beman.exemplar
PUBLIC
Expand Down

0 comments on commit cb30b2b

Please sign in to comment.