Skip to content

Commit 7015057

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 7015057

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

CMakeLists.txt

Lines changed: 20 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,28 @@ 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 OR _ZK_HAS_MMAP_WIN32)
122+
target_compile_definitions(zenkit PUBLIC _ZK_MMAP_AVAILABLE=1)
123+
if (ZK_ENABLE_MMAP)
124+
message(STATUS "ZenKit: Memory mapping enabled")
129125
target_compile_definitions(zenkit PUBLIC _ZK_WITH_MMAP=1)
126+
else ()
127+
message(STATUS "ZenKit: Memory mapping disabled")
130128
endif ()
131129
else ()
132-
message(WARNING "ZenKit: Building WITHOUT memory mapping support")
130+
if (ZK_ENABLE_MMAP)
131+
message(WARNING "ZenKit: Memory mapping enabled but not supported!")
132+
else ()
133+
message(STATUS "ZenKit: Memory mapping not supported")
134+
endif ()
135+
endif ()
136+
137+
if (_ZK_HAS_MMAP_POSIX)
138+
message(STATUS "ZenKit: Building with POSIX memory mapping support")
139+
list(APPEND _ZK_SOURCES src/MmapPosix.cc)
140+
elseif (_ZK_HAS_MMAP_WIN32)
141+
message(STATUS "ZenKit: Building with Windows memory mapping support")
142+
list(APPEND _ZK_SOURCES src/MmapWin32.cc)
133143
endif ()
134144

135145
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)