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
bilibrary 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_TESTSis enabled (default isON), run the tests using:ctest
-
Install the Library:
cmake --install . --prefix /path/to/installReplace
/path/to/installwith 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_TYPEtoReleaseat configuration time:cmake .. -DCMAKE_BUILD_TYPE=Release
For single-configuration generators, if
CMAKE_BUILD_TYPEis not specified, this library will setCMAKE_BUILD_TYPEtoReleaseby 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 Releaseoption with thecmake --buildcommand to specify a release build:cmake --build . --config ReleaseFor a debug build, use the
--config Debugoption.
Development
-
Enabling the export of compile commands is useful for tools like linters or editors. To do this, set
CMAKE_EXPORT_COMPILE_COMMANDStoON. 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
biLibrary or Use a Packaged Version of the Library
-
Install the
biLibraryEnsure that
biis 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
bilibrary, 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_PATHin your project, enabling CMake to find and link the library.
-
Configure Your Project to Find the
biLibraryIn your project's
CMakeLists.txtfile, use thefind_package()command to locate thebilibrary:find_package(bi REQUIRED) -
Link Against the
biLibraryAfter finding the
bilibrary 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
bito a non-standard location, say,/path/to/install.
-
Option 1: Using Command Line
Set
CMAKE_PREFIX_PATHto/path/to/installwhen configuring your project.For example:
cmake .. -DCMAKE_PREFIX_PATH=/path/to/install
-
Option 2: Modifying
CMakeLists.txtAlternatively, append the path to
CMAKE_PREFIX_PATHin 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:
cpackRefer to the
cpackdocumentation 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
bilibrary by setting theCMAKE_PREFIX_PATHto the path of the extracted library. This can be done within theCMakeLists.txtfile 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.