Skip to main content

Prerequisites

  • CMake >= 3.16
  • OpenSSL (>= 1.0.0) or Botan (>= 2.0.0) — cryptographic backend
  • CppUnit — required to build and run tests (-DBUILD_TESTS=ON)
  • SQLite3 (>= 3.4.2) — required when enabling the migration tool or database object store
  • A C++11-capable compiler (GCC, Clang, or MSVC)

Build steps

1

Configure the build

Run CMake from the source root, placing build artefacts in a build subdirectory:
cmake -H. -Bbuild
Pass any options as -D flags on the same command line:
cmake -H. -Bbuild -DWITH_CRYPTO_BACKEND=openssl -DBUILD_TESTS=ON
2

Compile

make -C build
3

Run tests (optional)

Requires -DBUILD_TESTS=ON during configuration.
cd build
ctest -V
4

Install

sudo make -C build install

CMake options

Testing

OptionDefaultDescription
-DBUILD_TESTS=ONOFFCompile the test suite along with the library.

Memory

OptionDefaultDescription
-DDISABLE_NON_PAGED_MEMORY=ONOFFDisable non-paged memory for secure storage.

Algorithm support

OptionDefaultDescription
-DENABLE_ECC=ONONEnable ECC support.
-DENABLE_EDDSA=ONONEnable EdDSA (Ed25519, Ed448) support.
-DENABLE_MLDSA=ONOFFEnable ML-DSA (FIPS 204 post-quantum signature scheme) support.
-DENABLE_GOST=ONOFFEnable GOST algorithm support.

Crypto backend

OptionDefaultDescription
-DWITH_CRYPTO_BACKEND=openssl|botanopensslSelect the cryptographic backend.
# Use Botan instead of OpenSSL
cmake -H. -Bbuild -DWITH_CRYPTO_BACKEND=botan

Migration tool and object store

OptionDefaultDescription
-DWITH_MIGRATE=ONOFFBuild softhsm2-migrate for converting SoftHSM v1 databases. Requires SQLite3.
-DWITH_OBJECTSTORE_BACKEND_DB=ONOFFEnable the SQLite3 database object store. Automatically enables WITH_MIGRATE.

Windows-specific notes

On Windows, the recommended approach is to use vcpkg for dependency management and the Visual Studio generator for CMake.

Required software

Install dependencies with vcpkg

set VCPKG_HOME=C:\Projects\vcpkg
git clone https://github.com/Microsoft/vcpkg.git %VCPKG_HOME%
cd %VCPKG_HOME%
bootstrap-vcpkg.bat

vcpkg install cppunit:x86-windows
vcpkg install cppunit:x86-windows-static
vcpkg install openssl-windows:x86-windows
vcpkg install botan:x86-windows
vcpkg install sqlite3:x86-windows

vcpkg integrate install

Configure and build

set SOFTHSM_HOME=C:\Projects\SoftHSMv2

mkdir %SOFTHSM_HOME%\tmp32
cd %SOFTHSM_HOME%\tmp32
cmake .. -G "Visual Studio 15 2017" -A Win32 ^
    -DCMAKE_TOOLCHAIN_FILE=%VCPKG_HOME%\scripts\buildsystems\vcpkg.cmake ^
    -DCMAKE_INSTALL_PREFIX=%SOFTHSM_HOME%\out32 ^
    -DBUILD_TESTS=ON ^
    -DWITH_CRYPTO_BACKEND=openssl ^
    -DWITH_OBJECTSTORE_BACKEND_DB=OFF

Compile, test, and install (Windows)

# Compile
cmake --build . --config RelWithDebInfo

# Run tests
ctest -C RelWithDebInfo --output-on-failure --progress --verbose

# Install
cmake -DCMAKE_INSTALL_CONFIG_NAME=RelWithDebInfo -P cmake_install.cmake
The -DWITH_OBJECTSTORE_BACKEND_DB=ON flag automatically enables -DWITH_MIGRATE=ON and links SQLite3.

Build docs developers (and LLMs) love