Skip to content

Commit

Permalink
added CMake option USE_BOOST_INT128 to use a Boost.Multiprecision 1…
Browse files Browse the repository at this point in the history
…28-bit integer for `MathLib:big{u}int` (danmar#7028)

Co-authored-by: chrchr-github <[email protected]>
  • Loading branch information
firewave and chrchr-github authored Dec 4, 2024
1 parent 773663f commit 74f9437
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions cmake/compilerDefinitions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions cmake/cxx11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions cmake/printInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 12 additions & 2 deletions lib/mathlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#include <cstdint>
#include <string>

#if defined(HAVE_BOOST) && defined(HAVE_BOOST_INT128)
#include <boost/multiprecision/cpp_int.hpp>
#endif

/// @addtogroup Core
/// @{

Expand All @@ -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:
Expand Down Expand Up @@ -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() */
Expand Down

0 comments on commit 74f9437

Please sign in to comment.