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
[cmake] Place export target file in the correct directory #5677
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know!. |
Prior to this patch, the ONNXConfig.cmake script (generated from the ONNXConfig.cmake.in file) tries to read the export target file (ONNXTargets.cmake) from the same directory where ONNXConfig.cmake is located, but the two files are not in the same directory. Specifically, CMake places the export target file (ONNXTargets.cmake) in a directory whose name contains the build hash, whereas the ONNXConfig.cmake script is placed in the ${PROJECT_BINARY_DIR}/ONNXConfig.cmake, as specified in the top-level CMakeLists.txt directory. This patch reconciles the difference by explicitly instructing CMake to place the export target file (ONNXTargets.cmake) in the same directory as the ONNXConfig.cmake script during the build step. This patch also makes two ancillary changes. First, it adds the `ONNX::` namespace to the target names, so that targets built by this project don't interfere with targets built by other projects. Second, this patch adds Protobuf to the list of packages that consumers of ONNX must have available, since protobuf libraries are linked publicly while building ONNX. Signed-off-by: Ashay Rane <ashay@users.noreply.github.com>
jcwchen
reviewed
Oct 17, 2023
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.
Please ignore the failure from Windows release CI, which will be fixed by #5678.
justinchuby
approved these changes
Oct 26, 2023
isdanni
pushed a commit
to isdanni/onnx
that referenced
this pull request
Nov 2, 2023
## Description Prior to this patch, the ONNXConfig.cmake script (generated from the ONNXConfig.cmake.in file) tries to read the export target file (ONNXTargets.cmake) from the same directory where ONNXConfig.cmake is located, but the two files are not in the same directory. Specifically, CMake places the export target file (ONNXTargets.cmake) in a directory whose name contains the build hash, whereas the ONNXConfig.cmake script is placed in the ${PROJECT_BINARY_DIR}/ONNXConfig.cmake, as specified in the top-level CMakeLists.txt directory. This patch reconciles the difference by explicitly instructing CMake to place the export target file (ONNXTargets.cmake) in the same directory as the ONNXConfig.cmake script during the build step. This patch also makes two ancillary changes. First, it adds the `ONNX::` namespace to the target names, so that targets built by this project don't interfere with targets built by other projects. Second, this patch adds Protobuf to the list of packages that consumers of ONNX must have available, since protobuf libraries are linked publicly while building ONNX. <!-- copilot:all --> ### <samp>🤖 Generated by Copilot at 5173943</samp> ### Summary 🛠️🚀🌐 <!-- 1. 🛠️ - This emoji represents the addition of the commands to the `cmake/ONNXConfig.cmake.in` file, which are tools for improving the ONNX CMake configuration and making the Protobuf library findable. 2. 🚀 - This emoji represents the improvement of the ONNX CMake configuration by setting the Protobuf variables and adding the namespace option, which are enhancements that make the ONNX project more robust and portable. 3. 🌐 - This emoji represents the conditional export command for the Protobuf library, which is a feature that makes the ONNX project more compatible with different platforms and environments. --> This pull request enhances the ONNX CMake configuration to make the Protobuf library more accessible and consistent for the ONNX library and its users. It modifies the `CMakeLists.txt` and `cmake/ONNXConfig.cmake.in` files to set and export the relevant Protobuf variables and commands. > _Sing, O Muse, of the valiant ONNX project, the source of many models_ > _That with `CMake` configures its code, and to other projects unfolds_ > _Its mighty `Protobuf` dependency, that it finds and exports with care_ > _Like Zeus who wields his thunderbolt, and his power with the gods shares_ ### Walkthrough * Add `find_package(Protobuf REQUIRED)` command and set `CMAKE_PREFIX_PATH` and `Protobuf_INCLUDE_DIR` variables to make Protobuf library findable by ONNXConfig.cmake file ([link](https://github.com/onnx/onnx/pull/5677/files?diff=unified&w=0#diff-67d7a4f3d6c006f4fd85472c38c422e6f1ad75e026c69c3657c6ca1ec29e6673R9-R12)) * Set `PROTOBUF_DIR` and `PROTOBUF_INCLUDE_DIR` variables to Protobuf installation prefix or binary and source directories depending on whether Protobuf was fetched and built by ONNX or not ([link](https://github.com/onnx/onnx/pull/5677/files?diff=unified&w=0#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20aR179-R180), [link](https://github.com/onnx/onnx/pull/5677/files?diff=unified&w=0#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20aR270-R271)) * Add `NAMESPACE ONNX::` option to `install(EXPORT ONNXTargets ...)` and `export(EXPORT ONNXTargets ...)` commands to follow CMake best practices and avoid name clashes ([link](https://github.com/onnx/onnx/pull/5677/files?diff=unified&w=0#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20aL720-R736)) * Add conditional `export(EXPORT ONNXTargets ...)` command to workaround Protobuf export issue when it is built as part of ONNX ([link](https://github.com/onnx/onnx/pull/5677/files?diff=unified&w=0#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20aL720-R736)) Signed-off-by: Ashay Rane <ashay@users.noreply.github.com> Co-authored-by: Chun-Wei Chen <jacky82226@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
build
Issues related to ONNX builds and packages
run release CIs
Use this label to trigger release tests in CI
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Prior to this patch, the ONNXConfig.cmake script (generated from the
ONNXConfig.cmake.in file) tries to read the export target file
(ONNXTargets.cmake) from the same directory where ONNXConfig.cmake is
located, but the two files are not in the same directory. Specifically,
CMake places the export target file (ONNXTargets.cmake) in a directory
whose name contains the build hash, whereas the ONNXConfig.cmake script
is placed in the ${PROJECT_BINARY_DIR}/ONNXConfig.cmake, as specified in
the top-level CMakeLists.txt directory.
This patch reconciles the difference by explicitly instructing CMake to
place the export target file (ONNXTargets.cmake) in the same directory
as the ONNXConfig.cmake script during the build step.
This patch also makes two ancillary changes. First, it adds the
ONNX::
namespace to the target names, so that targets built by thisproject don't interfere with targets built by other projects. Second,
this patch adds Protobuf to the list of packages that consumers of ONNX
must have available, since protobuf libraries are linked publicly while
building ONNX.
🤖 Generated by Copilot at 5173943
Summary
🛠️🚀🌐
This pull request enhances the ONNX CMake configuration to make the Protobuf library more accessible and consistent for the ONNX library and its users. It modifies the
CMakeLists.txt
andcmake/ONNXConfig.cmake.in
files to set and export the relevant Protobuf variables and commands.Walkthrough
find_package(Protobuf REQUIRED)
command and setCMAKE_PREFIX_PATH
andProtobuf_INCLUDE_DIR
variables to make Protobuf library findable by ONNXConfig.cmake file (link)PROTOBUF_DIR
andPROTOBUF_INCLUDE_DIR
variables to Protobuf installation prefix or binary and source directories depending on whether Protobuf was fetched and built by ONNX or not (link, link)NAMESPACE ONNX::
option toinstall(EXPORT ONNXTargets ...)
andexport(EXPORT ONNXTargets ...)
commands to follow CMake best practices and avoid name clashes (link)export(EXPORT ONNXTargets ...)
command to workaround Protobuf export issue when it is built as part of ONNX (link)