Skip to content

Integrate OpenSSL as FetchContent-based CMake dependency which can be used with CPM.

License

Notifications You must be signed in to change notification settings

Klebert-Engineering/openssl-cmake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenSSL CMake FetchContent Integration

A cross-platform CMake module for building OpenSSL from source using FetchContent and ExternalProject.

Features

  • Cross-platform support: Windows, macOS, and Linux (x86_64 and ARM64)
  • Automatic dependency management: Uses CMake's FetchContent to download OpenSSL source
  • Static and shared library builds: Configurable via OPENSSL_SHARED option
  • Parallel builds: Automatically detects CPU cores for faster compilation
  • Standard CMake targets: Provides OpenSSL::SSL and OpenSSL::Crypto imported targets
  • CI/CD tested: GitHub Actions workflow tests builds across all supported platforms

Usage

Basic Usage

# REQUIRED: Set the OpenSSL version
set(OPENSSL_VERSION "openssl-3.5.1")  # or any other version tag

# Include the CMake module
include(path/to/CMakeLists.txt)

# Your targets can now link against OpenSSL
target_link_libraries(your_target OpenSSL::SSL OpenSSL::Crypto)

Configuration Options

OpenSSL Version (Required)

The OPENSSL_VERSION variable must be set before including the CMakeLists.txt. There is no default fallback:

set(OPENSSL_VERSION "openssl-3.4.0")  # Required - no default
include(path/to/CMakeLists.txt)

Static vs Shared Libraries

Control whether to build static or shared libraries using the OPENSSL_SHARED option:

set(OPENSSL_SHARED OFF)  # Default: OFF (static libraries)
# or
set(OPENSSL_SHARED ON)   # Build shared libraries (.dll/.so/.dylib)

set(OPENSSL_VERSION "openssl-3.5.1")
include(path/to/CMakeLists.txt)

Verbose Build Output

Control whether to see OpenSSL build output in real-time:

set(OPENSSL_VERBOSE ON)   # Default: ON (shows real-time output)
# or
set(OPENSSL_VERBOSE OFF)  # Quiet mode (logs to files only)

set(OPENSSL_VERSION "openssl-3.5.1")
include(path/to/CMakeLists.txt)

When OPENSSL_VERBOSE is ON (default), output is displayed directly to the console as the build progresses. When OFF, build output is logged to files in the build directory for later review.

Note: This doesn't work on Windows yet.

Requirements

  • CMake 3.14+
  • Perl (required for OpenSSL configuration)
  • NASM (Netwide Assembler) - required for OpenSSL builds
  • Platform-specific build tools:
    • Windows: Visual Studio with nmake (install jom for parallel builds)
    • macOS: Xcode Command Line Tools
    • Linux: GCC/Clang and make

Notes

  • The OPENSSL_VERSION variable is required and must be set before including the CMake module
  • Default build type is static libraries. Use OPENSSL_SHARED=ON for shared libraries
  • On Windows, shared builds will produce both .lib (import libraries) and .dll files

Windows: faster parallel builds (jom)

  • Install jom to parallelize the OpenSSL build step (nmake is single-threaded):
    choco install jom -y
  • After install, reconfigure your build. Our CMake will auto-detect jom and use jom -j<N> (where N is the detected core count or OPENSSL_JOBS if set).
  • For live output during builds, prefer the Ninja generator; MSBuild buffers ExternalProject output.

License

BSD 3-Clause License - see LICENSE file for details.

About

Integrate OpenSSL as FetchContent-based CMake dependency which can be used with CPM.

Resources

License

Stars

Watchers

Forks

Packages

No packages published