Skip to content

Commit 3b1fb04

Browse files
committed
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`
1 parent 8c4edf7 commit 3b1fb04

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

CMakeLists.txt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ option(ZK_BUILD_SHARED "ZenKit: Build a shared library." OFF)
1010
option(ZK_ENABLE_ASAN "ZenKit: Enable sanitizers in debug builds." ON)
1111
option(ZK_ENABLE_DEPRECATION "ZenKit: Enable deprecation warnings." ON)
1212
option(ZK_ENABLE_INSTALL "ZenKit: Enable CMake install target creation." ON)
13-
option(ZK_ENABLE_MMAP "ZenKit: Build ZenKit with memory-mapping support." ON)
13+
option(ZK_ENABLE_MMAP "ZenKit: Build ZenKit with memory-mapping if supported by platform." ON)
1414
option(ZK_ENABLE_FUTURE "ZenKit: Enable breaking changes to be release in a future version" OFF)
1515

1616
add_subdirectory(vendor)
@@ -118,18 +118,25 @@ bs_select_cflags(${ZK_ENABLE_ASAN} _ZK_COMPILE_FLAGS _ZK_LINK_FLAGS)
118118
bs_check_posix_mmap(_ZK_HAS_MMAP_POSIX)
119119
bs_check_win32_mmap(_ZK_HAS_MMAP_WIN32)
120120

121-
if (ZK_ENABLE_MMAP AND (_ZK_HAS_MMAP_POSIX OR _ZK_HAS_MMAP_WIN32))
122-
if (_ZK_HAS_MMAP_POSIX)
123-
message(STATUS "ZenKit: Building with POSIX memory mapping support")
124-
list(APPEND _ZK_SOURCES src/MmapPosix.cc)
125-
target_compile_definitions(zenkit PUBLIC _ZK_WITH_MMAP=1)
126-
elseif (_ZK_HAS_MMAP_WIN32)
127-
message(STATUS "ZenKit: Building with Windows memory mapping support")
128-
list(APPEND _ZK_SOURCES src/MmapWin32.cc)
121+
if (_ZK_HAS_MMAP_POSIX)
122+
message(STATUS "ZenKit: POSIX memory mapping available")
123+
list(APPEND _ZK_SOURCES src/MmapPosix.cc)
124+
target_compile_definitions(zenkit PUBLIC _ZK_MMAP_AVAILABLE=1)
125+
elseif (_ZK_HAS_MMAP_WIN32)
126+
message(STATUS "ZenKit: Windows memory mapping available")
127+
list(APPEND _ZK_SOURCES src/MmapWin32.cc)
128+
target_compile_definitions(zenkit PUBLIC _ZK_MMAP_AVAILABLE=1)
129+
endif ()
130+
131+
if (ZK_ENABLE_MMAP)
132+
if (_ZK_HAS_MMAP_POSIX OR _ZK_HAS_MMAP_WIN32)
133+
message(STATUS "ZenKit: Memory mapping enabled")
129134
target_compile_definitions(zenkit PUBLIC _ZK_WITH_MMAP=1)
135+
elseif (ZK_ENABLE_MMAP)
136+
message(WARNING "ZenKit: Memory mapping enabled but not supported!")
130137
endif ()
131138
else ()
132-
message(WARNING "ZenKit: Building WITHOUT memory mapping support")
139+
message(STATUS "ZenKit: Memory mapping disabled")
133140
endif ()
134141

135142
target_sources(zenkit PRIVATE ${_ZK_SOURCES} ${_ZK_HEADERS})

include/zenkit/Mmap.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include <filesystem>
55

66
namespace zenkit {
7-
#ifdef _ZK_WITH_MMAP
7+
#ifdef _ZK_MMAP_AVAILABLE
88
class Mmap {
99
public:
1010
explicit Mmap(std::filesystem::path const& path);

0 commit comments

Comments
 (0)