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
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ cmake_minimum_required(VERSION 3.1)
##
project(nlohmann_json VERSION 3.9.1 LANGUAGES CXX)

##
## MAIN_PROJECT CHECK
globberwops marked this conversation as resolved.
Show resolved Hide resolved
## determine if nlohmann_json is built as a subproject (using add_subdirectory) or if it is the main project
##
set(MAIN_PROJECT OFF)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(MAIN_PROJECT ON)
endif()

##
## INCLUDE
##
Expand All @@ -21,8 +30,8 @@ if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif ()

option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ON)
option(JSON_Install "Install CMake targets during install step." ON)
option(JSON_BuildTests "Build the unit tests when BUILD_TESTING is enabled." ${MAIN_PROJECT})
option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT})
option(JSON_MultipleHeaders "Use non-amalgamated version of the library." OFF)
option(JSON_ImplicitConversions "Enable implicit conversions." ON)

Expand Down Expand Up @@ -101,9 +110,8 @@ CONFIGURE_FILE(
## TESTS
## create and configure the unit test target
##
include(CTest) #adds option BUILD_TESTING (default ON)

if(BUILD_TESTING AND JSON_BuildTests)
if (JSON_BuildTests)
include(CTest) #adds option BUILD_TESTING (default ON)
globberwops marked this conversation as resolved.
Show resolved Hide resolved
enable_testing()
add_subdirectory(test)
endif()
Expand Down