diff --git a/cmake/onnxruntime.cmake b/cmake/onnxruntime.cmake index 31579d9375..6ad7f009c2 100644 --- a/cmake/onnxruntime.cmake +++ b/cmake/onnxruntime.cmake @@ -32,15 +32,24 @@ target_include_directories(onnxruntime PRIVATE ${ONNXRUNTIME_ROOT}) onnxruntime_add_include_to_target(onnxruntime gsl) if(UNIX) - set(BEGIN_WHOLE_ARCHIVE -Xlinker --whole-archive) - set(END_WHOLE_ARCHIVE -Xlinker --no-whole-archive) - set(ONNXRUNTIME_SO_LINK_FLAG "-Xlinker --version-script=${SYMBOL_FILE} -Xlinker --no-undefined") + if (APPLE) + set(BEGIN_WHOLE_ARCHIVE -Xlinker -all_load) + set(END_WHOLE_ARCHIVE -Xlinker -noall_load) + else() + set(BEGIN_WHOLE_ARCHIVE -Xlinker --whole-archive) + set(END_WHOLE_ARCHIVE -Xlinker --no-whole-archive) + set(ONNXRUNTIME_SO_LINK_FLAG "-Xlinker --version-script=${SYMBOL_FILE} -Xlinker --no-undefined") + endif() else() set(ONNXRUNTIME_SO_LINK_FLAG "-DEF:${SYMBOL_FILE}") endif() if (NOT WIN32) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'") + if (APPLE) + set_target_properties(onnxruntime PROPERTIES INSTALL_RPATH "@loader_path") + else() + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'") + endif() endif() #The BEGIN_WHOLE_ARCHIVE/END_WHOLE_ARCHIVE part should contain the implementations of all the C API functions diff --git a/tools/ci_build/github/azure-pipelines/mac-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/mac-ci-pipeline.yml index 55b6f4234a..c81271622b 100644 --- a/tools/ci_build/github/azure-pipelines/mac-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/mac-ci-pipeline.yml @@ -5,7 +5,7 @@ jobs: steps: - script: | sudo xcode-select --switch /Applications/Xcode_10.app/Contents/Developer - ./build.sh --skip_submodule_sync --parallel + ./build.sh --skip_submodule_sync --parallel --build_shared_lib displayName: 'Command Line Script' - template: templates/clean-agent-build-directory-step.yml \ No newline at end of file