-
Notifications
You must be signed in to change notification settings - Fork 335
Enable GENAI with FetchContent or find_package() for client projects
#1858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 19 commits
47a5965
05f5749
0691161
68a545d
4e628e3
5f7aeea
5305384
a7b6ff2
9285680
fdbaffc
006bf1a
0d7b08e
4ac8295
893560a
f24dbf1
38a4346
b84ab59
e9b479a
3401949
4e623ea
a7d4a51
83c18bd
6f9e3b8
1fd3a6d
a6a3a85
6009a52
e8311ee
c1241ff
b77750e
0d461a4
37e63ed
7f04a01
11311dd
9546c37
4e23a0e
1fcce6e
beee6b5
c82b6d7
3c768e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| @PACKAGE_INIT@ | ||
| if (NOT TARGET onnxruntime::onnxruntime-genai) | ||
| include(${CMAKE_CURRENT_LIST_DIR}/onnxruntime-genai-targets.cmake) | ||
| endif() | ||
| check_required_components(onnxruntime-genai) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| include_guard() | ||
|
|
||
| if(USE_WINML) | ||
| message(STATUS "----- Building with WinML support ----- ") | ||
|
|
||
|
|
@@ -53,6 +55,24 @@ if(USE_WINML) | |
| message(STATUS "USE_WINML: ORT_HOME set to: ${ORT_HOME}") | ||
| endif() | ||
|
|
||
| function(_get_target_location_property variable target property) | ||
| get_target_property(_result ${target} ${property}) | ||
| if(NOT _result) | ||
| set(_configuration_types ${CMAKE_CONFIGURATION_TYPES}) | ||
| if (NOT _configuration_types) | ||
| set(_configuration_types Release;RelWithDebInfo;MinSizeRel;Debug) | ||
| endif() | ||
| foreach(_build_type ${_configuration_types}) | ||
| string(TOUPPER ${_build_type} _build_type) | ||
| get_target_property(_result ${target} ${property}_${_build_type}) | ||
| if(_result) | ||
| break() | ||
| endif() | ||
| endforeach() | ||
| endif() | ||
| set(${variable} ${_result} PARENT_SCOPE) | ||
| endfunction() | ||
|
|
||
| if(ORT_HOME) | ||
| # If ORT_HOME is specified at build time, use ORT_HOME to get the onnxruntime headers and libraries | ||
| message(STATUS "Using ONNX Runtime from: ${ORT_HOME} [as provided]") | ||
|
|
@@ -65,15 +85,42 @@ if(ORT_HOME) | |
| # Paths are based on the directory structure of the ORT Android AAR. | ||
| set(ORT_HEADER_DIR ${ORT_HOME}/headers) | ||
| set(ORT_LIB_DIR ${ORT_HOME}/jni/${ANDROID_ABI}) | ||
| set(ORT_BIN_DIR ${ORT_LIB_DIR}) | ||
| elseif (IOS OR MAC_CATALYST) | ||
| set(ORT_HEADER_DIR ${ORT_HOME}/Headers) | ||
| set(ORT_LIB_DIR ${ORT_HOME}/) | ||
| set(ORT_BIN_DIR ${ORT_LIB_DIR}) | ||
| elseif (CMAKE_SYSTEM_NAME MATCHES "AIX") | ||
| set(ORT_HEADER_DIR ${ORT_HOME}/include/onnxruntime) | ||
| set(ORT_BIN_DIR ${ORT_HOME}/bin) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On AIX, is the ort bin dir inside ${ORT_HOME}/bin?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure. I don't have access to AIX systems. If there's no bin directory, I will change it to LIB. I must have made that change because CI was failing for AIX (if any)? |
||
| set(ORT_LIB_DIR ${ORT_HOME}/lib) | ||
| else() | ||
| set(ORT_HEADER_DIR ${ORT_HOME}/include) | ||
| set(ORT_LIB_DIR ${ORT_HOME}/lib) | ||
| find_package(onnxruntime QUIET PATHS ${ORT_HOME}/${CMAKE_BUILD_TYPE} ${ORT_HOME}) | ||
| if(onnxruntime_FOUND) | ||
| get_target_property(ORT_HEADER_DIR onnxruntime::onnxruntime INTERFACE_INCLUDE_DIRECTORIES) | ||
| _get_target_location_property(_onnxruntime_dll onnxruntime::onnxruntime IMPORTED_LOCATION) | ||
| if(CMAKE_SYSTEM_NAME STREQUAL "Windows") | ||
| _get_target_location_property(_onnxruntime_lib onnxruntime::onnxruntime IMPORTED_IMPLIB) | ||
| else() | ||
| set(_onnxruntime_lib "${_onnxruntime_dll}") | ||
| endif() | ||
| else() | ||
| find_file(_onnxruntime_c_api_h onnxruntime_c_api.h REQUIRED | ||
| HINTS "${ORT_HOME}" PATH_SUFFIXES include include/onnxruntime) | ||
| if(CMAKE_SYSTEM_NAME STREQUAL "Windows") | ||
| find_file(_onnxruntime_dll onnxruntime.dll REQUIRED | ||
| HINTS "${ORT_HOME}" PATH_SUFFIXES bin lib) | ||
| find_file(_onnxruntime_lib onnxruntime.lib REQUIRED | ||
| HINTS "${ORT_HOME}" PATH_SUFFIXES lib) | ||
| else() | ||
| find_file(_onnxruntime_dll libonnxruntime.so REQUIRED | ||
| HINTS "${ORT_HOME}" PATH_SUFFIXES bin lib) | ||
| set(_onnxruntime_lib "${_onnxruntime_dll}") | ||
|
apwojcik marked this conversation as resolved.
Outdated
|
||
| endif() | ||
| cmake_path(GET _onnxruntime_c_api_h PARENT_PATH ORT_HEADER_DIR) | ||
| endif() | ||
| cmake_path(GET _onnxruntime_dll PARENT_PATH ORT_BIN_DIR) | ||
| cmake_path(GET _onnxruntime_lib PARENT_PATH ORT_LIB_DIR) | ||
| endif() | ||
| else() | ||
| # If ORT_HOME is not specified, download the onnxruntime headers and libraries from the nightly feed | ||
|
|
@@ -147,6 +194,7 @@ else() | |
| message(FATAL_ERROR "Auto download ONNX Runtime for this platform is not supported.") | ||
| endif() | ||
| endif() | ||
| set(ORT_BIN_DIR ${ORT_LIB_DIR}) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've mostly had the lib and bin dir be the same in most scenarios. Why do we need the distinction now?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is required for ONNX Runtime installed with the |
||
| endif() | ||
|
|
||
| # Download DML headers and libraries | ||
|
|
@@ -194,3 +242,4 @@ set(ONNXRUNTIME_LIB_DIR ${ORT_LIB_DIR}) | |
|
|
||
| message(STATUS "ORT_HEADER_DIR: ${ORT_HEADER_DIR}") | ||
| message(STATUS "ORT_LIB_DIR: ${ORT_LIB_DIR}") | ||
| message(STATUS "ORT_BIN_DIR: ${ORT_BIN_DIR}") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this leak all internal headers to consumers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, only the headers marked public and interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are all the files installed on Windows with the
cmake --install ...command. I anonymized the actual installation path with.... The command installs similar files on other operating systems, except that the .so files are located in thelibdirectory rather thanbin.