diff --git a/cmake/onnxruntime.cmake b/cmake/onnxruntime.cmake index 78edb4179fafd..6c1d4485ebcc9 100644 --- a/cmake/onnxruntime.cmake +++ b/cmake/onnxruntime.cmake @@ -62,7 +62,7 @@ foreach(f ${ONNXRUNTIME_PROVIDER_NAMES}) list(APPEND SYMBOL_FILES "${ONNXRUNTIME_ROOT}/core/providers/${f}/symbols.txt") endforeach() -if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX") +if(NOT CMAKE_SYSTEM_NAME MATCHES "AIX") add_custom_command(OUTPUT ${SYMBOL_FILE} ${CMAKE_CURRENT_BINARY_DIR}/generated_source.c COMMAND ${Python_EXECUTABLE} "${REPO_ROOT}/tools/ci_build/gen_def.py" --version_file "${ONNXRUNTIME_ROOT}/../VERSION_NUMBER" --src_root "${ONNXRUNTIME_ROOT}" @@ -118,7 +118,7 @@ elseif(onnxruntime_BUILD_APPLE_FRAMEWORK) # Note: The PUBLIC_HEADER and VERSION properties for the 'onnxruntime' target will be set later in this file. ) else() - if(${CMAKE_SYSTEM_NAME} MATCHES "AIX") + if(CMAKE_SYSTEM_NAME MATCHES "AIX") onnxruntime_add_shared_library(onnxruntime ${ONNXRUNTIME_ROOT}/core/session/onnxruntime_c_api.cc) else() onnxruntime_add_shared_library(onnxruntime ${CMAKE_CURRENT_BINARY_DIR}/generated_source.c ) @@ -132,7 +132,7 @@ else() endif() endif() -if(${CMAKE_SYSTEM_NAME} MATCHES "AIX") +if(CMAKE_SYSTEM_NAME MATCHES "AIX") add_dependencies(onnxruntime ${onnxruntime_EXTERNAL_DEPENDENCIES}) else() add_dependencies(onnxruntime onnxruntime_generate_def ${onnxruntime_EXTERNAL_DEPENDENCIES}) @@ -145,7 +145,7 @@ target_compile_definitions(onnxruntime PRIVATE FILE_NAME=\"onnxruntime.dll\") if(UNIX) if (APPLE) target_link_options(onnxruntime PRIVATE "LINKER:-dead_strip") - elseif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX") + elseif(NOT CMAKE_SYSTEM_NAME MATCHES "AIX") target_link_options(onnxruntime PRIVATE "LINKER:--version-script=${SYMBOL_FILE}" "LINKER:--no-undefined" "LINKER:--gc-sections") endif() else() @@ -237,7 +237,7 @@ set(onnxruntime_INTERNAL_LIBRARIES onnxruntime_flatbuffers ) -if (${CMAKE_SYSTEM_NAME} MATCHES "AIX") +if (CMAKE_SYSTEM_NAME MATCHES "AIX") list(APPEND onnxruntime_INTERNAL_LIBRARIES iconv) endif() @@ -261,7 +261,7 @@ if(WIN32) endif() #See: https://cmake.org/cmake/help/latest/prop_tgt/SOVERSION.html if(NOT APPLE AND NOT WIN32) - if(${CMAKE_SYSTEM_NAME} MATCHES "AIX") + if(CMAKE_SYSTEM_NAME MATCHES "AIX") set_target_properties(onnxruntime PROPERTIES PUBLIC_HEADER "${ONNXRUNTIME_PUBLIC_HEADERS}" VERSION ${ORT_VERSION} diff --git a/cmake/onnxruntime_framework.cmake b/cmake/onnxruntime_framework.cmake index d013b7552b60d..b1e98a9e0411c 100644 --- a/cmake/onnxruntime_framework.cmake +++ b/cmake/onnxruntime_framework.cmake @@ -105,7 +105,7 @@ add_dependencies(onnxruntime_framework ${onnxruntime_EXTERNAL_DEPENDENCIES}) # For the shared onnxruntime library, this is set in onnxruntime.cmake through CMAKE_SHARED_LINKER_FLAGS # But our test files don't use the shared library so this must be set for them. # For Win32 it generates an absolute path for shared providers based on the location of the executable/onnxruntime.dll -if (UNIX AND NOT APPLE AND NOT onnxruntime_MINIMAL_BUILD AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX") +if (UNIX AND NOT APPLE AND NOT onnxruntime_MINIMAL_BUILD AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND NOT CMAKE_SYSTEM_NAME MATCHES "AIX") set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath='$ORIGIN'") endif() diff --git a/cmake/onnxruntime_providers_cpu.cmake b/cmake/onnxruntime_providers_cpu.cmake index a959c5dd9581a..beff30d193b94 100644 --- a/cmake/onnxruntime_providers_cpu.cmake +++ b/cmake/onnxruntime_providers_cpu.cmake @@ -229,6 +229,12 @@ if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD onnxruntime_add_shared_library(onnxruntime_providers_shared ${onnxruntime_providers_shared_cc_srcs} "${ONNXRUNTIME_ROOT}/core/dll/onnxruntime.rc") set_target_properties(onnxruntime_providers_shared PROPERTIES FOLDER "ONNXRuntime") set_target_properties(onnxruntime_providers_shared PROPERTIES LINKER_LANGUAGE CXX) + #ON AIX, to call dlopen on onnxruntime_providers_shared, we need to generate this library as shared object .so file. + #Latest cmake behavior is changed and cmake will remove shared object .so file after generating the shared archive. + #To prevent that, making AIX_SHARED_LIBRARY_ARCHIVE as OFF for onnxruntime_providers_shared. + if (CMAKE_SYSTEM_NAME MATCHES "AIX") + set_target_properties(onnxruntime_providers_shared PROPERTIES AIX_SHARED_LIBRARY_ARCHIVE OFF) + endif() target_compile_definitions(onnxruntime_providers_shared PRIVATE FILE_NAME=\"onnxruntime_providers_shared.dll\") @@ -241,7 +247,7 @@ if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD if(APPLE) set_property(TARGET onnxruntime_providers_shared APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker -exported_symbols_list ${ONNXRUNTIME_ROOT}/core/providers/shared/exported_symbols.lst") elseif(UNIX) - if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX") + if(NOT CMAKE_SYSTEM_NAME MATCHES "AIX") target_link_options(onnxruntime_providers_shared PRIVATE "LINKER:--version-script=${ONNXRUNTIME_ROOT}/core/providers/shared/version_script.lds" "LINKER:--gc-sections") diff --git a/cmake/onnxruntime_unittests.cmake b/cmake/onnxruntime_unittests.cmake index 896139a4e65a3..e6138deaebb60 100644 --- a/cmake/onnxruntime_unittests.cmake +++ b/cmake/onnxruntime_unittests.cmake @@ -1265,7 +1265,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) if (CMAKE_SYSTEM_NAME STREQUAL "Android") list(APPEND onnxruntime_perf_test_libs ${android_shared_libs}) endif() - if (${CMAKE_SYSTEM_NAME} MATCHES "AIX") + if (CMAKE_SYSTEM_NAME MATCHES "AIX") list(APPEND onnxruntime_perf_test_libs onnxruntime_graph onnxruntime_session onnxruntime_providers onnxruntime_framework onnxruntime_util onnxruntime_mlas onnxruntime_optimizer onnxruntime_flatbuffers iconv re2 gtest absl_failure_signal_handler absl_examine_stack absl_flags_parse absl_flags_usage absl_flags_usage_internal) endif() target_link_libraries(onnxruntime_perf_test PRIVATE ${onnxruntime_perf_test_libs} Threads::Threads) @@ -1343,7 +1343,7 @@ if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) list(APPEND onnxruntime_shared_lib_test_LIBS ${android_shared_libs}) endif() - if (${CMAKE_SYSTEM_NAME} MATCHES "AIX") + if (CMAKE_SYSTEM_NAME MATCHES "AIX") list(APPEND onnxruntime_shared_lib_test_LIBS onnxruntime_graph onnxruntime_session onnxruntime_providers onnxruntime_framework onnxruntime_util onnxruntime_mlas onnxruntime_optimizer onnxruntime_flatbuffers iconv re2 onnx) endif() @@ -1582,7 +1582,7 @@ if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") if(UNIX) if (APPLE) set(ONNXRUNTIME_CUSTOM_OP_LIB_LINK_FLAG "-Xlinker -dead_strip") - elseif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX") + elseif(NOT CMAKE_SYSTEM_NAME MATCHES "AIX") set(ONNXRUNTIME_CUSTOM_OP_LIB_LINK_FLAG "-Xlinker --version-script=${TEST_SRC_DIR}/testdata/custom_op_library/custom_op_library.lds -Xlinker --no-undefined -Xlinker --gc-sections -z noexecstack") endif() else() @@ -1593,6 +1593,12 @@ if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") endif() endif() set_property(TARGET custom_op_library APPEND_STRING PROPERTY LINK_FLAGS ${ONNXRUNTIME_CUSTOM_OP_LIB_LINK_FLAG}) + #ON AIX, to call dlopen on custom_op_library, we need to generate this library as shared object .so file. + #Latest cmake behavior is changed and cmake will remove shared object .so file after generating the shared archive. + #To prevent that, making AIX_SHARED_LIBRARY_ARCHIVE as OFF for custom_op_library. + if (CMAKE_SYSTEM_NAME MATCHES "AIX") + set_target_properties(custom_op_library PROPERTIES AIX_SHARED_LIBRARY_ARCHIVE OFF) + endif() if (NOT onnxruntime_ENABLE_TRAINING_TORCH_INTEROP) if (onnxruntime_BUILD_JAVA AND NOT onnxruntime_ENABLE_STATIC_ANALYSIS) @@ -1660,7 +1666,7 @@ if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten") if (onnxruntime_USE_TENSORRT) list(APPEND onnxruntime_customopregistration_test_LIBS ${TENSORRT_LIBRARY_INFER}) endif() - if (${CMAKE_SYSTEM_NAME} MATCHES "AIX") + if (CMAKE_SYSTEM_NAME MATCHES "AIX") list(APPEND onnxruntime_customopregistration_test_LIBS onnxruntime_graph onnxruntime_session onnxruntime_providers onnxruntime_lora onnxruntime_framework onnxruntime_util onnxruntime_mlas onnxruntime_optimizer onnxruntime_flatbuffers iconv re2 ${PROTOBUF_LIB} onnx onnx_proto) endif() AddTest(DYN @@ -1697,7 +1703,7 @@ if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND (NOT onnxruntime_MINIMAL_BUI if(UNIX) if (APPLE) set(ONNXRUNTIME_CUSTOM_OP_INVALID_LIB_LINK_FLAG "-Xlinker -dead_strip") - elseif (NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX") + elseif (NOT CMAKE_SYSTEM_NAME MATCHES "AIX") string(CONCAT ONNXRUNTIME_CUSTOM_OP_INVALID_LIB_LINK_FLAG "-Xlinker --version-script=${TEST_SRC_DIR}/testdata/custom_op_invalid_library/custom_op_library.lds " "-Xlinker --no-undefined -Xlinker --gc-sections -z noexecstack") @@ -1728,7 +1734,7 @@ if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND (NOT onnxruntime_MINIMAL_BUI if(UNIX) if (APPLE) set(ONNXRUNTIME_CUSTOM_OP_GET_CONST_INPUT_TEST_LIB_LINK_FLAG "-Xlinker -dead_strip") - elseif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX") + elseif(NOT CMAKE_SYSTEM_NAME MATCHES "AIX") string(CONCAT ONNXRUNTIME_CUSTOM_OP_GET_CONST_INPUT_TEST_LIB_LINK_FLAG "-Xlinker --version-script=${TEST_SRC_DIR}/testdata/custom_op_get_const_input_test_library/custom_op_lib.lds " "-Xlinker --no-undefined -Xlinker --gc-sections -z noexecstack") @@ -1760,7 +1766,7 @@ if (NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" AND (NOT onnxruntime_MINIMAL_BUI if(UNIX) if (APPLE) set(ONNXRUNTIME_CUSTOM_OP_lOCAL_FUNCTION_TEST_LIB_LINK_FLAG "-Xlinker -dead_strip") - elseif(NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX") + elseif(NOT CMAKE_SYSTEM_NAME MATCHES "AIX") string(CONCAT ONNXRUNTIME_CUSTOM_OP_lOCAL_FUNCTION_TEST_LIB_LINK_FLAG "-Xlinker --version-script=${TEST_SRC_DIR}/testdata/custom_op_local_function/custom_op_local_function.lds " "-Xlinker --no-undefined -Xlinker --gc-sections -z noexecstack") @@ -1779,7 +1785,7 @@ if (onnxruntime_BUILD_SHARED_LIB AND NOT CMAKE_SYSTEM_NAME STREQUAL "Emscripten" ${ONNXRUNTIME_LOGGING_APIS_TEST_SRC_DIR}/test_logging_apis.cc) set(onnxruntime_logging_apis_test_LIBS onnxruntime_common onnxruntime_test_utils) - if (${CMAKE_SYSTEM_NAME} MATCHES "AIX") + if (CMAKE_SYSTEM_NAME MATCHES "AIX") list(APPEND onnxruntime_logging_apis_test_LIBS onnxruntime_session onnxruntime_util onnxruntime_lora onnxruntime_framework onnxruntime_common onnxruntime_graph onnxruntime_providers onnxruntime_mlas onnxruntime_optimizer onnxruntime_flatbuffers iconv re2 ${PROTOBUF_LIB} onnx onnx_proto) endif() @@ -1850,7 +1856,7 @@ if (NOT onnxruntime_MINIMAL_BUILD AND NOT onnxruntime_EXTENDED_MINIMAL_BUILD if(APPLE) set_property(TARGET test_execution_provider APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker -exported_symbols_list ${REPO_ROOT}/onnxruntime/test/testdata/custom_execution_provider_library/exported_symbols.lst") elseif(UNIX) - if (NOT ${CMAKE_SYSTEM_NAME} MATCHES "AIX") + if (NOT CMAKE_SYSTEM_NAME MATCHES "AIX") set_property(TARGET test_execution_provider APPEND_STRING PROPERTY LINK_FLAGS "-Xlinker --version-script=${REPO_ROOT}/onnxruntime/test/testdata/custom_execution_provider_library/version_script.lds -Xlinker --gc-sections -Xlinker -rpath=\\$ORIGIN") endif() elseif(WIN32)