Merge pull request #298 from cobyj33/cobyj33-fix-subdirectory-cmake-options

Set argparse to not run tests or set up install if not top level
This commit is contained in:
Pranav 2023-11-01 06:13:02 -05:00 committed by GitHub
commit ac4c578f60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -1,5 +1,11 @@
cmake_minimum_required(VERSION 3.12.4) cmake_minimum_required(VERSION 3.12.4)
if(NOT DEFINED PROJECT_NAME)
set(ARGPARSE_IS_TOP_LEVEL ON)
else()
set(ARGPARSE_IS_TOP_LEVEL OFF)
endif()
project(argparse project(argparse
VERSION 2.9.0 VERSION 2.9.0
DESCRIPTION "A single header argument parser for C++17" DESCRIPTION "A single header argument parser for C++17"
@ -9,6 +15,7 @@ project(argparse
option(ARGPARSE_INSTALL "Include an install target" ON) option(ARGPARSE_INSTALL "Include an install target" ON)
option(ARGPARSE_BUILD_TESTS "Build tests" ON) option(ARGPARSE_BUILD_TESTS "Build tests" ON)
option(ARGPARSE_BUILD_SAMPLES "Build samples" OFF)
include(GNUInstallDirs) include(GNUInstallDirs)
include(CMakePackageConfigHelpers) include(CMakePackageConfigHelpers)
@ -25,11 +32,11 @@ if(ARGPARSE_BUILD_SAMPLES)
add_subdirectory(samples) add_subdirectory(samples)
endif() endif()
if(ARGPARSE_BUILD_TESTS) if(ARGPARSE_BUILD_TESTS AND ARGPARSE_IS_TOP_LEVEL)
add_subdirectory(test) add_subdirectory(test)
endif() endif()
if(ARGPARSE_INSTALL) if(ARGPARSE_INSTALL AND ARGPARSE_IS_TOP_LEVEL)
install(TARGETS argparse EXPORT argparseConfig) install(TARGETS argparse EXPORT argparseConfig)
install(EXPORT argparseConfig install(EXPORT argparseConfig
NAMESPACE argparse:: NAMESPACE argparse::

View File

@ -1179,8 +1179,6 @@ PROJECT(myproject)
# fetch latest argparse # fetch latest argparse
include(FetchContent) include(FetchContent)
set(ARGPARSE_BUILD_TESTS OFF CACHE INTERNAL "Turn off building argparse tests")
set(ARGPARSE_BUILD_SAMPLES OFF CACHE INTERNAL "Turn off building argparse samples")
FetchContent_Declare( FetchContent_Declare(
argparse argparse
GIT_REPOSITORY https://github.com/p-ranav/argparse.git GIT_REPOSITORY https://github.com/p-ranav/argparse.git