Skip to content
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

Add MAIN_PROJECT check for test and install options #2514

Merged
merged 4 commits into from
Dec 14, 2020
Merged

Add MAIN_PROJECT check for test and install options #2514

merged 4 commits into from
Dec 14, 2020

Conversation

globberwops
Copy link
Contributor

@globberwops globberwops commented Dec 9, 2020

This resolves #2513 by checking if this is the main project in a CMake project tree.
JSON_BuildTests and JSON_Install will only be set to ON if this is the main project.
CTest will only be included, if JSON_BuildTests is set to ON.
BUILD_TESTING will therefore only be set, if this is the main project.

Pull request checklist

Read the Contribution Guidelines for detailed information.

  • Changes are described in the pull request, or an existing issue is referenced.
  • The test suite compiles and runs without error.
  • Code coverage is 100%. Test cases can be added by editing the test suite.
  • The source code is amalgamated; that is, after making changes to the sources in the include/nlohmann directory, run make amalgamate to create the single-header file single_include/nlohmann/json.hpp. The whole process is described here.

@coveralls
Copy link

coveralls commented Dec 9, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling ea759d0 on globberwops:develop into d8d8cbf on nlohmann:develop.

@hac01
Copy link

hac01 commented Dec 10, 2020

Can you teach me c++

@YarikTH
Copy link
Contributor

YarikTH commented Dec 12, 2020

For reference, here is the same purpose code from {fmt}

# Determine if fmt is built as a subproject (using add_subdirectory)
# or if it is the master project.
set(MASTER_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
  set(MASTER_PROJECT ON)
  message(STATUS "CMake version: ${CMAKE_VERSION}")
endif ()
...
...
...
# Options that control generation of various targets.
option(FMT_DOC "Generate the doc target." ${MASTER_PROJECT})
option(FMT_INSTALL "Generate the install target." ${MASTER_PROJECT})
option(FMT_TEST "Generate the test target." ${MASTER_PROJECT})
option(FMT_FUZZ "Generate the fuzz target." OFF)
option(FMT_CUDA_TEST "Generate the cuda-test target." OFF)
option(FMT_OS "Include core requiring OS (Windows/Posix) " ON)

So it might be a good idea at least copy explanatory comment and maybe use CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR check instead of CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR.

CMakeLists.txt Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
Copy link
Owner

@nlohmann nlohmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A last change request, otherwise looks good to me.

Copy link
Owner

@nlohmann nlohmann left a 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.

@nlohmann nlohmann merged commit 2fc1f69 into nlohmann:develop Dec 14, 2020
@nlohmann
Copy link
Owner

Thanks!

@globberwops
Copy link
Contributor Author

@nlohmann Thank you 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Including CTest in the top-level CMakeLists.txt sets BUILD_TESTING=ON for parent projects
5 participants