pytorch / cpuinfo

CPU INFOrmation library (x86/x86-64/ARM/ARM64, Linux/Windows/Android/macOS/iOS)
BSD 2-Clause "Simplified" License
992 stars 311 forks source link

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

Closed petrhosek closed 2 years ago

petrhosek commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

petrhosek commented 2 years ago

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

Maratyszcza commented 2 years ago

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

malfet commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

Thank you for the explanation, looks good to me

Maratyszcza commented 2 years ago

cc @bjacob