Skip to content

Commit

Permalink
Fix/MinGW cleanup (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
cursey authored Jan 30, 2024
1 parent 4e10523 commit ac0f562
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 242 deletions.
224 changes: 0 additions & 224 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,38 +215,6 @@ if(SAFETYHOOK_BUILD_TESTS) # build-tests
cxx_std_23
)

if(MSVC) # msvc
target_compile_options(test0 PRIVATE
"/WX"
"/permissive-"
"/W4"
"/w14640"
"/EHsc"
)
endif()

if((CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$") OR (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$")) # clang
target_compile_options(test0 PRIVATE
-Werror
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-pedantic
)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "GNU") # gcc
target_compile_options(test0 PRIVATE
-Werror
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-pedantic
)
endif()

target_link_libraries(test0 PRIVATE
safetyhook::safetyhook
)
Expand All @@ -273,38 +241,6 @@ if(SAFETYHOOK_BUILD_TESTS) # build-tests
cxx_std_23
)

if(MSVC) # msvc
target_compile_options(test1 PRIVATE
"/WX"
"/permissive-"
"/W4"
"/w14640"
"/EHsc"
)
endif()

if((CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$") OR (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$")) # clang
target_compile_options(test1 PRIVATE
-Werror
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-pedantic
)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "GNU") # gcc
target_compile_options(test1 PRIVATE
-Werror
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-pedantic
)
endif()

target_link_libraries(test1 PRIVATE
safetyhook::safetyhook
)
Expand All @@ -331,38 +267,6 @@ if(SAFETYHOOK_BUILD_TESTS) # build-tests
cxx_std_23
)

if(MSVC) # msvc
target_compile_options(test2 PRIVATE
"/WX"
"/permissive-"
"/W4"
"/w14640"
"/EHsc"
)
endif()

if((CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$") OR (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$")) # clang
target_compile_options(test2 PRIVATE
-Werror
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-pedantic
)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "GNU") # gcc
target_compile_options(test2 PRIVATE
-Werror
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-pedantic
)
endif()

target_link_libraries(test2 PRIVATE
safetyhook::safetyhook
)
Expand All @@ -389,38 +293,6 @@ if(SAFETYHOOK_BUILD_TESTS) # build-tests
cxx_std_23
)

if(MSVC) # msvc
target_compile_options(test3 PRIVATE
"/WX"
"/permissive-"
"/W4"
"/w14640"
"/EHsc"
)
endif()

if((CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$") OR (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$")) # clang
target_compile_options(test3 PRIVATE
-Werror
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-pedantic
)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "GNU") # gcc
target_compile_options(test3 PRIVATE
-Werror
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-pedantic
)
endif()

target_link_libraries(test3 PRIVATE
safetyhook::safetyhook
)
Expand All @@ -447,38 +319,6 @@ if(SAFETYHOOK_BUILD_TESTS) # build-tests
cxx_std_23
)

if(MSVC) # msvc
target_compile_options(test4 PRIVATE
"/WX"
"/permissive-"
"/W4"
"/w14640"
"/EHsc"
)
endif()

if((CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$") OR (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$")) # clang
target_compile_options(test4 PRIVATE
-Werror
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-pedantic
)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "GNU") # gcc
target_compile_options(test4 PRIVATE
-Werror
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-pedantic
)
endif()

target_link_libraries(test4 PUBLIC
safetyhook::safetyhook
)
Expand All @@ -504,38 +344,6 @@ if(SAFETYHOOK_BUILD_TESTS) # build-tests
cxx_std_23
)

if(MSVC) # msvc
target_compile_options(unittest PRIVATE
"/WX"
"/permissive-"
"/W4"
"/w14640"
"/EHsc"
)
endif()

if((CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$") OR (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$")) # clang
target_compile_options(unittest PRIVATE
-Werror
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-pedantic
)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "GNU") # gcc
target_compile_options(unittest PRIVATE
-Werror
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-pedantic
)
endif()

target_link_libraries(unittest PRIVATE
safetyhook::safetyhook
)
Expand Down Expand Up @@ -574,38 +382,6 @@ if(SAFETYHOOK_BUILD_TESTS) # build-tests
cxx_std_23
)

if(MSVC) # msvc
target_compile_options(unittest-amalgamated PRIVATE
"/WX"
"/permissive-"
"/W4"
"/w14640"
"/EHsc"
)
endif()

if((CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$") OR (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$")) # clang
target_compile_options(unittest-amalgamated PRIVATE
-Werror
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-pedantic
)
endif()

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "GNU") # gcc
target_compile_options(unittest-amalgamated PRIVATE
-Werror
-Wall
-Wextra
-Wshadow
-Wnon-virtual-dtor
-pedantic
)
endif()

