From b29b52eaaade4fbbd483173107f9c42e4ecfd707 Mon Sep 17 00:00:00 2001 From: Ivan Zhakov Date: Sat, 14 Sep 2024 15:50:07 +0000 Subject: [PATCH] CMake: Use single target for shared and static build (libaprutil-1) but keep different output name: libapr-1.lib for shared build and apr-1.lib for static build. git-svn-id: https://svn.apache.org/repos/asf/apr/apr-util/branches/1.7.x@1920637 13f79535-47bb-0310-9956-ffa450edef68 --- CMakeLists.txt | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb09871c..41748c62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -302,27 +302,30 @@ IF(NOT APU_DSO_BUILD AND APU_HAVE_SQLITE3) LIST(APPEND APU_EXTRA_LIBRARIES ${SQLite3_LIBRARIES}) ENDIF() -# libaprutil-1 is shared, aprutil-1 is static +ADD_LIBRARY(libaprutil-1 ${APR_SOURCES} ${APU_EXTRA_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED}) +LIST(APPEND install_targets libaprutil-1) +TARGET_LINK_LIBRARIES(libaprutil-1 + PRIVATE ${XMLLIB_LIBRARIES} ${APU_EXTRA_LIBRARIES}) +TARGET_INCLUDE_DIRECTORIES(libaprutil-1 + PRIVATE ${APU_EXTRA_INCLUDE_DIRECTORIES}) +TARGET_COMPILE_DEFINITIONS(libaprutil-1 + PRIVATE "XML_STATIC") + IF(BUILD_SHARED_LIBS) - ADD_LIBRARY(libaprutil-1 SHARED ${APR_SOURCES} ${APU_EXTRA_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED} libaprutil.rc) - LIST(APPEND install_targets libaprutil-1) LIST(APPEND install_bin_pdb $) + TARGET_SOURCES(libaprutil-1 PRIVATE libaprutil.rc) TARGET_LINK_LIBRARIES(libaprutil-1 - PRIVATE apr::libapr-1 ${XMLLIB_LIBRARIES} ${APU_EXTRA_LIBRARIES}) - TARGET_INCLUDE_DIRECTORIES(libaprutil-1 - PRIVATE ${APU_EXTRA_INCLUDE_DIRECTORIES}) + PRIVATE apr::libapr-1) TARGET_COMPILE_DEFINITIONS(libaprutil-1 - PRIVATE "APU_DECLARE_EXPORT;XML_STATIC" + PRIVATE "APU_DECLARE_EXPORT" INTERFACE "APU_DECLARE_IMPORT") ELSE() - ADD_LIBRARY(aprutil-1 STATIC ${APR_SOURCES} ${APU_EXTRA_SOURCES} ${APR_PUBLIC_HEADERS_GENERATED}) - LIST(APPEND install_targets aprutil-1) - TARGET_LINK_LIBRARIES(aprutil-1 - PRIVATE apr::apr-1 ${XMLLIB_LIBRARIES} ${APU_EXTRA_LIBRARIES}) - TARGET_INCLUDE_DIRECTORIES(aprutil-1 - PRIVATE ${APU_EXTRA_INCLUDE_DIRECTORIES}) - TARGET_COMPILE_DEFINITIONS(aprutil-1 - PRIVATE "APU_DECLARE_STATIC;XML_STATIC" + SET_TARGET_PROPERTIES(libaprutil-1 PROPERTIES + OUTPUT_NAME aprutil-1) + TARGET_LINK_LIBRARIES(libaprutil-1 + PRIVATE apr::apr-1) + TARGET_COMPILE_DEFINITIONS(libaprutil-1 + PRIVATE "APU_DECLARE_STATIC" INTERFACE "APU_DECLARE_STATIC") ENDIF() @@ -394,7 +397,7 @@ IF(APR_BUILD_TESTAPR) IF(BUILD_SHARED_LIBS) SET(whichapr "apr::libapr-1;libaprutil-1") ELSE() - SET(whichapr "apr::apr-1;aprutil-1") + SET(whichapr "apr::apr-1;libaprutil-1") ENDIF() SET (APR_TEST_SOURCES