From 97f65636884fc35ccf5a04f598991a8ddbbc34b6 Mon Sep 17 00:00:00 2001 From: scivision Date: Sat, 3 Feb 2024 20:46:56 -0500 Subject: [PATCH 1/4] ci: remove unused vars --- .github/workflows/build-linux.yml | 8 +++----- .github/workflows/build-macos.yml | 8 +++----- .github/workflows/build-win.yml | 3 +-- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.yml index f8b9b8a..711eced 100644 --- a/.github/workflows/build-linux.yml +++ b/.github/workflows/build-linux.yml @@ -15,7 +15,7 @@ jobs: c_compiler: [gcc, clang] sanitizers: [address, OFF] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set reusable strings id: strings shell: bash @@ -24,7 +24,6 @@ jobs: - name: Configure CMake 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 }} -DENABLE_TESTS=1 @@ -32,10 +31,9 @@ jobs: -DENABLE_SANITIZER=${{ matrix.sanitizers }} -S ${{ github.workspace }} - name: Build - run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} - name: Test - working-directory: ${{ steps.strings.outputs.build-output-dir }} - run: ctest --build-config ${{ matrix.build_type }} + run: ctest --ttest-dir ${{ steps.strings.outputs.build-output-dir }} - name: Coverage if: ${{ matrix.c_compiler == 'gcc' && matrix.sanitizers == 'OFF' }} working-directory: ${{ steps.strings.outputs.build-output-dir }} diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml index 7f216ec..b8b2dc5 100644 --- a/.github/workflows/build-macos.yml +++ b/.github/workflows/build-macos.yml @@ -14,7 +14,7 @@ jobs: build_type: [Release] c_compiler: [gcc, clang] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set reusable strings id: strings shell: bash @@ -23,13 +23,11 @@ jobs: - name: Configure CMake 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 }} -DENABLE_TESTS=1 -S ${{ github.workspace }} - name: Build - run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} - name: Test - working-directory: ${{ steps.strings.outputs.build-output-dir }} - run: ctest --build-config ${{ matrix.build_type }} + run: ctest --test-dir ${{ steps.strings.outputs.build-output-dir }} diff --git a/.github/workflows/build-win.yml b/.github/workflows/build-win.yml index eec9f82..7429fc4 100644 --- a/.github/workflows/build-win.yml +++ b/.github/workflows/build-win.yml @@ -14,7 +14,7 @@ jobs: build_type: [Release] c_compiler: [cl] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set reusable strings id: strings shell: bash @@ -23,7 +23,6 @@ jobs: - name: Configure CMake 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 }} -DCMAKE_C_FLAGS=/wd5105 From 5bdb3f53934c6802d094fe96a473e443d38e9b5c Mon Sep 17 00:00:00 2001 From: scivision Date: Sat, 3 Feb 2024 20:47:12 -0500 Subject: [PATCH 2/4] CMake >= 3.14 required also if() style lint for CMake --- CMakeLists.txt | 21 +++++++++++++-------- cmake/EnableWarnings.cmake | 4 ++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe15a1a..ed724b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.9.2) +cmake_minimum_required(VERSION 3.14) # set project name project(cwalk @@ -7,6 +7,11 @@ project(cwalk HOMEPAGE_URL "https://likle.github.io/cwalk/" LANGUAGES C) +option(ENABLE_COVERAGE "Coverage testing") +option(BUILD_SHARED_LIBS "Build shared library") +option(ENABLE_TESTS "Build test executables") +option(IGNORE_WARNINGS "Ignore warnings") + # include utilities list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(EnableWarnings) @@ -25,16 +30,16 @@ set(TEST_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/test") # enable coverage if requested if(ENABLE_COVERAGE) - message("-- Coverage enabled") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") + message(STATUS "Coverage enabled") + add_compile_options("$<$:-fprofile-arcs;-ftest-coverage>") + add_link_options("$<$:--coverage>") endif() # enable sanitizer if(ENABLE_SANITIZER) - message("-- Sanitizer enabled") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=${ENABLE_SANITIZER}") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-omit-frame-pointer -fsanitize=${ENABLE_SANITIZER}") + message(STATUS "Sanitizer enabled") + add_compile_options("$<$:-fno-omit-frame-pointer;-fsanitize=${ENABLE_SANITIZER}>") + add_link_options("$<$:-fno-omit-frame-pointer;-fsanitize=${ENABLE_SANITIZER}>") endif() # add the main executable @@ -56,7 +61,7 @@ endif() # enable tests if(ENABLE_TESTS) - message("-- Tests enabled") + message(STATUS "Tests enabled") enable_testing() create_test_list(DEFAULT cwalktest) diff --git a/cmake/EnableWarnings.cmake b/cmake/EnableWarnings.cmake index 772fb49..8500e66 100755 --- a/cmake/EnableWarnings.cmake +++ b/cmake/EnableWarnings.cmake @@ -6,7 +6,7 @@ function(enable_warnings target) if (NOT IGNORE_WARNINGS) target_compile_options(${target} PRIVATE /WX) endif() - elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") + elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang") target_compile_options(${target} PRIVATE -Wall) target_compile_options(${target} PRIVATE -Wextra) target_compile_options(${target} PRIVATE -Wpedantic) @@ -14,7 +14,7 @@ function(enable_warnings target) if (NOT IGNORE_WARNINGS) target_compile_options(${target} PRIVATE -Werror) endif() - elseif("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") + elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU") target_compile_options(${target} PRIVATE -Wall) target_compile_options(${target} PRIVATE -Wextra) target_compile_options(${target} PRIVATE -Wpedantic) From b212ca8942937468bb79fe60a3a7e1ca4f2fe009 Mon Sep 17 00:00:00 2001 From: scivision Date: Sat, 3 Feb 2024 20:53:16 -0500 Subject: [PATCH 3/4] cmake:enablewarnings: simplify/generalize --- cmake/EnableWarnings.cmake | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/cmake/EnableWarnings.cmake b/cmake/EnableWarnings.cmake index 8500e66..2d1dd12 100755 --- a/cmake/EnableWarnings.cmake +++ b/cmake/EnableWarnings.cmake @@ -3,23 +3,24 @@ function(enable_warnings target) if(MSVC) target_compile_definitions(${target} PRIVATE _CRT_SECURE_NO_WARNINGS) target_compile_options(${target} PRIVATE /W4) - if (NOT IGNORE_WARNINGS) - target_compile_options(${target} PRIVATE /WX) - endif() elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang") - target_compile_options(${target} PRIVATE -Wall) - target_compile_options(${target} PRIVATE -Wextra) - target_compile_options(${target} PRIVATE -Wpedantic) - target_compile_options(${target} PRIVATE -Wno-gnu-zero-variadic-macro-arguments) - if (NOT IGNORE_WARNINGS) - target_compile_options(${target} PRIVATE -Werror) - endif() + target_compile_options(${target} PRIVATE + -Wall + -Wextra + -Wpedantic + -Wno-gnu-zero-variadic-macro-arguments + ) elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU") - target_compile_options(${target} PRIVATE -Wall) - target_compile_options(${target} PRIVATE -Wextra) - target_compile_options(${target} PRIVATE -Wpedantic) - if (NOT IGNORE_WARNINGS) - target_compile_options(${target} PRIVATE -Werror) + target_compile_options(${target} PRIVATE + -Wall + -Wextra + -Wpedantic + ) + endif() + + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24") + if(NOT IGNORE_WARNINGS) + set_property(TARGET ${target} PROPERTY COMPILE_WARNING_AS_ERROR true) endif() endif() endfunction() From 081380c37428d47e727d1ee0d6ec0800b3e4e586 Mon Sep 17 00:00:00 2001 From: scivision Date: Sat, 3 Feb 2024 21:12:18 -0500 Subject: [PATCH 4/4] cmake: label tests --- cmake/CreateTestList.cmake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmake/CreateTestList.cmake b/cmake/CreateTestList.cmake index a437c8f..cbb9cad 100644 --- a/cmake/CreateTestList.cmake +++ b/cmake/CreateTestList.cmake @@ -4,12 +4,13 @@ endfunction() function(write_test_file list_name file) set("TEST_LIST_FILE_${list_name}" ${file} PARENT_SCOPE) - file(WRITE ${file} "#define UNIT_TESTS(XX) \\\n") - file(APPEND ${file} ${TEST_LIST_CONTENT_${list_name}}) - file(APPEND ${file} "\n") + file(WRITE ${file} "#define UNIT_TESTS(XX) \\ +${TEST_LIST_CONTENT_${list_name}} +") endfunction() function(create_test list_name unit_name test_name) set(TEST_LIST_CONTENT_${list_name} "${TEST_LIST_CONTENT_${list_name}} XX(${unit_name},${test_name}) \\\n" PARENT_SCOPE) add_test(NAME "${unit_name}_${test_name}" COMMAND ${TEST_LIST_TARGET_${list_name}} ${unit_name} ${test_name}) + set_property(TEST "${unit_name}_${test_name}" PROPERTY LABELS "${unit_name}") endfunction()