Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion .github/workflows/static-analyzers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,32 @@ jobs:
steps:
- uses: actions/checkout@v6
- name: Run cppcheck
run: cppcheck --enable=performance,portability --check-level=exhaustive --suppressions-list=config/cppcheck_suppressions.txt --error-exitcode=-4 -i ThirdParty -i FuzzTargets -i docs -i config .
run: cppcheck --enable=performance,portability --check-level=exhaustive --suppressions-list=config/cppcheck_suppressions.txt --error-exitcode=-4 -i ThirdParty -i FuzzTargets -i docs -i config .

gcc-strict-overflow:
name: GCC strict-overflow
runs-on: ubuntu-latest
container:
image: helics/buildenv:gcc15-builder

steps:
- uses: actions/checkout@v6
with:
submodules: true

- name: Mark workspace as safe for git
run: git config --global --add safe.directory "${GITHUB_WORKSPACE}"

- name: Configure
run: >
cmake -S . -B build
-DCMAKE_CXX_STANDARD=23
-DUNITS_ENABLE_ERROR_ON_WARNINGS=ON
-DCMAKE_CXX_FLAGS="-Wstrict-overflow=5 -Werror=strict-overflow"

- name: Build
run: cmake --build build --parallel 4

- name: Test
working-directory: build
run: ctest --output-on-failure
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ endif()
project(
${UNITS_CMAKE_PROJECT_NAME}
LANGUAGES C CXX
VERSION 0.13.1
VERSION 0.14.0
)
include(CMakeDependentOption)
include(CTest)
Expand Down
240 changes: 177 additions & 63 deletions ThirdParty/CLI11.hpp

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,6 @@ jobs:
containerImage: helics/buildenv:gcc4-8-builder
units.std: 11
units.options:
gcc15:
containerImage: helics/buildenv:gcc15-builder
units.std: 26
units.options: -DCMAKE_CXX_FLAGS="-std=c++2c -Warith-conversion -Wbidi-chars=any -Wstrict-overflow=5 -Werror=strict-overflow"
clang9_17:
containerImage: helics/buildenv:clang9-builder
units.std: 17
Expand Down
52 changes: 32 additions & 20 deletions config/AddGoogletest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@
#

include(extraMacros)
include(CheckCXXCompilerFlag)

check_cxx_compiler_flag(
"-Wno-c++17-attribute-extensions" UNITS_HAS_WNO_CXX17_ATTRIBUTE_EXTENSIONS
)
check_cxx_compiler_flag("-Wno-unknown-attributes" UNITS_HAS_WNO_UNKNOWN_ATTRIBUTES)

function(units_configure_gtest_warnings target_name)
if(NOT MSVC)
target_compile_options(${target_name} PUBLIC "-Wno-undef")
if(UNITS_HAS_WNO_CXX17_ATTRIBUTE_EXTENSIONS)
target_compile_options(
${target_name}
PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-Wno-c++17-attribute-extensions>>
)
endif()
if(UNITS_HAS_WNO_UNKNOWN_ATTRIBUTES)
target_compile_options(
${target_name}
PUBLIC
$<$<COMPILE_LANGUAGE:CXX>:$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:-Wno-unknown-attributes>>
)
endif()
endif()
endfunction()

if(NOT UNITS_USE_EXTERNAL_GTEST AND NOT GTest_FOUND)

Expand Down Expand Up @@ -44,26 +70,10 @@ if(NOT UNITS_USE_EXTERNAL_GTEST AND NOT GTest_FOUND)
${CMAKE_BINARY_DIR}/ThirdParty/googletest EXCLUDE_FROM_ALL
)

if(NOT MSVC)
target_compile_options(
gtest PUBLIC "-Wno-undef"
$<$<CXX_COMPILER_ID:Clang>:-Wno-c++17-attribute-extensions>
)
target_compile_options(
gmock PUBLIC "-Wno-undef"
$<$<CXX_COMPILER_ID:Clang>:-Wno-c++17-attribute-extensions>
)
target_compile_options(
gtest_main
PUBLIC "-Wno-undef"
$<$<CXX_COMPILER_ID:Clang>:-Wno-c++17-attribute-extensions>
)
target_compile_options(
gmock_main
PUBLIC "-Wno-undef"
$<$<CXX_COMPILER_ID:Clang>:-Wno-c++17-attribute-extensions>
)
endif()
units_configure_gtest_warnings(gtest)
units_configure_gtest_warnings(gmock)
units_configure_gtest_warnings(gtest_main)
units_configure_gtest_warnings(gmock_main)

