From e6d262872390f3ee1ba93362d9ee7a142acf72d9 Mon Sep 17 00:00:00 2001 From: cobyj33 Date: Tue, 31 Oct 2023 21:09:12 -0500 Subject: [PATCH] Set argparse to not run tests or set up install if not top level --- CMakeLists.txt | 15 +++++++++++---- README.md | 2 -- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 91463f8..38bf1bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,11 @@ 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 VERSION 2.9.0 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_BUILD_TESTS "Build tests" ON) +option(ARGPARSE_BUILD_SAMPLES "Build samples" OFF) include(GNUInstallDirs) include(CMakePackageConfigHelpers) @@ -24,12 +31,12 @@ target_include_directories(argparse INTERFACE if(ARGPARSE_BUILD_SAMPLES) add_subdirectory(samples) endif() - -if(ARGPARSE_BUILD_TESTS) + +if(ARGPARSE_BUILD_TESTS AND ARGPARSE_IS_TOP_LEVEL) add_subdirectory(test) endif() - -if(ARGPARSE_INSTALL) + +if(ARGPARSE_INSTALL AND ARGPARSE_IS_TOP_LEVEL) install(TARGETS argparse EXPORT argparseConfig) install(EXPORT argparseConfig NAMESPACE argparse:: diff --git a/README.md b/README.md index 44b0cdf..64b9236 100644 --- a/README.md +++ b/README.md @@ -1179,8 +1179,6 @@ PROJECT(myproject) # fetch latest argparse 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( argparse GIT_REPOSITORY https://github.com/p-ranav/argparse.git