From e4b501153cfae02c31052366b2194ba8b9461483 Mon Sep 17 00:00:00 2001 From: neargye Date: Thu, 18 Apr 2019 14:27:35 +0500 Subject: [PATCH] enable tests and examples only if is top project --- CMakeLists.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ffde25f..b61479c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,14 @@ project(nameof VERSION "0.8.0" LANGUAGES CXX) -option(NAMEOF_OPT_BUILD_EXAMPLES "Build nameof examples" ON) -option(NAMEOF_OPT_BUILD_TESTS "Build and perform nameof tests" ON) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + set(IS_TOPLEVEL_PROJECT TRUE) +else() + set(IS_TOPLEVEL_PROJECT FALSE) +endif() + +option(NAMEOF_OPT_BUILD_EXAMPLES "Build nameof examples" ${IS_TOPLEVEL_PROJECT}) +option(NAMEOF_OPT_BUILD_TESTS "Build and perform nameof tests" ${IS_TOPLEVEL_PROJECT}) if(NAMEOF_OPT_BUILD_EXAMPLES) add_subdirectory(example)