-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable CMake policy CMP0077 #2222
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:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
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_subdirectory
pointed at a git submodule may want to setJSON_BuildTests
to "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/nlohmann
directory, runmake amalgamate
to create the single-header filesingle_include/nlohmann/json.hpp
. The whole process is described here.