Skip to content

Commit

Permalink
Add support for consumption by projects that use C++ modules (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
netadr authored Feb 27, 2024
1 parent 91fbc79 commit 3f157c8
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ option(SAFETYHOOK_BUILD_TEST "" OFF)
option(SAFETYHOOK_BUILD_EXAMPLES "" OFF)
option(SAFETYHOOK_AMALGAMATE "" OFF)
option(SAFETYHOOK_FETCH_ZYDIS "" OFF)
option(SAFETYHOOK_USE_CXXMODULES "" OFF)

project(safetyhook)

Expand Down Expand Up @@ -146,6 +147,11 @@ target_link_libraries(safetyhook PUBLIC
Zydis
)

set(CMKR_TARGET safetyhook)
if(SAFETYHOOK_USE_CXXMODULES)
target_compile_definitions(safetyhook INTERFACE SAFETYHOOK_USE_CXXMODULES)
endif()

# Target: docs
if(SAFETYHOOK_BUILD_DOCS) # build-docs
set(CMKR_TARGET docs)
Expand Down
6 changes: 6 additions & 0 deletions cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SAFETYHOOK_BUILD_TEST = false
SAFETYHOOK_BUILD_EXAMPLES = false
SAFETYHOOK_AMALGAMATE = false
SAFETYHOOK_FETCH_ZYDIS = false
SAFETYHOOK_USE_CXXMODULES = false

[conditions]
build-docs = "SAFETYHOOK_BUILD_DOCS"
Expand Down Expand Up @@ -59,6 +60,11 @@ link-libraries = ["Zydis"]
msvc.private-compile-options = ["/permissive-", "/W4", "/w14640"]
clang.private-compile-options = ["-Wall", "-Wextra", "-Wshadow", "-Wnon-virtual-dtor", "-pedantic"]
gcc.private-compile-options = ["-Wall", "-Wextra", "-Wshadow", "-Wnon-virtual-dtor", "-pedantic"]
cmake-after = """
if(SAFETYHOOK_USE_CXXMODULES)
target_compile_definitions(safetyhook INTERFACE SAFETYHOOK_USE_CXXMODULES)
endif()
"""

[target.docs]
condition = "build-docs"
Expand Down
4 changes: 4 additions & 0 deletions include/safetyhook/allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

#pragma once

#ifndef SAFETYHOOK_USE_CXXMODULES
#include <cstdint>
#include <expected>
#include <memory>
#include <mutex>
#include <vector>
#else
import std.compat;
#endif

namespace safetyhook {
class Allocator;
Expand Down
4 changes: 4 additions & 0 deletions include/safetyhook/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

#pragma once

#ifndef SAFETYHOOK_USE_CXXMODULES
#include <cstdint>
#else
import std.compat;
#endif

#include "safetyhook/common.hpp"

Expand Down
4 changes: 4 additions & 0 deletions include/safetyhook/inline_hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

#pragma once

#ifndef SAFETYHOOK_USE_CXXMODULES
#include <cstdint>
#include <expected>
#include <memory>
#include <mutex>
#include <utility>
#include <vector>
#else
import std.compat;
#endif

#include "safetyhook/allocator.hpp"
#include "safetyhook/common.hpp"
Expand Down
4 changes: 4 additions & 0 deletions include/safetyhook/mid_hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@

#pragma once

#ifndef SAFETYHOOK_USE_CXXMODULES
#include <cstdint>
#include <memory>
#else
import std.compat;
#endif

#include "safetyhook/allocator.hpp"
#include "safetyhook/context.hpp"
Expand Down
4 changes: 4 additions & 0 deletions include/safetyhook/os.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// This is the OS abstraction layer.
#pragma once

#ifndef SAFETYHOOK_USE_CXXMODULES
#include <cstdint>
#include <expected>
#include <functional>
#else
import std.compat;
#endif

namespace safetyhook {

Expand Down
4 changes: 4 additions & 0 deletions include/safetyhook/utility.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#pragma once

#ifndef SAFETYHOOK_USE_CXXMODULES
#include <algorithm>
#include <cstdint>
#include <optional>
#include <type_traits>
#else
import std.compat;
#endif

namespace safetyhook {
template <typename T> constexpr void store(uint8_t* address, const T& value) {
Expand Down
4 changes: 4 additions & 0 deletions include/safetyhook/vmt_hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@

#pragma once

#ifndef SAFETYHOOK_USE_CXXMODULES
#include <cstdint>
#include <expected>
#include <unordered_map>
#else
import std.compat;
#endif

#include "safetyhook/allocator.hpp"
#include "safetyhook/common.hpp"
Expand Down

0 comments on commit 3f157c8

Please sign in to comment.