From 059bb014fcd8626ddc2087c0b367d4a3d52aa40a Mon Sep 17 00:00:00 2001 From: Ryan Hill Date: Thu, 20 Feb 2025 20:32:07 -0800 Subject: [PATCH] Simplify cmake and refine error messages --- CMakeLists.txt | 3 +++ src/generators.cpp | 2 +- src/python/CMakeLists.txt | 7 ------- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb259ec16..b296f9af8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,9 @@ target_link_libraries(onnxruntime-genai PRIVATE onnxruntime_extensions) target_link_directories(onnxruntime-genai PRIVATE ${ORT_LIB_DIR}) target_link_libraries(onnxruntime-genai PRIVATE Threads::Threads) +# The genai library itself is always embedded in the shared library +list(APPEND ortgenai_embed_libs "$") + # we keep the shared libraries disconnected on Android as they will come from separate AARs and we don't want to force # the ORT version to match in both. if(CMAKE_SYSTEM_NAME STREQUAL "Android" OR CMAKE_SYSTEM_NAME STREQUAL "Linux" OR (CMAKE_SYSTEM_NAME STREQUAL "Darwin" AND (NOT BUILD_APPLE_FRAMEWORK) AND (NOT MAC_CATALYST))) diff --git a/src/generators.cpp b/src/generators.cpp index dc7e1ecfc..b20ecd632 100644 --- a/src/generators.cpp +++ b/src/generators.cpp @@ -152,7 +152,7 @@ struct LibraryHandle { auto path = Ort::GetCurrentModuleDir() + "/" + filename; handle_ = dlopen(path.c_str(), RTLD_NOW | RTLD_LOCAL); if (!handle_) - throw std::runtime_error(std::string("Failed to load library: ") + path + " Error:" + dlerror()); + throw std::runtime_error(std::string("Failed to load library: ") + dlerror()); // dlerror() includes the path } ~LibraryHandle() { dlclose(handle_); diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index b2e8b6aa6..addf90963 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -52,13 +52,6 @@ if(BUILD_WHEEL) file(COPY "${CMAKE_SOURCE_DIR}/ThirdPartyNotices.txt" DESTINATION ${WHEEL_TARGET_NAME}/) file(COPY "${CMAKE_SOURCE_DIR}/LICENSE" DESTINATION ${WHEEL_TARGET_NAME}/) - # Copy over the onnxruntime-genai.dll shared library - add_custom_command(TARGET python POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - $ $ - ${WHEEL_TARGET_NAME} - COMMENT "Copying files to wheel directory: ${WHEEL_TARGET_NAME}" - ) add_custom_command(TARGET python POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${ortgenai_embed_libs} $