diff options
author | Kefu Chai <tchaikov@gmail.com> | 2024-02-11 09:53:26 +0100 |
---|---|---|
committer | Kefu Chai <tchaikov@gmail.com> | 2024-02-11 09:57:38 +0100 |
commit | 0de5755531e890e26c37a184db98b40538d25286 (patch) | |
tree | 93333415671371bdaf59fe618c4b37b669baf1cd /cmake/modules/Findcap.cmake | |
parent | Merge pull request #55525 from zdover23/wip-doc-2024-02-11-radosgw-55524-roll... (diff) | |
download | ceph-0de5755531e890e26c37a184db98b40538d25286.tar.xz ceph-0de5755531e890e26c37a184db98b40538d25286.zip |
cmake: find_package(cap) before linking against it
before this change, we link against libcap without finding it. this
works fine as long as libcap-devel or libcap-dev is installed in the
system. but if it is not, the source would fail to build due to missing
`sys/capability.h`. this is not a great developer experience.
in this change, a `Findcap.cmake` is added to find the capability
library. which would fail the build at the configure phase.
Signed-off-by: Kefu Chai <tchaikov@gmail.com>
Diffstat (limited to 'cmake/modules/Findcap.cmake')
-rw-r--r-- | cmake/modules/Findcap.cmake | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/cmake/modules/Findcap.cmake b/cmake/modules/Findcap.cmake new file mode 100644 index 00000000000..f33b22d2c29 --- /dev/null +++ b/cmake/modules/Findcap.cmake @@ -0,0 +1,35 @@ +# Try to find libcap +# +find_package(PkgConfig QUIET REQUIRED) + +pkg_check_modules(PC_cap QUIET cap) + +find_library(cap_LIBRARY + NAMES cap + HINTS + ${PC_cap_LIBDIR} + ${PC_cap_LIBRARY_DIRS}) + +find_path(cap_INCLUDE_DIR + NAMES sys/capability.h + HINTS + ${PC_cap_INCLUDEDIR} + ${PC_cap_INCLUDE_DIRS}) + +mark_as_advanced( + cap_LIBRARY + cap_INCLUDE_DIR) + +include (FindPackageHandleStandardArgs) +find_package_handle_standard_args (cap + REQUIRED_VARS + cap_LIBRARY + cap_INCLUDE_DIR) + +if(cap_FOUND AND NOT TARGET cap::cap) + add_library(cap::cap UNKNOWN IMPORTED) + set_target_properties(cap::cap + PROPERTIES + IMPORTED_LOCATION ${cap_LIBRARY} + INTERFACE_INCLUDE_DIRECTORIES ${cap_INCLUDE_DIR}) +endif() |