From 3b1fb04d63ae3434a74228fe91f4a1386934781e Mon Sep 17 00:00:00 2001 From: Jan Date: Thu, 27 Mar 2025 20:34:18 +0100 Subject: [PATCH] Build Mmap.hh even if memory mapping is disabled Build flag `ZK_ENABLE_MMAP` no longer excludes relevant header and implementation files from build -> Users of ZenKit can now use Mmap.hh by themselves even if `ZK_ENABLE_MMAP` is `OFF` --- CMakeLists.txt | 27 +++++++++++++++++---------- include/zenkit/Mmap.hh | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e000ceb1..62afbacb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ option(ZK_BUILD_SHARED "ZenKit: Build a shared library." OFF) option(ZK_ENABLE_ASAN "ZenKit: Enable sanitizers in debug builds." ON) option(ZK_ENABLE_DEPRECATION "ZenKit: Enable deprecation warnings." ON) option(ZK_ENABLE_INSTALL "ZenKit: Enable CMake install target creation." ON) -option(ZK_ENABLE_MMAP "ZenKit: Build ZenKit with memory-mapping support." ON) +option(ZK_ENABLE_MMAP "ZenKit: Build ZenKit with memory-mapping if supported by platform." ON) option(ZK_ENABLE_FUTURE "ZenKit: Enable breaking changes to be release in a future version" OFF) add_subdirectory(vendor) @@ -118,18 +118,25 @@ bs_select_cflags(${ZK_ENABLE_ASAN} _ZK_COMPILE_FLAGS _ZK_LINK_FLAGS) bs_check_posix_mmap(_ZK_HAS_MMAP_POSIX) bs_check_win32_mmap(_ZK_HAS_MMAP_WIN32) -if (ZK_ENABLE_MMAP AND (_ZK_HAS_MMAP_POSIX OR _ZK_HAS_MMAP_WIN32)) - if (_ZK_HAS_MMAP_POSIX) - message(STATUS "ZenKit: Building with POSIX memory mapping support") - list(APPEND _ZK_SOURCES src/MmapPosix.cc) - target_compile_definitions(zenkit PUBLIC _ZK_WITH_MMAP=1) - elseif (_ZK_HAS_MMAP_WIN32) - message(STATUS "ZenKit: Building with Windows memory mapping support") - list(APPEND _ZK_SOURCES src/MmapWin32.cc) +if (_ZK_HAS_MMAP_POSIX) + message(STATUS "ZenKit: POSIX memory mapping available") + list(APPEND _ZK_SOURCES src/MmapPosix.cc) + target_compile_definitions(zenkit PUBLIC _ZK_MMAP_AVAILABLE=1) +elseif (_ZK_HAS_MMAP_WIN32) + message(STATUS "ZenKit: Windows memory mapping available") + list(APPEND _ZK_SOURCES src/MmapWin32.cc) + target_compile_definitions(zenkit PUBLIC _ZK_MMAP_AVAILABLE=1) +endif () + +if (ZK_ENABLE_MMAP) + if (_ZK_HAS_MMAP_POSIX OR _ZK_HAS_MMAP_WIN32) + message(STATUS "ZenKit: Memory mapping enabled") target_compile_definitions(zenkit PUBLIC _ZK_WITH_MMAP=1) + elseif (ZK_ENABLE_MMAP) + message(WARNING "ZenKit: Memory mapping enabled but not supported!") endif () else () - message(WARNING "ZenKit: Building WITHOUT memory mapping support") + message(STATUS "ZenKit: Memory mapping disabled") endif () target_sources(zenkit PRIVATE ${_ZK_SOURCES} ${_ZK_HEADERS}) diff --git a/include/zenkit/Mmap.hh b/include/zenkit/Mmap.hh index db8ce1dc..abec1361 100644 --- a/include/zenkit/Mmap.hh +++ b/include/zenkit/Mmap.hh @@ -4,7 +4,7 @@ #include namespace zenkit { -#ifdef _ZK_WITH_MMAP +#ifdef _ZK_MMAP_AVAILABLE class Mmap { public: explicit Mmap(std::filesystem::path const& path);