diff --git a/COMPILE.md b/COMPILE.md index 2e83ad6b..e1bf15ba 100644 --- a/COMPILE.md +++ b/COMPILE.md @@ -148,7 +148,7 @@ for performance experiments and platform-specific builds. It keeps the same external calling style as `facedetect_cnn`, but exposes a separate entry point: ```C++ -#include "facedetect_hw.h" +#include int* results = facedetect_hw_cnn(buffer, bgr_image_data, width, height, step); ``` @@ -272,6 +272,32 @@ The current `hw` implementation follows the same deployment style as the original project: build separately for different instruction sets/platforms instead of using Highway runtime dynamic dispatch. +#### Installing and consuming via `find_package` + +The Highway module can also be installed and consumed as a CMake package. +After installing it, downstream projects discover it with `find_package`: + +```bash +cmake -S highway -B build-hw -DCMAKE_INSTALL_PREFIX= \ + -Dhwy_DIR=/lib/cmake/hwy +cmake --build build-hw +cmake --install build-hw +``` + +```cmake +# In the consumer project, with on CMAKE_PREFIX_PATH: +find_package(fdt_hw 0.0.3 REQUIRED CONFIG) +target_link_libraries(my_app PRIVATE fdt_hw::fdt_hw_kernels) +``` + +```C++ +#include +``` + +The generated package config re-discovers Highway via `find_dependency(hwy)`, so +the transitive `hwy::hwy` include/link requirements propagate to consumers +automatically; no manual include or link wiring is needed. + ### Cross build for aarch64 1. Set cross compiler for aarch64 (please refer to aarch64-toolchain.cmake). diff --git a/README.md b/README.md index 7f470e8f..b01ce9c1 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ An independent Highway-based implementation has been added under `highway/`. It keeps the original implementation untouched and exposes a separate C API: ```C++ -#include "facedetect_hw.h" +#include int* results = facedetect_hw_cnn(result_buffer, bgr_image_data, width, height, step); diff --git a/example/benchmark-highway.cpp b/example/benchmark-highway.cpp index 196b0bf9..113c1687 100644 --- a/example/benchmark-highway.cpp +++ b/example/benchmark-highway.cpp @@ -3,7 +3,7 @@ #include -#include "facedetect_hw.h" +#include #ifdef _OPENMP #include diff --git a/example/detect-image-highway.cpp b/example/detect-image-highway.cpp index a8b074eb..fa680efb 100644 --- a/example/detect-image-highway.cpp +++ b/example/detect-image-highway.cpp @@ -3,7 +3,7 @@ #include -#include "facedetect_hw.h" +#include #define DETECT_BUFFER_SIZE FACEDETECTION_HW_RESULT_BUFFER_SIZE diff --git a/highway/CMakeLists.txt b/highway/CMakeLists.txt index de0f4e63..3191978a 100644 --- a/highway/CMakeLists.txt +++ b/highway/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.15) -project(fdt_hw LANGUAGES CXX) +project(fdt_hw VERSION 0.0.3 LANGUAGES CXX) + +include(GNUInstallDirs) option(FDT_HW_BUILD_TESTS "Build hw doctest tests" ON) option(FDT_HW_BUILD_BENCHMARKS "Build hw benchmarks" ON) @@ -84,8 +86,9 @@ add_library(fdt_hw_kernels ) target_include_directories(fdt_hw_kernels PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_CURRENT_SOURCE_DIR}/src + $ + $ + $ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../src ) @@ -244,3 +247,44 @@ message(STATUS "FDT_HW_FORCE_SCALAR = ${FDT_HW_FORCE_SCALAR}") message(STATUS "FDT_HW_ENABLE_INTRINSICS_COMPARE = ${FDT_HW_ENABLE_INTRINSICS_COMPARE}") message(STATUS "FDT_HW_ENABLE_X86_AVX2 = ${FDT_HW_ENABLE_X86_AVX2}") message(STATUS "FDT_HW_ENABLE_HYBRID_CEILING = ${FDT_HW_ENABLE_HYBRID_CEILING}") + +# --------------------------------------------------------------------------- +# Install + package config so downstream projects can use find_package(fdt_hw). +# +# find_package(fdt_hw REQUIRED CONFIG) +# target_link_libraries(my_app PRIVATE fdt_hw::fdt_hw_kernels) +# +# The generated config re-discovers Highway via find_dependency(hwy), so the +# transitive hwy::hwy link/include usage requirements propagate automatically. +# --------------------------------------------------------------------------- +include(CMakePackageConfigHelpers) + +install(TARGETS fdt_hw_kernels + EXPORT fdt_hwTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/facedetect_hw.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/facedetection) + +install(EXPORT fdt_hwTargets + FILE fdt_hwTargets.cmake + NAMESPACE fdt_hw:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/fdt_hw) + +configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/fdt_hwConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/fdt_hwConfig.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/fdt_hw) + +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/fdt_hwConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/fdt_hwConfig.cmake + ${CMAKE_CURRENT_BINARY_DIR}/fdt_hwConfigVersion.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/fdt_hw) diff --git a/highway/cmake/fdt_hwConfig.cmake.in b/highway/cmake/fdt_hwConfig.cmake.in new file mode 100644 index 00000000..50abe46d --- /dev/null +++ b/highway/cmake/fdt_hwConfig.cmake.in @@ -0,0 +1,11 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) + +# fdt_hw_kernels links Highway as a PUBLIC dependency, so consumers must be able +# to resolve the hwy::hwy imported target before the exported targets are loaded. +find_dependency(hwy 1.3.0) + +include("${CMAKE_CURRENT_LIST_DIR}/fdt_hwTargets.cmake") + +check_required_components(fdt_hw) \ No newline at end of file