From 635f99166d925ab23b36b2cdbe5eb92de6adf089 Mon Sep 17 00:00:00 2001 From: jayeshkrishna Date: Tue, 4 Aug 2026 09:55:34 -0500 Subject: [PATCH] Enable PIC for shared lib builds Explicitly enable PIC for shared library builds (CMake does not apply PIC to OBJECT libraries when BUILD_SHARED_LIBS is turned ON. So explicitly apply it for all sources files) --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 056acea84c..7f760aa907 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,6 +83,9 @@ endif () # Get the name of the build host cmake_host_system_information (RESULT FQDN_SITENAME QUERY FQDN) +# Build position independent code (PIC) for shared library builds +set(CMAKE_POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}) + # Backwards Compatibility - allow users to define [NETCDF|PNETCDF]_DIR instead # of [NetCDF|PnetCDF]_PATH # Old NETCDF_DIR variable --> NetCDF_PATH