-
-
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
Make nlohmann friendly for inclusion. #1266
Conversation
I'm a bit confused as to the problem this is trying to solve. When would PROJECT_SOURCE_DIR not be the same as CMAKE_CURRENT_LIST_DIR in the top level CMake? The usual way to add a third party CMake library to another CMake project is via We (at kitware) are currently using this as a third party library via find_package for external or add_subdirectory for internal, without issue. So what doesn't work that this is trying to fix? It wasn't really clear what doesn't work since you should be abel to do the following as is without changing anything:
...
add_subdirectory(3rdParty)
...
add_subdirectory(src)
...
...
find_package(nlohmann_json 3.2.0 QUIET)
if(nlohmann_json_FOUND)
message(STATUS "Nlohmann JSON found externally.")
else()
message(STATUS "Nlohmann JSON not found externally; will use included version.")
add_subdirectory(json)
endif()
# Set any project specific options for nlohmann_json
set(BUILD_TESTING OFF)
add_subdirectory(nlohmann_json)
...
# The nlohmann_json::nlohmann_json target will always be there since via find_package
# the target is already namespaced and if built internally then the
# nlohmann_json::nlohmann_json target is added as an alias to nlohmann_json.
target_link_libraries(performous PRIVATE nlohmann_json::nlohmann_json)
...
This should work as a third party library infrastructure in general with each |
@chuckatkins what it's trying to solve is it not working via include(), which is a valid choice AFAIK. Either way, the way I see it... it's perhaps an unusual way to do things but it's a couple lines of code that doesn't affect "normal" usage and makes the Cmake script more robust. |
Using project(foo ...)
# PROJECT_<...> variables set correctly for the foo project
include(3rdParty/json/CMakeLists.txt)
# PROJECT_<...> variables now set to the values from nlohmann_json There should probably be better documentation in CMake for some of these implications and to suggest not to add additional cmake projects in that way. This is somewhat conveyed in the docs for the
Which essentially says that |
I have little experience with CMake and trust @chuckatkins in this regard. To my understanding, the PR would add a fix to support a discouraged way of including the library. If this is the case, then I'd rather not have the PR merged, especially as #1260 added a comment https://github.com/nlohmann/json#integration on how to use CMake for the library. |
[Describe your pull request here. Please read the text below the line, and make sure you follow the checklist.]
New PR for #1250
The one change I haven't tested is the natvis bit because I don't have an MSVC system on hand. Other than that, I tried installing regularly, running the tests and including my way and it worked as expected.
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.Please don't
#ifdef
s or other means.