From 380e068df6445e8bd0523fc10991a53d82960738 Mon Sep 17 00:00:00 2001 From: gojimmypi Date: Fri, 20 Jun 2025 11:24:58 -0700 Subject: [PATCH] Introduce CMakePresets.json and CMakeSettings.json --- CMakePresets.json | 20 ++++++++++++++++++ CMakeSettings.json | 9 ++++++++ Makefile.am | 2 ++ cmake/README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 CMakePresets.json create mode 100644 CMakeSettings.json diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 000000000..4a03876fb --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,20 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 22, + "patch": 0 + }, + "configurePresets": [ + { + "name": "vs2022-x64", + "displayName": "Visual Studio 2022 x64", + "generator": "Visual Studio 17 2022", + "architecture": "x64", + "binaryDir": "${sourceDir}/build", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "ON" + } + } + ] +} diff --git a/CMakeSettings.json b/CMakeSettings.json new file mode 100644 index 000000000..d117d5307 --- /dev/null +++ b/CMakeSettings.json @@ -0,0 +1,9 @@ +{ + "configurations": [ + { + "name": "No-CMake", + "generator": "Ninja", + "buildCommandArgs": "echo 'No build command'" + } + ] +} diff --git a/Makefile.am b/Makefile.am index ba768ec35..63dbb3e02 100644 --- a/Makefile.am +++ b/Makefile.am @@ -156,6 +156,8 @@ EXTRA_DIST+= LPCExpresso.cproject EXTRA_DIST+= LPCExpresso.project EXTRA_DIST+= resource.h wolfssl.rc EXTRA_DIST+= CMakeLists.txt +EXTRA_DIST+= CMakePresets.json +EXTRA_DIST+= CMakeSettings.json EXTRA_DIST+= m4/ax_atomic.m4 include cmake/include.am diff --git a/cmake/README.md b/cmake/README.md index 04b3bf386..bb4efb4e3 100644 --- a/cmake/README.md +++ b/cmake/README.md @@ -5,3 +5,55 @@ This directory contains some supplementary functions for the [CMakeLists.txt](.. See also cmake notes in the [INSTALL](../INSTALL) documentation file. If new CMake build options are added `cmake/options.h.in` must also be updated. + +For more information on building wolfSSL, see the [wolfSSL Manual](https://www.wolfssl.com/documentation/manuals/wolfssl/). + +In summary for cmake: + +``` +# From the root of the wolfSSL repo: + +mkdir -p out +pushd out +cmake .. +cmake --build . + +# View the available ciphers with: +./examples/client/client -e +popd +``` + +## CMake Presets + +The `CMakePresets.json`; see [cmake-presets(https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html) + +- Cross-platform and cross-IDE. + +- Standardized CMake feature (since CMake 3.19+, recommended after 3.21). + +- Works in Visual Studio, VS Code, CLI, CI systems, etc.. + +## Visual Studio Settings + +There's also a Visual Studio specific file: `CMakeSettings.json`. This the file that supports the GUI CMake settings. + +See the Microsoft [CMakeSettings.json schema reference](https://learn.microsoft.com/en-us/cpp/build/cmakesettings-reference?view=msvc-170) + +## Visual Studio (2022 v17.1 and later): + +- Prefers `CMakePresets.json` if it exists. + +- Falls back to `CMakeSettings.json` if no presets are found. + +- Lets you override or extend presets via `CMakeSettings.json`. + +### Recommendations: + +- Use `CMakePresets.json` to define shared, cross-platform presets. + +- Use `CMakeSettings.json` to define Visual Studio-specific overrides, like: + * Custom output directories + * Specific environment variables + * *UI-related tweaks + +