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

added CMake option USE_BOOST_INT128 to use a Boost.Multiprecision 128-bit integer for MathLib:big{u}int #7028

Merged
merged 1 commit into from
Dec 4, 2024
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
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)
Copy link
Collaborator Author

@firewave firewave Nov 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the top so the default values for the options will be applied here.


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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this because it will later be needed higher up in the class.

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