Skip to content

Commit

Permalink
Add an option to control -Werror, addresses #107
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy-rifkin committed Dec 4, 2024
1 parent 2f5b014 commit e47aff4
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 27 deletions.
10 changes: 7 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ jobs:
cmake .. \
-DCMAKE_BUILD_TYPE=${{matrix.target}} \
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} \
-DLIBASSERT_DESIRED_CXX_STANDARD="${{matrix.cxx_version}}"
-DLIBASSERT_DESIRED_CXX_STANDARD="${{matrix.cxx_version}}" \
-DLIBASSERT_WERROR_BUILD=On
make -j
build-macos:
runs-on: macos-14
Expand All @@ -44,7 +45,8 @@ jobs:
cmake .. \
-DCMAKE_BUILD_TYPE=${{matrix.target}} \
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} \
-DLIBASSERT_DESIRED_CXX_STANDARD="${{matrix.cxx_version}}"
-DLIBASSERT_DESIRED_CXX_STANDARD="${{matrix.cxx_version}}" \
-DLIBASSERT_WERROR_BUILD=On
make -j
build-windows:
runs-on: windows-2022
Expand All @@ -65,7 +67,8 @@ jobs:
cmake .. `
-DCMAKE_BUILD_TYPE=${{matrix.target}} `
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} `
-DLIBASSERT_DESIRED_CXX_STANDARD="${{matrix.cxx_version}}"
-DLIBASSERT_DESIRED_CXX_STANDARD="${{matrix.cxx_version}}" \
-DLIBASSERT_WERROR_BUILD=On
msbuild .\libassert.sln
build-mingw:
runs-on: windows-2022
Expand All @@ -87,5 +90,6 @@ jobs:
-DCMAKE_BUILD_TYPE=${{matrix.target}} `
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} `
-DLIBASSERT_DESIRED_CXX_STANDARD="${{matrix.cxx_version}}" `
-DLIBASSERT_WERROR_BUILD=On `
"-GUnix Makefiles"
make -j
24 changes: 12 additions & 12 deletions .github/workflows/cmake-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
cp -rv libassert/tests/fetchcontent-integration .
mkdir fetchcontent-integration/build
cd fetchcontent-integration/build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DLIBASSERT_TAG=$tag
cmake .. -DCMAKE_BUILD_TYPE=Debug -DLIBASSERT_TAG=$tag -DLIBASSERT_WERROR_BUILD=On
make
./main
test-linux-findpackage:
Expand All @@ -28,7 +28,7 @@ jobs:
tag=$(git rev-parse --abbrev-ref HEAD)
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake .. -DCMAKE_BUILD_TYPE=Debug -DLIBASSERT_WERROR_BUILD=On
sudo make -j install
sudo /sbin/ldconfig
cd ../..
Expand All @@ -49,7 +49,7 @@ jobs:
cp -rv libassert add_subdirectory-integration
mkdir add_subdirectory-integration/build
cd add_subdirectory-integration/build
cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake .. -DCMAKE_BUILD_TYPE=Debug -DLIBASSERT_WERROR_BUILD=On
make
./main
Expand All @@ -64,7 +64,7 @@ jobs:
cp -rv libassert/tests/fetchcontent-integration .
mkdir fetchcontent-integration/build
cd fetchcontent-integration/build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DLIBASSERT_TAG=$tag
cmake .. -DCMAKE_BUILD_TYPE=Debug -DLIBASSERT_TAG=$tag -DLIBASSERT_WERROR_BUILD=On
make
./main
test-macos-findpackage:
Expand All @@ -76,7 +76,7 @@ jobs:
tag=$(git rev-parse --abbrev-ref HEAD)
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake .. -DCMAKE_BUILD_TYPE=Debug -DLIBASSERT_WERROR_BUILD=On
sudo make -j install
cd ../..
cp -rv libassert/tests/findpackage-integration .
Expand All @@ -96,7 +96,7 @@ jobs:
cp -rv libassert add_subdirectory-integration
mkdir add_subdirectory-integration/build
cd add_subdirectory-integration/build
cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake .. -DCMAKE_BUILD_TYPE=Debug -DLIBASSERT_WERROR_BUILD=On
make
./main
Expand All @@ -111,7 +111,7 @@ jobs:
cp -Recurse libassert/tests/fetchcontent-integration .
mkdir fetchcontent-integration/build
cd fetchcontent-integration/build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DLIBASSERT_TAG="$tag" "-GUnix Makefiles"
cmake .. -DCMAKE_BUILD_TYPE=Debug -DLIBASSERT_TAG="$tag" "-GUnix Makefiles" -DLIBASSERT_WERROR_BUILD=On
make
.\main.exe
test-mingw-findpackage:
Expand All @@ -123,7 +123,7 @@ jobs:
$tag=$(git rev-parse --abbrev-ref HEAD)
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug "-GUnix Makefiles" -DCMAKE_INSTALL_PREFIX=C:/foo
cmake .. -DCMAKE_BUILD_TYPE=Debug "-GUnix Makefiles" -DCMAKE_INSTALL_PREFIX=C:/foo -DLIBASSERT_WERROR_BUILD=On
make -j install
cd ../..
cp -Recurse libassert/tests/findpackage-integration .
Expand All @@ -143,7 +143,7 @@ jobs:
cp -Recurse libassert add_subdirectory-integration
mkdir add_subdirectory-integration/build
cd add_subdirectory-integration/build
cmake .. -DCMAKE_BUILD_TYPE=Debug "-GUnix Makefiles"
cmake .. -DCMAKE_BUILD_TYPE=Debug "-GUnix Makefiles" -DLIBASSERT_WERROR_BUILD=On
make
.\main.exe
test-windows-fetchcontent:
Expand All @@ -159,7 +159,7 @@ jobs:
cp -Recurse libassert/tests/fetchcontent-integration .
mkdir fetchcontent-integration/build
cd fetchcontent-integration/build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DLIBASSERT_TAG="$tag"
cmake .. -DCMAKE_BUILD_TYPE=Debug -DLIBASSERT_TAG="$tag" -DLIBASSERT_WERROR_BUILD=On
msbuild demo_project.sln
.\Debug\main.exe
test-windows-findpackage:
Expand All @@ -173,7 +173,7 @@ jobs:
$tag=$(git rev-parse --abbrev-ref HEAD)
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=C:/foo
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=C:/foo -DLIBASSERT_WERROR_BUILD=On
msbuild .\libassert.sln
msbuild INSTALL.vcxproj
cd ../..
Expand All @@ -196,6 +196,6 @@ jobs:
cp -Recurse libassert add_subdirectory-integration
mkdir add_subdirectory-integration/build
cd add_subdirectory-integration/build
cmake .. -DCMAKE_BUILD_TYPE=Debug
cmake .. -DCMAKE_BUILD_TYPE=Debug -DLIBASSERT_WERROR_BUILD=On
msbuild demo_project.sln
.\Debug\main.exe
18 changes: 12 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ jobs:
cmake .. \
-DCMAKE_BUILD_TYPE=${{matrix.target}} \
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} \
-DLIBASSERT_BUILD_TESTING=On
-DLIBASSERT_BUILD_TESTING=On \
-DLIBASSERT_WERROR_BUILD=On
make -j
- name: test
working-directory: build
Expand All @@ -54,7 +55,8 @@ jobs:
cmake .. \
-DCMAKE_BUILD_TYPE=${{matrix.target}} \
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} \
-DLIBASSERT_BUILD_TESTING=On
-DLIBASSERT_BUILD_TESTING=On \
-DLIBASSERT_WERROR_BUILD=On
make -j
- name: test
working-directory: build
Expand Down Expand Up @@ -88,7 +90,8 @@ jobs:
-DCMAKE_BUILD_TYPE=${{matrix.target}} \
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} \
-DCMAKE_C_COMPILER=${{matrix.c_compiler}} \
-DLIBASSERT_BUILD_TESTING=On
-DLIBASSERT_BUILD_TESTING=On \
-DLIBASSERT_WERROR_BUILD=On
make -j
- name: test
working-directory: build
Expand All @@ -115,7 +118,8 @@ jobs:
cd build
cmake .. `
-DCMAKE_BUILD_TYPE=${{matrix.target}} `
-DLIBASSERT_BUILD_TESTING=On
-DLIBASSERT_BUILD_TESTING=On \
-DLIBASSERT_WERROR_BUILD=On
msbuild .\libassert.sln
# - name: build clang
# if: ${{ matrix.compiler == 'clang++' }}
Expand All @@ -126,7 +130,8 @@ jobs:
# -DCMAKE_BUILD_TYPE=${{matrix.target}} `
# -DCMAKE_CXX_COMPILER="C:\msys64\mingw64\bin\clang++" `
# -DCMAKE_C_COMPILER="C:\msys64\mingw64\bin\clang" `
# -DLIBASSERT_BUILD_TESTING=On
# -DLIBASSERT_BUILD_TESTING=On \
# -DLIBASSERT_WERROR_BUILD=On
# msbuild .\libassert.sln
- name: test
working-directory: build
Expand Down Expand Up @@ -155,7 +160,8 @@ jobs:
-DCMAKE_CXX_COMPILER=${{matrix.compiler}} `
-DLIBASSERT_BUILD_TESTING=On `
-DLIBASSERT_USE_CI_WRAPPER=On `
"-GUnix Makefiles"
"-GUnix Makefiles" \
-DLIBASSERT_WERROR_BUILD=On
make -j
- name: test
working-directory: build
Expand Down
20 changes: 17 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,26 @@ target_link_libraries(
cpptrace::cpptrace
)

set(
warning_options
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Werror=return-type -Wundef>
$<$<CXX_COMPILER_ID:GNU>:-Wuseless-cast -Wmaybe-uninitialized>
$<$<CXX_COMPILER_ID:MSVC>:/W4 /permissive->
)

if(LIBASSERT_WERROR_BUILD)
set(
warning_options
${warning_options}
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Werror -Wpedantic>
$<$<CXX_COMPILER_ID:MSVC>:/WX>
)
endif()

target_compile_options(
${target_name}
PRIVATE
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Werror=return-type -Wshadow -Wundef>
$<$<CXX_COMPILER_ID:GNU>:-Wuseless-cast -Wnonnull-compare>
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX /permissive->
${warning_options}
)

# ---- Generate Build Info Headers ----
Expand Down
2 changes: 2 additions & 0 deletions cmake/OptionVariables.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ option(
)
option(LIBASSERT_USE_EXTERNAL_MAGIC_ENUM "Obtain magic_enum via find_package instead of FetchContent" OFF)

option(LIBASSERT_WERROR_BUILD "" OFF)

option(LIBASSERT_PROVIDE_EXPORT_SET "" ON)
mark_as_advanced(
LIBASSERT_PROVIDE_EXPORT_SET
Expand Down
4 changes: 1 addition & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
target_compile_options(
${target_name}
PRIVATE
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall -Wextra -Werror=return-type -Wshadow -Wundef -Werror>
$<$<CXX_COMPILER_ID:GNU>:-Wuseless-cast -Wnonnull-compare>
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX /permissive->
${warning_options}
)
endforeach()
endif()

0 comments on commit e47aff4

Please sign in to comment.