From cb30b2be82fd61db6fa6d28b2fb00cb5cf989ffb Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 10 Nov 2024 20:27:22 +0100 Subject: [PATCH 1/4] Add support to build on OSX with clang-18 or newer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Co-authored-by: River <26424577+wusatosi@users.noreply.github.com> --- .github/workflows/ci_tests.yml | 48 ++++++++++++++++--------------- .gitignore | 8 +++++- CMakeLists.txt | 22 +++++++++----- CMakePresets.json | 8 ++++-- src/beman/exemplar/CMakeLists.txt | 4 +-- 5 files changed, 54 insertions(+), 36 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 96a46fa..fc4ca60 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -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" @@ -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 @@ -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 diff --git a/.gitignore b/.gitignore index 286a38e..d82e612 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,8 @@ -/compile_commands.json +# +# prevent in source build! +# +/CMakeCache.txt +/CMakeFiles/ +/CMakeUserPresets.json /build +/stagedir diff --git a/CMakeLists.txt b/CMakeLists.txt index fff30fb..8509837 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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() @@ -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() diff --git a/CMakePresets.json b/CMakePresets.json index ede9472..95a7727 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -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" } }, { @@ -56,7 +56,11 @@ }, { "name": "gcc-release", - "configurePreset": "gcc-release" + "configurePreset": "gcc-release", + "targets": [ + "all_verify_interface_header_sets", + "all" + ] } ], "testPresets": [ diff --git a/src/beman/exemplar/CMakeLists.txt b/src/beman/exemplar/CMakeLists.txt index edee25c..4747b3c 100644 --- a/src/beman/exemplar/CMakeLists.txt +++ b/src/beman/exemplar/CMakeLists.txt @@ -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 From 3cb30e866a82cd04d268b48ab3d089fa04a7e29d Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 10 Nov 2024 21:01:07 +0100 Subject: [PATCH 2/4] Quickfix --- .github/workflows/ci_tests.yml | 5 +++-- CMakePresets.json | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index fc4ca60..974aeb0 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -41,8 +41,9 @@ jobs: cmake_args: - description: "Default" args: "" - - description: "TSan" - args: "-DCMAKE_CXX_FLAGS=-fsanitize=thread" + # FIXME: find a better solution to be usable for multible OS builds on CI! CK + # - description: "TSan" + # args: "-DCMAKE_CXX_FLAGS=-fsanitize=thread" - description: "ASan" args: "-DCMAKE_CXX_FLAGS='-fsanitize=address -fsanitize=undefined'" include: diff --git a/CMakePresets.json b/CMakePresets.json index 95a7727..d12c505 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -52,7 +52,11 @@ "buildPresets": [ { "name": "gcc-debug", - "configurePreset": "gcc-debug" + "configurePreset": "gcc-debug", + "targets": [ + "all_verify_interface_header_sets", + "all" + ] }, { "name": "gcc-release", From 4c36c5988d187aebb96dbcabbab1679633a82fdd Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 10 Nov 2024 21:07:28 +0100 Subject: [PATCH 3/4] Add more FIXME notes --- .github/workflows/ci_tests.yml | 4 ++-- CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 974aeb0..9437e9f 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -44,8 +44,8 @@ jobs: # FIXME: find a better solution to be usable for multible OS builds on CI! CK # - description: "TSan" # args: "-DCMAKE_CXX_FLAGS=-fsanitize=thread" - - description: "ASan" - args: "-DCMAKE_CXX_FLAGS='-fsanitize=address -fsanitize=undefined'" + # - description: "ASan" + # args: "-DCMAKE_CXX_FLAGS='-fsanitize=address -fsanitize=undefined'" include: - platform: ubuntu-22.04 compiler: diff --git a/CMakeLists.txt b/CMakeLists.txt index 8509837..70da7da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ if(BUILD_TESTING) 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! + set(CMAKE_CXX_FLAGS) # FIXME: Do not propagate our project settings! CK FetchContent_MakeAvailable(googletest) endblock() From 4cc47f35b569662308ae1b5a0764fd7dd92612a9 Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Tue, 12 Nov 2024 20:43:39 +0100 Subject: [PATCH 4/4] Revert my workaround and notes --- .github/workflows/ci_tests.yml | 17 ++++++++--------- CMakeLists.txt | 1 - 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 9437e9f..0b90624 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -41,11 +41,10 @@ jobs: cmake_args: - description: "Default" args: "" - # FIXME: find a better solution to be usable for multible OS builds on CI! CK - # - description: "TSan" - # args: "-DCMAKE_CXX_FLAGS=-fsanitize=thread" - # - description: "ASan" - # args: "-DCMAKE_CXX_FLAGS='-fsanitize=address -fsanitize=undefined'" + - description: "TSan" + args: "-DCMAKE_CXX_FLAGS=-fsanitize=thread" + - description: "ASan" + args: "-DCMAKE_CXX_FLAGS='-fsanitize=address -fsanitize=undefined'" include: - platform: ubuntu-22.04 compiler: @@ -92,16 +91,16 @@ jobs: run: | cmake --build build --config Release --verbose cmake --build build --config Release --target all_verify_interface_header_sets - cmake --install build --config Release --prefix /tmp/beman.exemplar - find /tmp/beman.exemplar -type f + 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 /tmp/beman.exemplar - find /tmp/beman.exemplar -type f + 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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 70da7da..6283d14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,6 @@ if(BUILD_TESTING) 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 propagate our project settings! CK FetchContent_MakeAvailable(googletest) endblock()