@@ -572,7 +572,64 @@ if(BUILD_STATIC)
572572 message ("" )
573573 message (STATUS "STATIC_LIBS_LIST=${STATIC_LIBS_LIST} " )
574574
575- set (DNA_LIBRARIES ${STATIC_LIBS_LIST} -lpthread -lm -ldl)
575+ # For maximum portability, statically link libstdc++ and libgcc
576+ add_link_options (-static -libstdc++ -static -libgcc)
577+
578+ # Find static versions of xerces-c dependencies (curl and ICU)
579+ find_library (CURL_STATIC_LIB NAMES libcurl.a HINTS
580+ ENV LIBRARY_PATH /g/data/ms9/.envbin/lib /usr/lib64 /usr/lib)
581+ find_library (ICUUC_STATIC_LIB NAMES libicuuc.a HINTS
582+ ENV LIBRARY_PATH /g/data/ms9/.envbin/lib /usr/lib64 /usr/lib)
583+ find_library (ICUI18N_STATIC_LIB NAMES libicui18n.a HINTS
584+ ENV LIBRARY_PATH /g/data/ms9/.envbin/lib /usr/lib64 /usr/lib)
585+ find_library (ICUDATA_STATIC_LIB NAMES libicudata.a HINTS
586+ ENV LIBRARY_PATH /g/data/ms9/.envbin/lib /usr/lib64 /usr/lib)
587+ find_library (SSL_STATIC_LIB NAMES libssl.a HINTS
588+ ENV LIBRARY_PATH /g/data/ms9/.envbin/lib /usr/lib64 /usr/lib)
589+ find_library (CRYPTO_STATIC_LIB NAMES libcrypto.a HINTS
590+ ENV LIBRARY_PATH /g/data/ms9/.envbin/lib /usr/lib64 /usr/lib)
591+ find_library (Z_STATIC_LIB NAMES libz.a HINTS
592+ ENV LIBRARY_PATH /g/data/ms9/.envbin/lib /usr/lib64 /usr/lib)
593+
594+ # Build the list of xerces-c dependencies, preferring static
595+ set (XERCES_DEPS "" )
596+
597+ # ICU libraries (order matters: i18n depends on uc, both depend on data)
598+ if (ICUI18N_STATIC_LIB AND ICUUC_STATIC_LIB AND ICUDATA_STATIC_LIB)
599+ message (STATUS "Found static ICU: ${ICUUC_STATIC_LIB} " )
600+ list (APPEND XERCES_DEPS ${ICUI18N_STATIC_LIB} ${ICUUC_STATIC_LIB} ${ICUDATA_STATIC_LIB} )
601+ else ()
602+ message (STATUS "Static ICU not found, using dynamic" )
603+ list (APPEND XERCES_DEPS -licui18n -licuuc -licudata)
604+ endif ()
605+
606+ # curl and its dependencies
607+ if (CURL_STATIC_LIB)
608+ message (STATUS "Found static curl: ${CURL_STATIC_LIB} " )
609+ list (APPEND XERCES_DEPS ${CURL_STATIC_LIB} )
610+ # curl's dependencies
611+ if (SSL_STATIC_LIB AND CRYPTO_STATIC_LIB)
612+ message (STATUS "Found static OpenSSL" )
613+ list (APPEND XERCES_DEPS ${SSL_STATIC_LIB} ${CRYPTO_STATIC_LIB} )
614+ else ()
615+ list (APPEND XERCES_DEPS -lssl -lcrypto)
616+ endif ()
617+ if (Z_STATIC_LIB)
618+ message (STATUS "Found static zlib: ${Z_STATIC_LIB} " )
619+ list (APPEND XERCES_DEPS ${Z_STATIC_LIB} )
620+ else ()
621+ list (APPEND XERCES_DEPS -lz)
622+ endif ()
623+ # Other curl deps that are usually only available as shared
624+ list (APPEND XERCES_DEPS -lnghttp2 -lidn2 -lssh -lpsl -lbrotlidec -lbrotlicommon)
625+ else ()
626+ message (STATUS "Static curl not found, using dynamic" )
627+ list (APPEND XERCES_DEPS -lcurl)
628+ endif ()
629+
630+ # Set DNA_LIBRARIES with all dependencies
631+ # System libs at the end
632+ set (DNA_LIBRARIES ${STATIC_LIBS_LIST} ${XERCES_DEPS} -lpthread -lrt -lm -ldl)
576633
577634 # Print sizes of static libraries
578635 message (STATUS "" )
0 commit comments