Set argparse to not run tests or set up install if not top level #298
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request comes as a way to make sure users including argparse through FetchContent or through a direct add_subdirectory() call won't have argparse tests built or the argparse install commands configured by default.
Concerning not using the cmake provided PROJECT_IS_TOP_LEVEL variable, PROJECT_IS_TOP_LEVEL is not used because it has a required minimum cmake version of 3.21 while argparse uses a minimum cmake version of 3.12.4.
This approach is largely based on the way Catch2 handles this same condition (Lines 5-9) in their CMakeLists.txt, as well as this issue which references to glitchy installs when setting install targets in a subdirectory CMake structure.
While the user will have to use FetchContent after their project call, this is also how the official PROJECT_IS_TOP_LEVEL handles detecting subdirectory projects, so I don't see this as much of a concern.
Also, I removed the manual setting of ARGPARSE_BUILD_TESTS and ARGPARSE_BUILD_SAMPLES from the FetchContent section of the README, as they are not necessary as ARGPARSE_BUILD_SAMPLES defaults to OFF and test building will now not be run if argparse is not the top level project.
ARGPARSE_BUILD_SAMPLES was also officially declared as an option, as well as initialized to OFF to maintain previous behavior.