From b41b79a8e57a73f27ba9754d62c047425ac94d1f Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Wed, 25 Oct 2023 11:50:07 +0100 Subject: [PATCH] CMake: Add backport of `PROJECT_IS_TOP_LEVEL` for CMake <3.21 --- CMakeLists.txt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac0326d119..b070048eff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ # Set Project Properties ################################## -cmake_minimum_required(VERSION 3.21.0) +cmake_minimum_required(VERSION 3.12.0) #Project Name project(netCDF @@ -16,6 +16,14 @@ DESCRIPTION "NetCDF is a set of software libraries and machine-independent data ) set(PACKAGE "netCDF" CACHE STRING "") +# Backport of built-in `PROJECT_IS_TOP_LEVEL` from CMake 3.21 +if (NOT DEFINED NETCDF_IS_TOP_LEVEL) + set(NETCDF_IS_TOP_LEVEL OFF) + if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + set(NETCDF_IS_TOP_LEVEL ON) + endif () +endif () + ##### # Version Info: # @@ -2787,6 +2795,8 @@ install( #### # CPack inclusion must come last. -if (PROJECT_IS_TOP_LEVEL) +option(NETCDF_PACKAGE "Create netCDF-C package " ${NETCDF_IS_TOP_LEVEL}) + +if (NETCDF_PACKAGE) include(CMakeInstallation.cmake) endif()