From 99bf9204d043dbaa4f56ee17d80e5b1f8a5f3f86 Mon Sep 17 00:00:00 2001 From: Jan Wassenberg Date: Thu, 2 May 2024 06:11:10 -0700 Subject: [PATCH] experimental CMAKE_HEADER_ONLY flag, refs #2114 PiperOrigin-RevId: 630041101 --- CMakeLists.txt | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8c3fe23ac..7b9d732ce4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,9 @@ set(HWY_CMAKE_RVV ON CACHE BOOL "Set copts for RISCV with RVV?") # arise due to compiler/platform changes. Enable this in CI/tests. set(HWY_WARNINGS_ARE_ERRORS OFF CACHE BOOL "Add -Werror flag?") +# Experimental support for header-only builds +set(HWY_CMAKE_HEADER_ONLY OFF CACHE BOOL "Change to header-only?") + set(HWY_ENABLE_CONTRIB ON CACHE BOOL "Include contrib/") set(HWY_ENABLE_EXAMPLES ON CACHE BOOL "Build examples") set(HWY_ENABLE_INSTALL ON CACHE BOOL "Install library") @@ -137,9 +140,7 @@ list(APPEND HWY_CONTRIB_SOURCES endif() # HWY_ENABLE_CONTRIB set(HWY_SOURCES - hwy/abort.cc hwy/abort.h - hwy/aligned_allocator.cc hwy/aligned_allocator.h hwy/base.h hwy/cache_control.h @@ -148,7 +149,6 @@ set(HWY_SOURCES hwy/foreach_target.h hwy/highway_export.h hwy/highway.h - hwy/nanobenchmark.cc hwy/nanobenchmark.h hwy/ops/arm_neon-inl.h hwy/ops/arm_sve-inl.h @@ -164,20 +164,28 @@ set(HWY_SOURCES hwy/ops/x86_128-inl.h hwy/ops/x86_256-inl.h hwy/ops/x86_512-inl.h - hwy/per_target.cc hwy/per_target.h hwy/print-inl.h - hwy/print.cc hwy/print.h hwy/profiler.h hwy/robust_statistics.h - hwy/targets.cc hwy/targets.h hwy/timer-inl.h - hwy/timer.cc hwy/timer.h ) +if (HWY_CMAKE_HEADER_ONLY) + list(APPEND HWY_SOURCES + hwy/abort.cc + hwy/aligned_allocator.cc + hwy/nanobenchmark.cc + hwy/per_target.cc + hwy/print.cc + hwy/targets.cc + hwy/timer.cc + ) +endif() + set(HWY_TEST_SOURCES hwy/tests/hwy_gtest.h hwy/tests/test_util-inl.h @@ -367,6 +375,10 @@ else() endif() # !MSVC +if (HWY_CMAKE_HEADER_ONLY) + list(APPEND HWY_FLAGS -DHWY_HEADER_ONLY) +endif() + include(CheckIncludeFile) check_include_file(sys/auxv.h HAVE_SYS_AUXV_H) check_include_file(asm/hwcap.h HAVE_ASM_HWCAP_H)