target_link_libraries(unittest-amalgamated PRIVATE
safetyhook::safetyhook
)
Expand Down
6 changes: 0 additions & 6 deletions cmake.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,12 @@ condition = "build-tests"
type = "executable"
link-libraries = ["safetyhook::safetyhook"]
compile-features = ["cxx_std_23"]
msvc.private-compile-options = ["/WX", "/permissive-", "/W4", "/w14640", "/EHsc"]
clang.private-compile-options = ["-Werror", "-Wall", "-Wextra", "-Wshadow", "-Wnon-virtual-dtor", "-pedantic"]
gcc.private-compile-options = ["-Werror", "-Wall", "-Wextra", "-Wshadow", "-Wnon-virtual-dtor", "-pedantic"]

[template.test-dll]
condition = "build-tests"
type = "shared"
link-libraries = ["safetyhook::safetyhook"]
compile-features = ["cxx_std_23"]
msvc.private-compile-options = ["/WX", "/permissive-", "/W4", "/w14640", "/EHsc"]
clang.private-compile-options = ["-Werror", "-Wall", "-Wextra", "-Wshadow", "-Wnon-virtual-dtor", "-pedantic"]
gcc.private-compile-options = ["-Werror", "-Wall", "-Wextra", "-Wshadow", "-Wnon-virtual-dtor", "-pedantic"]

[target.test0]
type = "test"
Expand Down
20 changes: 10 additions & 10 deletions include/safetyhook/mid_hook.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,41 +50,41 @@ class MidHook final {

/// @brief Creates a new MidHook object.
/// @param target The address of the function to hook.
/// @param destination The destination function.
/// @param destination_fn The destination function.
/// @return The MidHook object or a MidHook::Error if an error occurred.
/// @note This will use the default global Allocator.
/// @note If you don't care about error handling, use the easy API (safetyhook::create_mid).
[[nodiscard]] static std::expected<MidHook, Error> create(void* target, MidHookFn destination);
[[nodiscard]] static std::expected<MidHook, Error> create(void* target, MidHookFn destination_fn);

/// @brief Creates a new MidHook object.
/// @param target The address of the function to hook.
/// @param destination The destination function.
/// @param destination_fn The destination function.
/// @return The MidHook object or a MidHook::Error if an error occurred.
/// @note This will use the default global Allocator.
/// @note If you don't care about error handling, use the easy API (safetyhook::create_mid).
[[nodiscard]] static std::expected<MidHook, Error> create(FnPtr auto target, MidHookFn destination) {
return create(reinterpret_cast<void*>(target), destination);
[[nodiscard]] static std::expected<MidHook, Error> create(FnPtr auto target, MidHookFn destination_fn) {
return create(reinterpret_cast<void*>(target), destination_fn);
}

/// @brief Creates a new MidHook object with a given Allocator.
/// @param allocator The Allocator to use.
/// @param target The address of the function to hook.
/// @param destination The destination function.
/// @param destination_fn The destination function.
/// @return The MidHook object or a MidHook::Error if an error occurred.
/// @note If you don't care about error handling, use the easy API (safetyhook::create_mid).
[[nodiscard]] static std::expected<MidHook, Error> create(
const std::shared_ptr<Allocator>& allocator, void* target, MidHookFn destination);
const std::shared_ptr<Allocator>& allocator, void* target, MidHookFn destination_fn);

/// @brief Creates a new MidHook object with a given Allocator.
/// @tparam T The type of the function to hook.
/// @param allocator The Allocator to use.
/// @param target The address of the function to hook.
/// @param destination The destination function.
/// @param destination_fn The destination function.
/// @return The MidHook object or a MidHook::Error if an error occurred.
/// @note If you don't care about error handling, use the easy API (safetyhook::create_mid).
[[nodiscard]] static std::expected<MidHook, Error> create(
const std::shared_ptr<Allocator>& allocator, FnPtr auto target, MidHookFn destination) {
return create(allocator, reinterpret_cast<void*>(target), destination);
const std::shared_ptr<Allocator>& allocator, FnPtr auto target, MidHookFn destination_fn) {
return create(allocator, reinterpret_cast<void*>(target), destination_fn);
}

MidHook() = default;
Expand Down
4 changes: 2 additions & 2 deletions src/mid_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ void MidHook::reset() {
}

std::expected<void, MidHook::Error> MidHook::setup(
const std::shared_ptr<Allocator>& allocator, uint8_t* target, MidHookFn destination) {
const std::shared_ptr<Allocator>& allocator, uint8_t* target, MidHookFn destination_fn) {
m_target = target;
m_destination = destination;
m_destination = destination_fn;

auto stub_allocation = allocator->allocate(asm_data.size());

Expand Down
1 change: 1 addition & 0 deletions tests/test3.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <iostream>
#include <thread>

#include <safetyhook.hpp>

Expand Down
2 changes: 2 additions & 0 deletions unittest/inline_hook.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <thread>

#include <catch2/catch_test_macros.hpp>
#include <safetyhook.hpp>
#include <xbyak/xbyak.h>
Expand Down

0 comments on commit ac0f562

Please sign in to comment.