Skip to content

Comments

added support for cmake "find_package"#8919

Merged
snnn merged 2 commits intomicrosoft:mainfrom
prateek9623:master
Jun 20, 2023
Merged

added support for cmake "find_package"#8919
snnn merged 2 commits intomicrosoft:mainfrom
prateek9623:master

Conversation

@prateek9623
Copy link
Contributor

@prateek9623 prateek9623 commented Sep 1, 2021

Description:
Adds support for cmake find_package.

Motivation and Context
As mentioned in issue #7150 onnxruntime doesn't have support for CMake find_package, this PR adds that and also adds the CMake package version file. Now anyone can link onnxruntime like this:

find_package(onnxruntime)
add_executable(test Source.cpp)
target_link_libraries(test PRIVATE onnxruntime::onnxruntime)

this also simplifies 3124

@prateek9623
Copy link
Contributor Author

prateek9623 commented Sep 1, 2021

@snnn I have a question are this compile definitions needs to be public?

target_compile_definitions(${target_name} PUBLIC -DPLATFORM_WINDOWS -DNOGDI -DNOMINMAX -D_USE_MATH_DEFINES -D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS)

also, in some headers, headers are not included relative to root dir, like:


So what should be done about this?

@prateek9623
Copy link
Contributor Author

prateek9623 commented Sep 1, 2021

also is this file: eigen_common_wrapper.h is intended to be used by user or this private header as this header file include onnxruntime_config.h which is cmake generate file and is not exported. If it is public then we should export onnxruntime_config.h or else not export it.


and there are also this "core/framework/data_transfer.h" "core/framework/allocatormgr.h" "core/framework/prepacked_weights_container.h" "core/framework/TensorSeq.h" "core/framework/config_options.h" "core/framework/session_options.h" "core/common/path.h" "core/platform/ort_mutex.h" "core/platform/threadpool.h" this files which are not exported but included in some headers.

@prateek9623 prateek9623 force-pushed the master branch 2 times, most recently from e8803ce to d5dcbb2 Compare September 1, 2021 12:23
@prateek9623 prateek9623 marked this pull request as ready for review September 2, 2021 04:58
@prateek9623 prateek9623 requested a review from a team as a code owner September 2, 2021 04:58
@snnn
Copy link
Contributor

snnn commented Sep 2, 2021

"onnxruntime_config.h" is a tricky thing. The idea was borrowed from autoconf, which is quite old. And it assumes that you won't do "build-once, run everywhere" such things. So the content of config.h is based on your current system's configuration. If you won't copy the generated file to another file, then it's totally fine to install it to /usr/include .

@prateek9623 prateek9623 closed this Sep 6, 2021
@prateek9623 prateek9623 reopened this Sep 6, 2021
@prateek9623
Copy link
Contributor Author

ok, and what about other headers, like

  • "core/framework/allocatormgr.h", "core/framework/data_transfer.h" used by "core/framework/execution_provider.h"
  • "core/framework/prepacked_weights_container.h" used by "core/framework/op_kernel.h"
  • "core/framework/TensorSeq.h" used by "core/framework/data_types.h", "core/framework/ort_value.h"
  • "core/framework/config_options.h" used by "core\framework\run_options.h"
  • "core/platform/ort_mutex.h" used by "schema_registry.h"
  • "core/platform/threadpool.h" used by environment.h
  • "thread_utils.h" used by ""core/framework/session_options.h" used by graph_viewer.h
  • path_string.h used by "core/common/path.h" used by graph.h

@snnn
Copy link
Contributor

snnn commented Sep 8, 2021

If they need be in the right place, please help us move them.

@ongun-kanat
Copy link

Why is this closed? I was looking for a proper CMake export. I was going to write it myself but realized this PR already does it. Now this one is closed. Does that mean the project does not want to merge it?

@prateek9623
Copy link
Contributor Author

@ongun-kanat i got distracted to some other project, but now I am back and cleaning commits

@prateek9623
Copy link
Contributor Author

@snnn Hey I saw now we have a NuGet package with tensorrt support, I wanted to ask right now Cmake install a lot of header files but in the NuGet package, there are only a few, do we want the same number of header in cmake to install as in NuGet or other headers are also useful.

@prateek9623 prateek9623 reopened this Oct 28, 2021
@snnn
Copy link
Contributor

snnn commented Oct 28, 2021

Do we want the same number of header

Is this for static link to onnxruntime or dynamic link?
If it is for libonnxruntime.so, then you will only need one file: onnxruntime_c_api.h (and the files it includes, not much).
Otherwise, it will be a lot and I don't know how to handle it.

@prateek9623
Copy link
Contributor Author

prateek9623 commented Oct 28, 2021

Do we want the same number of header

Is this for static link to onnxruntime or dynamic link? If it is for libonnxruntime.so, then you will only need one file: onnxruntime_c_api.h (and the files it includes, not much). Otherwise, it will be a lot and I don't know how to handle it.

