Enable CMake policy CMP0077#2222
Enable CMake policy CMP0077#2222nlohmann merged 1 commit intonlohmann:developfrom alexreinking:patch-1
Conversation
Projects that import json via [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html) or `add_subdirectory` pointed at a git submodule may want to set `JSON_BuildTests` to "NO". However, this doesn't work without creating an identical `option()` in the importing project. Enabling CMP0077 in supported versions of CMake changes the behavior of `option()` to allow importing projects to set default values for the variables without touching the cache. See the documentation for CMP0077 here: https://cmake.org/cmake/help/latest/policy/CMP0077.html
|
@alexreinking Can you clarify why that is needed? I'm doing here and the JSON tests are not built and I also don't define these options. My cmake version is 3.15.2 on windows. |
|
The key is not touching the cache. The snippet you posted will no longer set JSON_BuildTests to OFF if I explicitly set it to "ON" in the cache. Additionally,
Without the policy, the following does not work, but should, and is the default behavior of CMake going forward: |
|
Thanks! |
🔖 Release itemThis issue/PR will be part of the next release of the library. This template helps preparing the release notes. Type
Description
|
|
@alexreinking Thanks for the clarification. Makes sense! |
Projects that import json via FetchContent or
add_subdirectorypointed at a git submodule may want to setJSON_BuildTeststo "NO". However, this doesn't work without creating an identicaloption()in the importing project. Enabling CMP0077 in CMake 3.13+ changes the behavior ofoption()to allow importing projects to set default values for the variables without touching the cache.See the documentation for CMP0077 here: https://cmake.org/cmake/help/latest/policy/CMP0077.html
Pull request checklist
Read the Contribution Guidelines for detailed information.
include/nlohmanndirectory, runmake amalgamateto create the single-header filesingle_include/nlohmann/json.hpp. The whole process is described here.