bi
is an arbitrary precision integer library for C++.
- Documentation
- Building from Source
- Finding and Linking Against the Library Using find_package()
- Packaging with CPack
For detailed documentation, including this document and an
API reference, visit
the bi
Documentation.
- CMake (version 3.15 or higher): Required for configuring and building the project.
- C++20 compiler.
-
Clone the repository:
git clone <repository-url-or-ssh> cd bi
-
Create a build directory:
mkdir build && cd build
-
Configure the build:
For the default configuration:
cmake ..
For custom configurations, refer to the Options section below.
Note: The
bi
library targets C++20. Sometimes, the default compiler found by CMake might lack support for some C++20 features used in the library. CMake allows you to specify the compiler manually. For instance:cmake .. -DCMAKE_CXX_COMPILER=clang++
More generally:
cmake .. -DCMAKE_CXX_COMPILER=/path/to/your/compiler
-
Build the library
cmake --build .
-
Run Tests (if applicable):
If
BUILD_TESTS
is enabled (default isON
), run the tests using:ctest
-
Install the Library:
cmake --install . --prefix /path/to/install
Replace
/path/to/install
with the desired installation directory.
Configure the build by appending these options to the cmake
command in step 3:
BUILD_SHARED_LIBS
: Build shared libraries (ON
/OFF
). Default isOFF
.BUILD_TESTS
: Build the tests (ON
/OFF
). Default isON
.
Release-Optimized or Debug Build
-
Single-configuration generators. Set
CMAKE_BUILD_TYPE
toRelease
at configuration time:cmake .. -DCMAKE_BUILD_TYPE=Release
For single-configuration generators, if
CMAKE_BUILD_TYPE
is not specified, this library will setCMAKE_BUILD_TYPE
toRelease
by default. For a debug build, use-DCMAKE_BUILD_TYPE=Debug
. -
Multi-configuration generators (e.g. Visual Studio). The build type for these generators is selected at build time, not at configuration time. Use the
--config Release
option with thecmake --build
command to specify a release build:cmake --build . --config Release
For a debug build, use the
--config Debug
option.
Development
-
Enabling the export of compile commands is useful for tools like linters or editors. To do this, set
CMAKE_EXPORT_COMPILE_COMMANDS
toON
. For example:cmake .. -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
To integrate the bi
library into a CMake project, locate and link against it
using CMake's find_package()
command.
- Install the
bi
Library or Use a Packaged Version of the Library
-
Install the
bi
LibraryEnsure that
bi
is installed on your system. If you haven't already installed it, or if you're unsure how to do so, refer to the Building From Source section for steps on creating a build directory, configuring, building, and installing the library. -
Use a Packaged Version of the Library:
Alternatively, if you have a CPack-generated package of the
bi
library, extract it to a preferred location. This option is useful if you prefer not to build from source or are distributing the library to others.Important Note: If you install the library or extract a packaged version of it to a non-standard location (i.e., not in the default system paths), note the path (e.g.,
/path/to/install
). You may need this information for setting theCMAKE_PREFIX_PATH
in your project, enabling CMake to find and link the library.
-
Configure Your Project to Find the
bi
LibraryIn your project's
CMakeLists.txt
file, use thefind_package()
command to locate thebi
library:find_package(bi REQUIRED)
-
Link Against the
bi
LibraryAfter finding the
bi
library withfind_package()
, link it to your target:add_executable(sample sample.cpp) target_link_libraries(sample PRIVATE bi::bi)
-
Setting the
CMAKE_PREFIX_PATH
(if necessary)This step is only necessary if you installed or extracted
bi
to a non-standard location, say,/path/to/install
.
-
Option 1: Using Command Line
Set
CMAKE_PREFIX_PATH
to/path/to/install
when configuring your project.For example:
cmake .. -DCMAKE_PREFIX_PATH=/path/to/install
-
Option 2: Modifying
CMakeLists.txt
Alternatively, append the path to
CMAKE_PREFIX_PATH
in your project'sCMakeLists.txt
:list(APPEND CMAKE_PREFIX_PATH /path/to/install)
Add this before the
find_package()
call.
After building the bi
library, one can create a distributable package using
CPack, containing the compiled binaries and necessary headers.
-
Complete the build process as described in Building from Source.
-
In the build directory, run:
cpack
Refer to the
cpack
documentation for additional options and details.
Users with compatible platforms can integrate the packaged bi
library into
their projects.
For example, for CMake-based projects:
- Extract the Package: After downloading or receiving the CPack-generated package, extract it to a preferred location on your system.
- Configure the Project: In your CMake project, inform CMake where to find
the
bi
library by setting theCMAKE_PREFIX_PATH
to the path of the extracted library. This can be done within theCMakeLists.txt
file or as a command-line argument during CMake configuration. Refer to the section on Finding and Linking Against the Library Using find_package().
This approach allows users to integrate the library into their CMake-based projects, bypassing the need to build the library from source.