diff --git a/CMakeLists.txt b/CMakeLists.txt index 94c7cc40318..a3b6da6b440 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,8 @@ if(MSVC) endif() project(Cppcheck VERSION 2.16.99 LANGUAGES CXX) +include(cmake/options.cmake) + include(cmake/cxx11.cmake) use_cxx11() set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -14,7 +16,6 @@ include(GNUInstallDirs) include(cmake/compilerCheck.cmake) include(cmake/versions.cmake) -include(cmake/options.cmake) include(cmake/findDependencies.cmake) include(cmake/compileroptions.cmake) include(cmake/compilerDefinitions.cmake) diff --git a/cmake/compilerDefinitions.cmake b/cmake/compilerDefinitions.cmake index 5de849fc399..08854b65823 100644 --- a/cmake/compilerDefinitions.cmake +++ b/cmake/compilerDefinitions.cmake @@ -35,6 +35,9 @@ endif() if(Boost_FOUND) add_definitions(-DHAVE_BOOST) + if(USE_BOOST_INT128) + add_definitions(-DHAVE_BOOST_INT128) + endif() endif() if(ENABLE_CHECK_INTERNAL) diff --git a/cmake/cxx11.cmake b/cmake/cxx11.cmake index b5cb4631218..c0fac705149 100644 --- a/cmake/cxx11.cmake +++ b/cmake/cxx11.cmake @@ -3,6 +3,9 @@ macro(use_cxx11) if(MSVC AND USE_QT6) # CMAKE_CXX_STANDARD 17 was added in CMake 3.8 set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to use") + elseif(USE_BOOST AND USE_BOOST_INT128) + # Boost.Math requires C++14 + set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to use") else() set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to use") endif() diff --git a/cmake/options.cmake b/cmake/options.cmake index eedc649f9bc..4445f4e8d95 100644 --- a/cmake/options.cmake +++ b/cmake/options.cmake @@ -67,6 +67,7 @@ endif() option(CPPCHK_GLIBCXX_DEBUG "Usage of STL debug checks in Debug build" ON) option(DISALLOW_THREAD_EXECUTOR "Disallow usage of ThreadExecutor for -j" OFF) option(USE_BOOST "Usage of Boost" OFF) +option(USE_BOOST_INT128 "Usage of Boost.Multiprecision 128-bit integer for Mathlib" OFF) option(USE_LIBCXX "Use libc++ instead of libstdc++" OFF) if(DISALLOW_THREAD_EXECUTOR AND WIN32) diff --git a/cmake/printInfo.cmake b/cmake/printInfo.cmake index 97681645035..9ea57fe31a7 100644 --- a/cmake/printInfo.cmake +++ b/cmake/printInfo.cmake @@ -95,6 +95,8 @@ if(USE_BOOST) message(STATUS "Boost_FOUND = ${Boost_FOUND}") message(STATUS "Boost_VERSION_STRING = ${Boost_VERSION_STRING}") message(STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}") + message(STATUS "USE_BOOST_INT128 = ${USE_BOOST_INT128}") + message(STATUS) endif() message(STATUS "USE_LIBCXX = ${USE_LIBCXX}") message(STATUS) diff --git a/lib/mathlib.h b/lib/mathlib.h index 18684c8a7c1..08d63163372 100644 --- a/lib/mathlib.h +++ b/lib/mathlib.h @@ -26,6 +26,10 @@ #include #include +#if defined(HAVE_BOOST) && defined(HAVE_BOOST_INT128) +#include +#endif + /// @addtogroup Core /// @{ @@ -35,6 +39,14 @@ class CPPCHECKLIB MathLib { friend class TestMathLib; public: +#if defined(HAVE_BOOST) && defined(HAVE_BOOST_INT128) + using bigint = boost::multiprecision::int128_t; + using biguint = boost::multiprecision::uint128_t; +#else + using bigint = long long; + using biguint = unsigned long long; +#endif + /** @brief value class */ class value { private: @@ -66,8 +78,6 @@ class CPPCHECKLIB MathLib { value shiftRight(const value &v) const; }; - using bigint = long long; - using biguint = unsigned long long; static const int bigint_bits; /** @brief for conversion of numeric literals - for atoi-like conversions please use strToInt() */