hide_variable(gmock_build_tests)
hide_variable(gtest_build_samples)
Expand Down Expand Up @@ -104,6 +114,7 @@ function(add_unit_test test_source_file)
get_filename_component(test_name "${test_source_file}" NAME_WE)
add_executable("${test_name}" "${test_source_file}")
target_link_libraries("${test_name}" GTest::gtest GTest::gmock GTest::gtest_main)
units_configure_gtest_warnings("${test_name}")
add_test(NAME ${test_name} COMMAND $<TARGET_FILE:${test_name}>)
set_target_properties(${test_name} PROPERTIES FOLDER "Tests")
endfunction()
Expand All @@ -113,6 +124,7 @@ macro(add_gtest TESTNAME)
target_link_libraries(
${TESTNAME} PUBLIC GTest::gtest GTest::gmock GTest::gtest_main
)
units_configure_gtest_warnings(${TESTNAME})

if(GOOGLE_TEST_INDIVIDUAL)
gtest_discover_tests(
Expand Down
22 changes: 15 additions & 7 deletions config/compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
# SPDX-License-Identifier: BSD-3-Clause
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

include(CheckCXXCompilerFlag)

option(${PROJECT_NAME}_ENABLE_EXTRA_COMPILER_WARNINGS
"disable compiler warning for ${CMAKE_PROJECT_NAME} build" ON
)
Expand All @@ -28,26 +30,32 @@ endif()
target_compile_options(
compile_flags_target
INTERFACE
$<$<CXX_COMPILER_ID:MSVC>:$<$<BOOL:${HELICS_ENABLE_ERROR_ON_WARNINGS}>:/WX>>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:$<$<BOOL:${HELICS_ENABLE_ERROR_ON_WARNINGS}>:-Werror>>
$<$<CXX_COMPILER_ID:MSVC>:$<$<BOOL:${${PROJECT_NAME}_ENABLE_ERROR_ON_WARNINGS}>:/WX>>
$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:$<$<BOOL:${${PROJECT_NAME}_ENABLE_ERROR_ON_WARNINGS}>:-Werror>>
)

if(${PROJECT_NAME}_ENABLE_EXTRA_COMPILER_WARNINGS)
check_cxx_compiler_flag("-Wdouble-promotion" PROJECT_HAS_WDOUBLE_PROMOTION)

target_compile_options(
compile_flags_target INTERFACE $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wall
-pedantic>
)
target_compile_options(
compile_flags_target
INTERFACE $<$<COMPILE_LANGUAGE:CXX>:$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wextra
-Wshadow
-Wstrict-aliasing=1
-Wunreachable-code
-Woverloaded-virtual
-Wdouble-promotion
-Wshadow -Wstrict-aliasing=1 -Wunreachable-code -Woverloaded-virtual
-Wundef>>
)

if(PROJECT_HAS_WDOUBLE_PROMOTION)
target_compile_options(
compile_flags_target
INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:$<$<NOT:$<CXX_COMPILER_ID:MSVC>>:-Wdouble-promotion>>
)
endif()

target_compile_options(
compile_flags_target
INTERFACE $<$<COMPILE_LANGUAGE:CXX>:$<$<CXX_COMPILER_ID:Clang>:-Wcast-align>>
Expand Down
6 changes: 4 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ else()
test_complete_unit_list PUBLIC -DTEST_FILE_FOLDER="${TEST_FILE_FOLDER}"
)
if(NOT MSVC)
target_compile_options(test_ucum PRIVATE -Wno-double-promotion)
target_compile_options(test_udunits PRIVATE -Wno-double-promotion)
if(PROJECT_HAS_WDOUBLE_PROMOTION)
target_compile_options(test_ucum PRIVATE -Wno-double-promotion)
target_compile_options(test_udunits PRIVATE -Wno-double-promotion)
endif()
else()
target_compile_options(test_unit_ops PRIVATE /wd4127)
target_compile_options(test_random_round_trip PRIVATE /wd4127)
Expand Down
1 change: 1 addition & 0 deletions units/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ elseif(UNITS_BUILD_OBJECT_LIBRARY)
target_include_directories(
units PRIVATE $<BUILD_INTERFACE:${${UNITS_CMAKE_PROJECT_NAME}_SOURCE_DIR}>
)
target_link_libraries(units PRIVATE compile_flags_target)

if(UNITS_NAMESPACE)
target_compile_definitions(units PUBLIC -DUNITS_NAMESPACE=${UNITS_NAMESPACE})
Expand Down
6 changes: 3 additions & 3 deletions units/unit_definitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1831,9 +1831,9 @@ namespace detail {
double convertTemperature(double val, const UX& start, const UX2& result)
{
static constexpr std::array<double, 30> biasTable{
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 121.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 150.0, 0.0, 37.7778, 0.0, 0.0};
{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 121.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0, 150.0, 0.0, 37.7778, 0.0, 0.0}};

if (is_temperature(start)) {
if (units::degF == unit_cast(start)) {
Expand Down
Loading