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

Add KIVA_WERROR option to interpret compiler warnings as errors #55

Merged
merged 12 commits into from
Aug 31, 2022
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
sudo apt-get -y install libglu1-mesa-dev freeglut3-dev mesa-common-dev

- name: Configure CMake
run: cmake -S . -B build -DKIVA_COVERAGE="${{ matrix.coverage }}" -DKIVA_STATIC_LIB="${{ matrix.static_lib }}" -DCMAKE_BUILD_TYPE="${{ matrix.config }}"
run: cmake -S . -B build -DKIVA_WERROR="ON" -DKIVA_COVERAGE="${{ matrix.coverage }}" -DKIVA_STATIC_LIB="${{ matrix.static_lib }}" -DCMAKE_BUILD_TYPE="${{ matrix.config }}"

- name: Setup tooling
uses: ruby/setup-ruby@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
sudo apt-get -y install libglu1-mesa-dev freeglut3-dev mesa-common-dev

- name: Configure CMake
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DKIVA_WERROR="ON"

- name: Build
run: cmake --build build --config Release
Expand Down
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ option(ENABLE_OPENMP "Use OpenMP" OFF)
option( KIVA_GROUND_PLOT "Build ground plotting library" ON )
mark_as_advanced(FORCE BUILD_GROUND_PLOT)
option( KIVA_TESTING "Build tests" ON )
option( KIVA_WERROR "Turn on warnings into error" OFF )

find_package(Git QUIET)

Expand All @@ -21,6 +22,8 @@ if (KIVA_TESTING)
endif()
endif()

include(compiler-flags)

set( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${kiva_BINARY_DIR}" )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${kiva_BINARY_DIR}" )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${kiva_BINARY_DIR}" )
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Pre-requisites:
Building Kiva from source
-------------------------

1. Clone the git repository, or download and extract the source code (`tar.gz` or `zip`).
1. Clone the git repository.
2. Make a directory called `build` inside the top level of your source.
3. Open a console in the `build` directory.
4. Type `cmake ..`.
Expand Down
23 changes: 23 additions & 0 deletions cmake/compiler-flags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
add_library(kiva_common_interface INTERFACE)

#================#
# Compiler flags #
#================#

target_compile_options(kiva_common_interface INTERFACE
nealkruis marked this conversation as resolved.
Show resolved Hide resolved
$<$<CXX_COMPILER_ID:MSVC>:
/W4 # Warning level (default is W3)
$<$<BOOL:${KIVA_WERROR}>:
/WX # Turn warnings into errors
>
>
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:
-Wall
-Wextra
-Wpedantic
$<$<BOOL:${KIVA_WERROR}>:
-Werror # Turn warnings into errors
>
>

)
8 changes: 1 addition & 7 deletions src/kiva/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ set(CMAKE_INSTALL_RPATH "@executable_path")

add_executable(kiva ${kiva_src})

target_link_libraries(kiva libkiva groundplot boost_program_options yaml-cpp)
target_link_libraries(kiva PRIVATE groundplot boost_program_options yaml-cpp kiva_common_interface)

target_include_directories(kiva PRIVATE "${groundplot_SOURCE_DIR}")

target_compile_options(kiva PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -Wpedantic -Werror>
)

if (KIVA_COVERAGE)
add_coverage(kiva)
endif()
Expand Down
8 changes: 1 addition & 7 deletions src/libgroundplot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ set(groundplot_src GroundPlot.cpp

add_library(groundplot STATIC ${groundplot_src})

target_link_libraries(groundplot fmt mgl-static libkiva)
target_link_libraries(groundplot PUBLIC fmt mgl-static libkiva PRIVATE kiva_common_interface)

target_include_directories(groundplot PUBLIC "${MathGL2_SOURCE_DIR}/include" "${MathGL2_BINARY_DIR}/include")

target_compile_options(groundplot PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -Wpedantic -Werror>
)

if (KIVA_COVERAGE)
add_coverage(groundplot)
endif()
6 changes: 1 addition & 5 deletions src/libkiva/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,7 @@ target_include_directories(libkiva PUBLIC
"${BOOST_SOURCE_DIR}"
"${kiva_SOURCE_DIR}/vendor/eigen")

target_compile_options(libkiva PRIVATE
$<$<CXX_COMPILER_ID:MSVC>:/W4 /WX>
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wall -Wextra -Wpedantic -Werror>
)
target_link_libraries(libkiva PRIVATE kiva_common_interface)
target_compile_features(libkiva PUBLIC cxx_std_17) # Should be PRIVATE once boost is cleaned out of public API

include(GenerateExportHeader)
Expand Down
2 changes: 1 addition & 1 deletion test/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(kiva_test_src

add_executable(kiva_tests ${kiva_test_src})

target_link_libraries(kiva_tests gtest libkiva)
target_link_libraries(kiva_tests PRIVATE gtest libkiva kiva_common_interface)

add_test(NAME unit.GC10aFixture.calculateADI COMMAND $<TARGET_FILE:kiva_tests> "--gtest_filter=GC10aFixture.calculateADI")
add_test(NAME unit.GC10aFixture.calculateImplicit COMMAND $<TARGET_FILE:kiva_tests> "--gtest_filter=GC10aFixture.calculateImplicit")
Expand Down