From 7059b37ac1eb67c78d5fb57152f5e4835595aa5a Mon Sep 17 00:00:00 2001 From: Tessil Date: Fri, 31 Mar 2023 16:39:23 +0100 Subject: [PATCH] Add a CMake TSL_ROBIN_MAP_ENABLE_INSTALL option to explicitly enable/disable the install target --- CMakeLists.txt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e79537..73d9cc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,15 @@ project(tsl-robin-map VERSION 1.2.1 LANGUAGES CXX) include(GNUInstallDirs) +set(IS_MAIN_PROJECT FALSE) +if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + set(IS_MAIN_PROJECT TRUE) +endif() + +# Enable the install target if the project is used main project (disable by default if subproject) +option(TSL_ROBIN_MAP_ENABLE_INSTALL "Enable install target" ${IS_MAIN_PROJECT}) + + add_library(robin_map INTERFACE) # Use tsl::robin_map as target, more consistent with other libraries conventions (Boost, Qt, ...) add_library(tsl::robin_map ALIAS robin_map) @@ -25,16 +34,8 @@ if(MSVC) "$") endif() - - - -set(IS_SUBPROJECT TRUE) -if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) - set(IS_SUBPROJECT FALSE) -endif() - # Installation -if(NOT IS_SUBPROJECT) +if(TSL_ROBIN_MAP_ENABLE_INSTALL) include(CMakePackageConfigHelpers) ## Install include directory and potential natvis file