Skip to content

Commit 972498c

Browse files
committed
Fix: macOS ADIOS1 w/o XCode
Some compiler toolchains on macOS do not use the XCode system compiler. For instance, conda-forge uses vanilla clang to build packages. In that case, the symbol hiding instructions we used on macOS were not effective, leading to errors like #1195. The current patch checks if the toolchain understands GCC/LLVM-ish linker flags on macOS and if it does, it adds them.
1 parent 97eae91 commit 972498c

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

CMakeLists.txt

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ set(IO_SOURCE
459459
set(IO_ADIOS1_SEQUENTIAL_SOURCE
460460
src/Error.cpp
461461
src/auxiliary/Filesystem.cpp
462+
src/auxiliary/JSON.cpp
462463
src/ChunkInfo.cpp
463464
src/IO/ADIOS/CommonADIOS1IOHandler.cpp
464465
src/IO/ADIOS/ADIOS1IOHandler.cpp)
@@ -554,15 +555,34 @@ if(openPMD_HAVE_ADIOS1)
554555
$<TARGET_PROPERTY:openPMD::thirdparty::nlohmann_json,INTERFACE_INCLUDE_DIRECTORIES>
555556
$<TARGET_PROPERTY:openPMD::thirdparty::toml11,INTERFACE_INCLUDE_DIRECTORIES>)
556557

558+
# Strip all symbols from wrapped library objects, so we can link parallel
559+
# and serial ADIOS1 (with MPI mock/stubs) at the same time.
560+
include(CheckLinkerFlag)
561+
# Vanilla Clang, g++, etc., e.g., on conda-forge
562+
set(_GNU_LINKSTRIP "LINKER:SHELL:--exclude-libs,ALL")
563+
set(_LLVM_LINKSTRIP "LINKER:SHELL:--exclude-libs=ALL")
564+
check_linker_flag(CXX "${_GNU_LINKSTRIP}" SUPP_GNU_LINKSTRIP)
565+
check_linker_flag(CXX "${_LLVM_LINKSTRIP}" SUPP_LLVM_LINKSTRIP)
566+
557567
set_target_properties(openPMD.ADIOS1.Serial PROPERTIES
558568
POSITION_INDEPENDENT_CODE ON
559569
CXX_VISIBILITY_PRESET hidden
560570
VISIBILITY_INLINES_HIDDEN ON
561571
)
562572
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
563-
set_target_properties(openPMD.ADIOS1.Serial PROPERTIES
564-
LINK_FLAGS "-Wl,--exclude-libs,ALL")
573+
if(SUPP_GNU_LINKSTRIP)
574+
target_link_options(openPMD.ADIOS1.Serial PRIVATE "${_GNU_LINKSTRIP}")
575+
elseif(SUPP_LLVM_LINKSTRIP)
576+
target_link_options(openPMD.ADIOS1.Serial PRIVATE "${_LLVM_LINKSTRIP}")
577+
else()
578+
message(WARNING "Cannot strip serial ADIOS1 MPI mock")
579+
endif()
565580
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
581+
if(SUPP_GNU_LINKSTRIP)
582+
target_link_options(openPMD.ADIOS1.Serial PRIVATE "${_GNU_LINKSTRIP}")
583+
elseif(SUPP_LLVM_LINKSTRIP)
584+
target_link_options(openPMD.ADIOS1.Serial PRIVATE "${_LLVM_LINKSTRIP}")
585+
endif()
566586
set_target_properties(openPMD.ADIOS1.Serial PROPERTIES
567587
XCODE_ATTRIBUTE_STRIP_STYLE "non-global"
568588
XCODE_ATTRIBUTE_DEPLOYMENT_POSTPROCESSING "YES"
@@ -585,9 +605,19 @@ if(openPMD_HAVE_ADIOS1)
585605
VISIBILITY_INLINES_HIDDEN 1
586606
)
587607
if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
588-
set_target_properties(openPMD.ADIOS1.Parallel PROPERTIES
589-
LINK_FLAGS "-Wl,--exclude-libs,ALL")
608+
if(SUPP_GNU_LINKSTRIP)
609+
target_link_options(openPMD.ADIOS1.Parallel PRIVATE "${_GNU_LINKSTRIP}")
610+
elseif(SUPP_LLVM_LINKSTRIP)
611+
target_link_options(openPMD.ADIOS1.Parallel PRIVATE "${_LLVM_LINKSTRIP}")
612+
else()
613+
message(WARNING "Cannot strip serial ADIOS1 MPI mock")
614+
endif()
590615
elseif("${CMAKE_SYSTEM_NAME}" MATCHES "Darwin")
616+
if(SUPP_GNU_LINKSTRIP)
617+
target_link_options(openPMD.ADIOS1.Parallel PRIVATE "${_GNU_LINKSTRIP}")
618+
elseif(SUPP_LLVM_LINKSTRIP)
619+
target_link_options(openPMD.ADIOS1.Parallel PRIVATE "${_LLVM_LINKSTRIP}")
620+
endif()
591621
set_target_properties(openPMD.ADIOS1.Parallel PROPERTIES
592622
XCODE_ATTRIBUTE_STRIP_STYLE "non-global"
593623
XCODE_ATTRIBUTE_DEPLOYMENT_POSTPROCESSING "YES"

0 commit comments

Comments
 (0)