Build OpenSSL in parallel within CMake
- Support OpenSSL versions from
1.1.1
to the latest3.4.x
- Detect the target platform (
Linux
,macOS
,Windows
,Android
,iOS
, and more) - Download the source code only once (thanks CPM.cmake!)
- Don't reconfigure if same options are used
- Automatically use the maximum number of processors
- Reduce rebuild time using ccache
- Override the
FindOpenSSL
CMake module (no need to change existing CMake code)
Option | Type | Default | Description |
---|---|---|---|
OPENSSL_BUILD_OPTIONS |
list | (undefined) |
make -compatible options |
OPENSSL_BUILD_TARGET |
string | build_libs |
Makefile target for build |
OPENSSL_BUILD_VERBOSE |
bool | OFF |
Enable verbose output from build |
OPENSSL_CONFIGURE_OPTIONS |
list | (undefined) |
Use OpenSSL's Configure options |
OPENSSL_CONFIGURE_VERBOSE |
bool | OFF |
Enable verbose output from configuration |
OPENSSL_ENABLE_PARALLEL |
bool | ON |
Build and test in parallel if possible |
OPENSSL_INSTALL |
bool | OFF |
Install OpenSSL components |
OPENSSL_INSTALL_CERT |
bool | OFF |
Install cert.pem to the openssldir directory |
OPENSSL_INSTALL_TARGET |
string | install_dev |
Makefile target for install |
OPENSSL_PATCH |
list | (undefined) |
Apply patches to OpenSSL source |
OPENSSL_SOURCE |
path | (undefined) |
Specify the location of OpenSSL source (URL or path) |
OPENSSL_TARGET_PLATFORM |
string | (undefined) |
Use OpenSSL's Configure target (see below) |
OPENSSL_TARGET_VERSION |
string | 3.4.x |
Use the latest OpenSSL version by default |
OPENSSL_TEST |
bool | OFF |
Enable testing and build OpenSSL self tests |
OPENSSL_USE_CCACHE |
bool | ON |
Use ccache if available |
Important
OPENSSL_PATCH
- Since OpenSSL source is distributed with
LF
, patch files also should beLF
- Since OpenSSL source is distributed with
OPENSSL_USE_CCACHE
- Whenever you change this option, perform a fresh configuration (or just delete
CMakeCache.txt
) - This option will remove
/Zi /Fd
on MSVC
- Whenever you change this option, perform a fresh configuration (or just delete
Note
OPENSSL_CONFIGURE_OPTIONS
no-shared
is added whenBUILD_SHARED_LIBS
isOFF
no-tests
is added whenOPENSSL_TEST
isOFF
OPENSSL_TARGET_PLATFORM
- If this option is empty, the target platform will be detected
- If
openssl-cmake
fails to detect, you need to set this option explicitly
Tip
OPENSSL_INSTALL
- To change the installation path, add
--prefix=<path>
toOPENSSL_CONFIGURE_OPTIONS
- To change the installation path, add
OPENSSL_INSTALL_CERT
- The CA certs will be downloaded from https://curl.se/docs/caextract.html
OPENSSL_SOURCE
- You can download OpenSSL source from the internet or use the local OpenSSL source
- If this option is empty or invalid, OpenSSL source will be downloaded from the official website
- CMake 3.25+
- OpenSSL build tools Link
- Make implementation
- Perl 5
- ANSI C compiler
- NASM (Windows only)
- ccache (optional)
Install CMake from official website or Snapcraft
# Debian
sudo snap install cmake --classic
sudo apt-get install -y build-essential perl ninja-build ccache
Install packages from Homebrew
brew install cmake perl ninja ccache
xcode-select --install
Install packages from Chocolatey
# Powershell (run as administrator)
choco install -y cmake jom strawberryperl nasm ccache --installargs 'ADD_CMAKE_TO_PATH=System'
# Append "C:\Program Files\NASM" to the PATH environment variable
# or run this code
[Environment]::SetEnvironmentVariable("PATH", "$ENV:PATH;C:\Program Files\NASM", "USER")
cmake --list-presets all # List all CMake presets
cmake --preset windows # Configure
cmake --build --preset windows # Build
ctest --preset windows # Test
cmake --build --preset windows -t install # Install
FetchContent_Declare(
openssl-cmake
URL https://github.com/jimmy-park/openssl-cmake/archive/main.tar.gz
)
FetchContent_MakeAvailable(openssl-cmake)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE
OpenSSL::SSL
OpenSSL::Crypto
OpenSSL::applink
)
Important
FetchContent_MakeAvailable(openssl-cmake)
must be preceded beforefind_package(OpenSSL)
- If some libraries link OpenSSL using
OPENSSL_LIBRARIES
variable rather thanOpenSSL::SSL
target,add_dependencies()
may help change the build order
Using CPM.cmake
CPMAddPackage(
NAME openssl-cmake
URL https://github.com/jimmy-park/openssl-cmake/archive/main.tar.gz
OPTIONS
"OPENSSL_CONFIGURE_OPTIONS no-shared\\\\;no-tests"
)
Tip
For some reason, CPM requires double-escaping for semicolon-separated lists.
Configuration | Time | Speed |
---|---|---|
Sequential | 168 s | 1.00 x |
Sequential w/ ccache (cold) | 460 s | 0.37 x |
Sequential w/ ccache (warm) | 111 s | 1.51 x |
Parallel | 34 s | 4.94 x |
Parallel w/ ccache (cold) | 78 s | 2.15 x |
Parallel w/ ccache (warm) | 21 s | 8.00 x |
- OS : Windows 10 22H2
- CPU : AMD Ryzen 5 3600 6-Core Processor 3.60 GHz
- RAM : 16 GB
- Storage : Samsung SSD 860 EVO
- Compiler : MSVC 19.36
- Configuration
- OpenSSL 3.1.1 (
VC-WIN64A
,no-tests
,no-asm
,no-makedepend
,no-shared
) - ccache 4.8.1 (default options)
- OpenSSL 3.1.1 (
Tip
There are benchmark workflows