From f49793bb9e91261891853af14a4d494f5f00f7a7 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Thu, 25 May 2023 13:56:00 +0200 Subject: [PATCH] Use the common CMake BUILD_SHARED_LIBS to build shared library or not https://cmake.org/cmake/help/v3.0/variable/BUILD_SHARED_LIBS.html Usually it's built-in but make sure we have it on by default. We don't need to rename the windows static library when it's the only one built. This will also allow proper usage of the pkg-config file in this case. Otherwise there is no way to select the static library that way. --- CMakeLists.txt | 2 ++ libarchive/CMakeLists.txt | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f4abc3ed..0ca7eb694 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -199,6 +199,8 @@ ENDIF (MSVC) # Enable CTest/CDash support include(CTest) +option(BUILD_SHARED_LIBS "Build shared libraries" ON) + OPTION(ENABLE_MBEDTLS "Enable use of mbed TLS" OFF) OPTION(ENABLE_NETTLE "Enable use of Nettle" OFF) OPTION(ENABLE_OPENSSL "Enable use of OpenSSL" ON) diff --git a/libarchive/CMakeLists.txt b/libarchive/CMakeLists.txt index ff7ade006..f7fdfb68a 100644 --- a/libarchive/CMakeLists.txt +++ b/libarchive/CMakeLists.txt @@ -243,10 +243,12 @@ ELSEIF(ARCHIVE_ACL_SUNOS) ENDIF() # Libarchive is a shared library -ADD_LIBRARY(archive SHARED ${libarchive_SOURCES} ${include_HEADERS}) -TARGET_INCLUDE_DIRECTORIES(archive PUBLIC .) -TARGET_LINK_LIBRARIES(archive ${ADDITIONAL_LIBS}) -SET_TARGET_PROPERTIES(archive PROPERTIES SOVERSION ${SOVERSION}) +IF(BUILD_SHARED_LIBS) + ADD_LIBRARY(archive SHARED ${libarchive_SOURCES} ${include_HEADERS}) + TARGET_INCLUDE_DIRECTORIES(archive PUBLIC .) + TARGET_LINK_LIBRARIES(archive ${ADDITIONAL_LIBS}) + SET_TARGET_PROPERTIES(archive PROPERTIES SOVERSION ${SOVERSION}) +ENDIF(BUILD_SHARED_LIBS) # archive_static is a static library ADD_LIBRARY(archive_static STATIC ${libarchive_SOURCES} ${include_HEADERS}) @@ -254,13 +256,19 @@ TARGET_LINK_LIBRARIES(archive_static ${ADDITIONAL_LIBS}) SET_TARGET_PROPERTIES(archive_static PROPERTIES COMPILE_DEFINITIONS LIBARCHIVE_STATIC) # On Posix systems, libarchive.so and libarchive.a can co-exist. -IF(NOT WIN32 OR CYGWIN) +IF(NOT WIN32 OR CYGWIN OR NOT BUILD_SHARED_LIBS) SET_TARGET_PROPERTIES(archive_static PROPERTIES OUTPUT_NAME archive) -ENDIF(NOT WIN32 OR CYGWIN) +ENDIF(NOT WIN32 OR CYGWIN OR NOT BUILD_SHARED_LIBS) IF(ENABLE_INSTALL) # How to install the libraries - INSTALL(TARGETS archive archive_static + IF(BUILD_SHARED_LIBS) + INSTALL(TARGETS archive + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) + ENDIF(BUILD_SHARED_LIBS) + INSTALL(TARGETS archive_static RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) -- 2.47.2