Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time

primesieve build instructions

Prerequisites

You need to have installed a C++ compiler which supports C++11 (or later) and CMake β‰₯ 3.4.

macOS xcode-select --install && brew install cmake
Debian/Ubuntu: sudo apt install g++ cmake
Fedora: sudo dnf install gcc-c++ cmake
openSUSE: sudo zypper install gcc-c++ cmake
Arch Linux: sudo pacman -S gcc cmake

Unix-like OSes

Open a terminal, cd into the primesieve directory and run:

cmake .
cmake --build . --parallel
sudo cmake --install .
sudo ldconfig

MinGW/MSYS2 (Windows)

Open a terminal, cd into the primesieve directory and run:

cmake -G "Unix Makefiles" .
cmake --build . --parallel

Microsoft Visual C++

First install Visual Studio (includes CMake) on your Windows PC. Then go to the start menu, select Visual Studio and open a x64 Command Prompt. Now cd into the primesieve directory and run the commands below:

# Use 'cmake -G' to find your Visual Studio version
cmake -G "Visual Studio 17 2022" .
cmake --build . --config Release

# Optionally install using Admin shell
cmake --install . --config Release

CMake configure options

By default the primesieve binary and the static/shared libprimesieve will be built. The build options can be modified at the configure step using e.g. cmake . -DBUILD_TESTS=ON.

option(BUILD_PRIMESIEVE  "Build primesieve binary"       ON)
option(BUILD_SHARED_LIBS "Build shared libprimesieve"    ON)
option(BUILD_STATIC_LIBS "Build static libprimesieve"    ON)
option(BUILD_DOC         "Build C/C++ API documentation" OFF)
option(BUILD_MANPAGE     "Regenerate man page using a2x" OFF)
option(BUILD_EXAMPLES    "Build example programs"        OFF)
option(BUILD_TESTS       "Build test programs"           OFF)

option(WITH_AUTO_VECTORIZATION "Enable compiler auto-vectorization" ON)
option(WITH_MULTIARCH          "Enable runtime dispatching to fastest supported CPU instruction set" ON)
option(WITH_MSVC_CRT_STATIC    "Link primesieve.lib with /MT instead of the default /MD" OFF)

Run the tests

Open a terminal, cd into the primesieve directory and run:

cmake -DBUILD_TESTS=ON .
cmake --build . --parallel
ctest

For developers hacking on primesieve's source code the test/README.md document contains more information about primesieve testing such as testing in debug mode and testing using GCC/Clang sanitizers.

C/C++ examples

Open a terminal, cd into the primesieve directory and run:

cmake -DBUILD_EXAMPLES=ON .
cmake --build . --parallel

API documentation

To build the primesieve C/C++ API documentation in html/PDF format you need to have installed the doxygen, doxygen-latex and graphviz (dot) packages.

cmake -DBUILD_DOC=ON .
cmake --build . --target doc

Man page regeneration

primesieve includes an up to date man page at doc/primesieve.1. That man page has been generated from doc/primesieve.txt using the a2x program from the asciidoc package. However when packaging primesieve for e.g. a Linux distro it is recommended to regenerate the man page.

# Build man page using a2x program (asciidoc package)
cmake -DBUILD_MANPAGE=ON .
cmake --build . --parallel