wolfSSL Buildfest 2026: cmake

When your application already uses CMake, or when you want one build description that works across Linux, macOS, Windows, and cross-compilers, wolfSSL’s CMake build lets you configure, build, test, install, and consume wolfSSL with standard CMake tooling.

Instead of running ./configure, you select features with -DWOLFSSL_=yes|no cache options. CMake then generates its own wolfssl/options.h in the build directory, recording the configuration so that your application sees exactly what the library was built with.

When should I use CMake?


Use CMake when:

  • Your application is already built with CMake.
  • You want to pull wolfSSL in with add_subdirectory() or FetchContent.
  • You want to consume an installed wolfSSL with find_package(wolfssl).
  • You are building on Windows and want an alternative to the Visual Studio solution files.
  • You want an IDE that understands CMake natively (Visual Studio, VS Code, CLion).

How does the CMake build work?


wolfSSL’s CMakeLists.txt defines a cache option for each feature. When you configure, CMake translates those options into C preprocessor defines and writes them to:

/wolfssl/options.h

The template for that header is cmake/options.h.in.

The wolfssl target exports its include directories, so any target that links to it automatically sees both the wolfSSL headers and the generated options.h.

Your application should include:

#include 

before including any other wolfSSL header.

A typical project therefore looks like:

my-project/
├── CMakeLists.txt
├── src/
└── third_party/
    └── wolfssl/

or wolfSSL is installed separately and found with find_package().

Step 1: Configure


From the root of the wolfSSL source tree:

cmake -B build -DWOLFSSL_TLS13=yes -DWOLFSSL_CURVE25519=yes -DWOLFSSL_SNI=yes -DWOLFSSL_ALPN=yes

In-source builds are rejected, so always use a separate build directory.

To see every available option:

cmake -B build -LH

The option naming rule is simple:

Autotools CMake
–enable-foo -DWOLFSSL_FOO=yes
–disable-foo -DWOLFSSL_FOO=no

Standard CMake options also apply:

-DCMAKE_BUILD_TYPE=Debug|Release
-DBUILD_SHARED_LIBS=ON|OFF
-DWOLFSSL_EXAMPLES=no
-DWOLFSSL_CRYPT_TESTS=no

wolfSSL requires CMake 3.16 or later.

Step 2: Build and test


cmake --build build
ctest --test-dir build --output-on-failure

ctest runs the wolfCrypt self-tests and the TLS unit tests.

Step 3: Install (optional)


cmake --install build

This installs the library, headers (including the generated options.h), and CMake package files so other projects can use find_package(wolfssl).

Step 4: Use wolfSSL from your application


Installed package

find_package(wolfssl CONFIG REQUIRED)
add_executable(myapp main.c)
target_link_libraries(myapp PRIVATE wolfssl::wolfssl)

A working example lives in:

wolfssl/cmake/consumer/

Autotools installs also provide these CMake package files, so find_package(wolfssl) works whichever way wolfSSL was installed.

Embedded source tree

set(WOLFSSL_EXAMPLES no CACHE STRING "" FORCE)
set(WOLFSSL_CRYPT_TESTS no CACHE STRING "" FORCE)
add_subdirectory(third_party/wolfssl)
target_link_libraries(myapp PRIVATE wolfssl)

FetchContent works the same way.
In your source:

#include 
#include 

Why use CMake options instead of adding raw defines?


You generally should not add wolfSSL feature defines with add_compile_definitions() or CMAKE_C_FLAGS.

CMake options give you:

  • Correct dependency handling between features
  • A generated options.h that exactly matches the library
  • Configuration that propagates to consumers through the wolfssl target
  • The same option names whether you build standalone or embedded
  • Parity with the Autotools options and defaults

Presets and Visual Studio


The wolfSSL source tree includes CMakePresets.json with a vs2022-x64 preset. It uses the Visual Studio 2022 generator, so it applies to Windows only. Visual Studio picks it up automatically, or from a Windows command line:

cmake --preset vs2022-x64

On other hosts, cmake –list-presets shows nothing because the generator isn’t available there. Use cmake –list-presets=all to see it anyway.

CMakeSettings.json is also provided for Visual Studio-specific overrides. See cmake/README.md for details.

A common mistake: configuring the library and application differently


One of the most common wolfSSL build problems is a mismatch between the configuration used to compile the wolfSSL library and the configuration used by the application.

For example, if the library was built with -DWOLFSSL_OPENSSLEXTRA=yes but the application does not include options.h, structures can have different layouts in the library and the application. The build succeeds, but the program crashes or corrupts memory at runtime.

The application and wolfSSL library need to use the same configuration.

Link to the wolfssl (or wolfssl::wolfssl) target rather than hard-coding include paths, and include first.

A second, CMake-specific trap: a stale wolfssl/options.h left in the source tree by an earlier ./configure can shadow the one CMake generated in the build tree. wolfSSL’s CMake removes it automatically, but check for it if you see confusing results.

What about user_settings.h?


CMake supports user_settings.h.

Configure with:

cmake -B build -DWOLFSSL_USER_SETTINGS=yes

This drops all of CMake’s own feature defines and uses only -DWOLFSSL_USER_SETTINGS. Your user_settings.h must be on the include path. Either:

  • place it in the root of the wolfSSL source tree, or
  • add its directory to both the C and assembly flags, since wolfSSL also compiles .S assembly files that include settings.h:
cmake -B build -DWOLFSSL_USER_SETTINGS=yes \
    -DCMAKE_C_FLAGS="-I/path/to/config" \
    -DCMAKE_ASM_FLAGS="-I/path/to/config"

CMake always defines WOLFSSL_IGNORE_FILE_WARN on the command line. Many of the example configurations in examples/configs/ also #define WOLFSSL_IGNORE_FILE_WARN, which triggers a “redefined” error under the default -Werror. Guard it in your user_settings.h:

#undef  WOLFSSL_IGNORE_FILE_WARN
#define WOLFSSL_IGNORE_FILE_WARN

This is useful when the same user_settings.h is shared with an embedded IDE build.

Quick troubleshooting checklist


If your CMake build isn’t behaving the way you expect, check these first:

  1. Are you building out of source (cmake -B build)?
  2. Did you reconfigure after changing options? Delete build/CMakeCache.txt if a cached value sticks.
  3. Does your application include before other wolfSSL headers?
  4. Is your target linked to wolfssl / wolfssl::wolfssl, so it inherits the right include directories?
  5. Is find_package() picking up the install you intended? Check wolfssl_DIR in the cache.
  6. Is a stale wolfssl/options.h from an Autotools build sitting in the source tree?
  7. Using WOLFSSL_USER_SETTINGS? Is user_settings.h visible to assembly files too, and is WOLFSSL_IGNORE_FILE_WARN guarded with #undef?
  8. Does ctest –test-dir build pass for this configuration?

If you have questions about any of the above, please contact us at facts@wolfssl.com or call us at +1 425 245 8247.

Download wolfSSL Now