diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index ea0ce9dd..6e66d677 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -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 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 89f9f133..e8189207 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 0e7b9ea0..c327e186 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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}" ) diff --git a/README.md b/README.md index 924a8463..a15db741 100644 --- a/README.md +++ b/README.md @@ -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 ..`. diff --git a/cmake/compiler-flags.cmake b/cmake/compiler-flags.cmake new file mode 100644 index 00000000..6e76755c --- /dev/null +++ b/cmake/compiler-flags.cmake @@ -0,0 +1,23 @@ +add_library(kiva_common_interface INTERFACE) + + #================# + # Compiler flags # + #================# + +target_compile_options(kiva_common_interface INTERFACE +$<$: + /W4 # Warning level (default is W3) + $<$: + /WX # Turn warnings into errors + > +> +$<$,$>: + -Wall + -Wextra + -Wpedantic + $<$: + -Werror # Turn warnings into errors + > +> + +) diff --git a/src/kiva/CMakeLists.txt b/src/kiva/CMakeLists.txt index b739f4fb..c407569e 100644 --- a/src/kiva/CMakeLists.txt +++ b/src/kiva/CMakeLists.txt @@ -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 - $<$:/W4 /WX> - $<$,$,$>: - -Wall -Wextra -Wpedantic -Werror> -) - if (KIVA_COVERAGE) add_coverage(kiva) endif() diff --git a/src/libgroundplot/CMakeLists.txt b/src/libgroundplot/CMakeLists.txt index c5a9995d..faceda18 100644 --- a/src/libgroundplot/CMakeLists.txt +++ b/src/libgroundplot/CMakeLists.txt @@ -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 - $<$:/W4 /WX> - $<$,$,$>: - -Wall -Wextra -Wpedantic -Werror> - ) - if (KIVA_COVERAGE) add_coverage(groundplot) endif() diff --git a/src/libkiva/CMakeLists.txt b/src/libkiva/CMakeLists.txt index bb78b098..f2f000d9 100644 --- a/src/libkiva/CMakeLists.txt +++ b/src/libkiva/CMakeLists.txt @@ -179,11 +179,7 @@ target_include_directories(libkiva PUBLIC "${BOOST_SOURCE_DIR}" "${kiva_SOURCE_DIR}/vendor/eigen") -target_compile_options(libkiva PRIVATE - $<$:/W4 /WX> - $<$,$,$>: - -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) diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index f86e805b..bdbd6d45 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -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 $ "--gtest_filter=GC10aFixture.calculateADI") add_test(NAME unit.GC10aFixture.calculateImplicit COMMAND $ "--gtest_filter=GC10aFixture.calculateImplicit")