From 7b1b7ee16d86acdb5207966401dccbb28b849475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Blissing?= Date: Sat, 19 Jun 2021 12:51:27 +0200 Subject: [PATCH] Reverted to use of global BUILD_SHARED_LIBS option This commit reverts back to exposing the global variable BUILD_SHARED_LIBS. Since building static libraries are the default for CMake (i.e. BUILD_SHARED_LIBS=OFF) the option to build both static and shared libraries were moved into a conditional option. So the option PUGIXML_BUILD_SHARED_AND_STATIC is now only visible when the global BUILD_SHARED_LIBS variable is set to ON. The change also prevents the case were the user first enables BUILD_SHARED_LIBS and then enables PUGIXML_BUILD_SHARED_AND_STATIC to then again disable BUILD_SHARED_LIBS. --- CMakeLists.txt | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a9e1c3..3fd0c77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,12 +27,13 @@ cmake_dependent_option(PUGIXML_BUILD_TESTS set(PUGIXML_BUILD_DEFINES CACHE STRING "Build defines for custom options") separate_arguments(PUGIXML_BUILD_DEFINES) -option(PUGIXML_BUILD_SHARED_AND_STATIC_LIBS "Build both shared and static libraries" OFF) - - # Expose option to build PUGIXML as static even when the global BUILD_SHARED_LIBS variable is set -cmake_dependent_option(PUGIXML_BUILD_SHARED_LIBS - "Build shared instead of static library" OFF - "BUILD_SHARED_LIBS" ON) +# Technically not needed for this file. This is builtin CMAKE global variable. +option(BUILD_SHARED_LIBS "Build shared instead of static library" OFF) + +# Expose option to build PUGIXML as static as well when the global BUILD_SHARED_LIBS variable is set +cmake_dependent_option(PUGIXML_BUILD_SHARED_AND_STATIC_LIBS + "Build both shared and static libraries" OFF + "BUILD_SHARED_LIBS" OFF) # This is used to backport a CMake 3.15 feature, but is also forwards compatible if (NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY) @@ -73,7 +74,7 @@ set(versioned-dir $<$:/pugixml-${PROJECT_V set(libs) -if (PUGIXML_BUILD_SHARED_LIBS OR PUGIXML_BUILD_SHARED_AND_STATIC_LIBS) +if (BUILD_SHARED_LIBS) add_library(pugixml-shared SHARED ${PROJECT_SOURCE_DIR}/scripts/pugixml_dll.rc ${PROJECT_SOURCE_DIR}/src/pugixml.cpp) @@ -97,7 +98,7 @@ if (PUGIXML_BUILD_SHARED_LIBS OR PUGIXML_BUILD_SHARED_AND_STATIC_LIBS) ${msvc-rt-mt-static}) endif() -if (NOT PUGIXML_BUILD_SHARED_LIBS OR PUGIXML_BUILD_SHARED_AND_STATIC_LIBS) +if (NOT BUILD_SHARED_LIBS OR PUGIXML_BUILD_SHARED_AND_STATIC_LIBS) add_library(pugixml-static STATIC ${PROJECT_SOURCE_DIR}/src/pugixml.cpp) add_library(pugixml::static ALIAS pugixml-static) @@ -118,7 +119,7 @@ if (NOT PUGIXML_BUILD_SHARED_LIBS OR PUGIXML_BUILD_SHARED_AND_STATIC_LIBS) ${msvc-rt-mt-static}) endif() -if (PUGIXML_BUILD_SHARED_LIBS) +if (BUILD_SHARED_LIBS) set(pugixml-alias pugixml-shared) else() set(pugixml-alias pugixml-static)