Enable position-independent code for static libraries in CMake

This commit is contained in:
2026-02-08 17:01:40 +00:00
parent 2fa677638a
commit 29d57b804e

View File

@@ -126,6 +126,9 @@ if("${CMAKE_BUILD_TYPE}" MATCHES "Release" OR "${CMAKE_BUILD_TYPE}" MATCHES "Rel
endif()
endif()
# Ensure all static libraries are built with PIC so they can be linked into the shared library
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_subdirectory(3rdparty)
add_library("Aaru.Compression.Native" SHARED library.c apple_rle.c apple_rle.h adc.c adc.h lzip.c flac.c flac.h
@@ -190,10 +193,4 @@ if(HAVE_PTHREAD)
target_link_libraries_whole_archive("Aaru.Compression.Native" Threads::Threads)
endif()
if(NOT "${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW" OR (NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm" AND NOT ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64"))
set_property(TARGET "Aaru.Compression.Native" PROPERTY POSITION_INDEPENDENT_CODE TRUE)
else()
set_property(TARGET "Aaru.Compression.Native" PROPERTY POSITION_INDEPENDENT_CODE FALSE)
endif()
add_subdirectory(tests)