in Nuget we have only these headers:
image
location: Microsoft.ML.OnnxRuntime.Gpu.1.9.0\build\native\include
but in cmake, we are installing a lot of other headers

@prateek9623 prateek9623 marked this pull request as ready for review October 28, 2021 19:57
@prateek9623
Copy link
Contributor Author

prateek9623 commented Nov 12, 2021

@snnn Hey, this pr is ready for shared libs. Can you review it or ask someone else to review it if you dont have time.

@mszhanyi
Copy link
Contributor

/azp run Python packaging pipeline

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@mszhanyi
Copy link
Contributor

mszhanyi commented Jun 19, 2023

/azp run Zip-Nuget-Java-Nodejs Packaging Pipeline

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@microsoft microsoft deleted a comment from azure-pipelines bot Jun 19, 2023
@mszhanyi
Copy link
Contributor

/azp run Python packaging pipeline

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@mszhanyi
Copy link
Contributor

/azp run Zip-Nuget-Java-Nodejs Packaging Pipeline

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@prateek9623
Copy link
Contributor Author

I don't have enough React Native knowledge to fix these 2 remaining issues. Can anyone help with this?

@tianleiwu
Copy link
Contributor

tianleiwu commented Jun 19, 2023

I don't have enough React Native knowledge to fix these 2 remaining issues. Can anyone help with this?

It is fine since other jobs have same failure in the React pipeline. I think it is not related to this change.

@tianleiwu
Copy link
Contributor

tianleiwu commented Jun 19, 2023

@snnn, are there other pipelines need to verify for this PR?
@mszhanyi, I think some release pipelines (like packaging pipeline) cannot run in this PR since those require code in main/release branch.

@YUNQIUGUO
Copy link
Contributor

YUNQIUGUO commented Jun 19, 2023

I don't have enough React Native knowledge to fix these 2 remaining issues. Can anyone help with this?

Yeah, the react native pipeline is currently failing due to some other checked-in changes. We are working on a fix for that. It's not a required CI, won't affect this pr merge.

@snnn snnn merged commit 12dffef into microsoft:main Jun 20, 2023
edgchen1 added a commit that referenced this pull request Oct 4, 2023
The changes in PR #8919 overwrote the PUBLIC_HEADER property value of the `onnxruntime` target with a list that did not include EP-specific headers. We should probably be using a consistent set of header files across packages anyway.
@QiuYilin
Copy link

It seems that the target onnxruntime does not contain providers, which causes onnxruntime_providers.dll and onnxruntime_provider_cuda.dll to be lost when copying the target to the root directory.

@prateek9623
Copy link
Contributor Author

prateek9623 commented Dec 26, 2023

@QiuYilin Libs of providers should be installed if the "install" target is built in "CMAKE_INSTALL_LIBDIR". Just that the provider's cmake targets are not exported, I initially tried to do it but some of the providers had PUBLIC dependencies which were creating issues.

@Artalus
Copy link

Artalus commented Jan 29, 2024

@prateek9623 can you or someone else please explain, why the header structure had to be changed?..

In 1.15.1 and before, no matter if building ORT as shared or static, we always had include/onnxruntime/core/session/onnxruntime_cxx_api.h for example, same as it was in the ORT repo source tree.

But now, since in cmake/onnxruntime_session.cmake you have moved install(DIRECTORY ${PROJECT_SOURCE_DIR}/../include/onnxruntime/core/session ... under if (NOT onnxruntime_BUILD_SHARED_LIB), the aforementioned header may move around if ORT was built as shared. So in 1.16.3 it may become include/onnxruntime/onnxruntime_cxx_api.h instead.

Do we now have to use something like this in our code:

#ifdef ORT_SHARED
#  include <onnxruntime/onnxruntime_cxx_api.h>
#else
#  include <onnxruntime/core/session/onnxruntime_cxx_api.h>
#endif

, or am I missing something?

@prateek9623
Copy link
Contributor Author

@Artalus With this PR I tried to replicate prebuilt shared lib releases. And have not disturbed static build.
@snnn do you have any comments on this?

kleiti pushed a commit to kleiti/onnxruntime that referenced this pull request Mar 22, 2024
The changes in PR microsoft#8919 overwrote the PUBLIC_HEADER property value of the `onnxruntime` target with a list that did not include EP-specific headers. We should probably be using a consistent set of header files across packages anyway.
@thiagocrepaldi
Copy link
Contributor

thiagocrepaldi commented May 16, 2024

@prateek9623 @snn could the cmake files be added to the tar.gz file so that people can download ort and link to it without having to clone the repo?

@WilliamTambellini
Copy link
Contributor

I agree with @thiagocrepaldi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build build issues; typically submitted using template

Projects

None yet

Development

Successfully merging this pull request may close these issues.