Skip to content

Define namespace prefixed alias for cpuinfo in the CMake build#89

Merged
malfet merged 1 commit intopytorch:masterfrom
petrhosek:cmake-alias
Jun 17, 2022
Merged

Define namespace prefixed alias for cpuinfo in the CMake build#89
malfet merged 1 commit intopytorch:masterfrom
petrhosek:cmake-alias

Conversation

@petrhosek
Copy link
Copy Markdown
Contributor

This allows projects that depend on cpuinfo to use namespace qualified
target name regardless of whether they consume cpuinfo through
add_subdirectory or find_package.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

Hi @petrhosek!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link
Copy Markdown
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

This allows projects that depend on cpuinfo to use namespace qualified
target name regardless of whether they consume cpuinfo through
add_subdirectory or find_package.
@petrhosek
Copy link
Copy Markdown
Contributor Author

Thank you for the review, would it be possible to merge this PR?

@Maratyszcza
Copy link
Copy Markdown
Contributor

I don't have write access to the repo. @malfet PTAL

@malfet
Copy link
Copy Markdown
Contributor

malfet commented Jun 17, 2022

@Maratyszcza does the change look good to you?
@petrhosek can you please share link to CMake doc explaining what namespace prefixes are and what version of cmake they got introduced

@petrhosek
Copy link
Copy Markdown
Contributor Author

It's a common convention in modern CMake to provide aliases for each installed library to ensure that the library can be consumes via target_link(<pkg>::<target_name>) both if the project is used via find_package(<pkg>) or via add_subdirectory.

See for example https://github.com/abseil/abseil-cpp/blob/d2c5297a3c3948de765100cb7e5cccca1210d23c/CMake/AbseilHelpers.cmake#L329. This can avoid similar constructs in downstream projects such as https://github.com/google/ruy/blob/368db7123bf3178c92c8502696c6865fb07bfcda/CMakeLists.txt#L85.

There's an ongoing discussion about how to supports this directly in CMake, see https://gitlab.kitware.com/cmake/cmake/-/issues/22687

@malfet malfet merged commit 082deff into pytorch:master Jun 17, 2022
@malfet
Copy link
Copy Markdown
Contributor

malfet commented Jun 17, 2022

Thank you for the explanation, looks good to me

@Maratyszcza
Copy link
Copy Markdown
Contributor

cc @bjacob

megengine-bot pushed a commit to MegEngine/cpuinfo that referenced this pull request Sep 5, 2022
…ch#89)

This allows projects that depend on cpuinfo to use namespace qualified
target name regardless of whether they consume cpuinfo through
add_subdirectory or find_package.

GitOrigin-RevId: 082deff
salilsdesai added a commit to salilsdesai/pytorch that referenced this pull request Sep 16, 2022
Summary:
Pull Request resolved: pytorch#84876

Fixes the following error when building qnnpack:
```
CMake Error: install(EXPORT "cpuinfo-targets" ...) includes target "cpuinfo" which requires target "clog" that is not in any export set.
```

This diff mirrors the changes to the CMakeLists of
- pytorch/cpuinfo#69
- pytorch/cpuinfo#89

Test Plan:
# Build Qnnpack
```
export ANDROID_NDK=/opt/android_ndk/r20
export ANDROID_NDK_HOME=${ANDROID_NDK}
export ANDROID_SDK=/opt/android_sdk
export ANDROID_HOME=${ANDROID_SDK}

cd ~/fbsource/fbcode/caffe2/aten/src/ATen/native/quantized/cpu/qnnpack

./scripts/build-android-arm64.sh
```
Succeeds

Differential Revision: D39438768

fbshipit-source-id: 9bd0119ffea984d274e85b8b756b630743a89f0f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants