[PATCH] Add support for find_package + Config mode
authorMathieu Malaterre <mathieu.malaterre@gmail.com>
Mon, 30 Jan 2023 07:49:29 +0000 (08:49 +0100)
committerMathieu Malaterre <malat@debian.org>
Fri, 24 Feb 2023 07:52:20 +0000 (07:52 +0000)
Also prepend target names with hwy:: namespace for better CMake user
experience.

Gbp-Pq: Name bf4eef67e8f1864aa55aafc3cf125bf38db20d12.patch

CMakeLists.txt

index a47f39b698966820fd59530e6f33831a2407fa6e..0cf9478327e9ff42fea8212f7dc72449f29d2f0e 100644 (file)
@@ -26,6 +26,8 @@ if(POLICY CMP0111)
 endif()
 
 project(hwy VERSION 1.0.3)  # Keep in sync with highway.h version
+# `hwy` is lowercase to handle find_package() in Config mode:
+set(namespace "${PROJECT_NAME}::")
 
 # Directly define the ABI version from the cmake project() version values:
 set(LIBRARY_VERSION "${hwy_VERSION}")
@@ -572,8 +574,8 @@ target_sources(skeleton_test PRIVATE hwy/examples/skeleton.cc)
 
 endif()  # BUILD_TESTING
 
-# write HWYConfig file:
+# write hwy-config file to handle `Config` mode
 include(CMakePackageConfigHelpers)
-write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/HWYConfigVersion.cmake" COMPATIBILITY SameMajorVersion)
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/HWYConfigVersion.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/hwy")
-install(EXPORT hwy_targets FILE HWYConfig.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/hwy")
+write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/hwy-config-version.cmake" COMPATIBILITY SameMajorVersion)
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hwy-config-version.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/hwy")
+install(EXPORT hwy_targets NAMESPACE "${namespace}" FILE hwy-config.cmake DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/hwy")