Skip to content

Commit

Permalink
Merge pull request #28 from unknownv2/cmake-support
Browse files Browse the repository at this point in the history
Add CMake support for x86 and x64 architectures
  • Loading branch information
unknownv2 authored Dec 2, 2018
2 parents 5933a99 + 5c97c94 commit 2c00c15
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 1 deletion.
71 changes: 71 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
cmake_minimum_required(VERSION 3.2)

set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")

set(COREHOOK_INSTALL_INCLUDE_DIR ${PROJECT_SOURCE_DIR})
set(COREHOOK_INSTALL_BIN_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(COREHOOK_INSTALL_LIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib)

include_directories(${COREHOOK_INSTALL_INCLUDE_DIR})

project(corehook)
set(TARGET detours)

set(SOURCE_FILES
src/barrier.cpp
src/creatwth.cpp
src/detours.cpp
src/disasm.cpp
src/disolarm.cpp
src/disolarm64.cpp
src/disolia64.cpp
src/disolx64.cpp
src/disolx86.cpp
src/image.cpp
src/modules.cpp
)

set(COREHOOK_SOURCES
dll/corehook/corehook.cpp
dll/corehook/corehook.def
)

include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
src
)

add_library(corehook SHARED ${COREHOOK_SOURCES})

enable_language(ASM_MASM)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
set_target_properties(corehook PROPERTIES OUTPUT_NAME corehook32)
set_target_properties(corehook PROPERTIES LINK_FLAGS "/SAFESEH:NO")
set(SOURCE_ASM
src/trampolinex86.asm
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
set_target_properties(corehook PROPERTIES OUTPUT_NAME corehook64)
set(SOURCE_ASM
src/trampolinex64.asm
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM")
set_target_properties(corehook PROPERTIES OUTPUT_NAME corehook32)
set(SOURCE_ASM
src/trampolinearm.asm
)
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM64")
set_target_properties(corehook PROPERTIES OUTPUT_NAME corehook64)
set(SOURCE_ASM
src/trampolinearm64.asm
)
endif()

add_library(detours STATIC ${SOURCE_FILES} ${SOURCE_ASM})

target_link_libraries(corehook detours aux_ulib)

install(TARGETS detours DESTINATION ${COREHOOK_INSTALL_BIN_DIR})

12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ For [CoreHook](https://github.com/unknownv2/CoreHook), the [Microsoft Detours](h

## Building

Building the DLL requires Visual Studio and there are two options: You can build the DLL by using the `Visual Studio IDE` or `msbuild` within the `Developer Command Prompt`, or `nmake` (it has been tested with `Visual Studio 2017` only).
Building the DLL requires Visual Studio and there are three options: You can build the DLL by using the `Visual Studio IDE` or `msbuild` within the `Developer Command Prompt`, `cmake`, or `nmake` (it has been tested with `Visual Studio 2017` only).

### Visual Studio

You can find the Visual Studio solution inside [the msvc folder](/msvc). You can choose a configuration (**Debug|Release**) and a platform (**X86|X64|ARM|ARM64**) and build.

An example for building the X64 `corehook64.dll` in the Release configuration:
Expand All @@ -32,6 +33,15 @@ nuget restore msvc/corehook.sln
msbuild msvc/corehook.sln /p:Configuration=Release /p:Platform=x64
```

### CMake

You can also build the library using CMake. You can run the `build/win-vs-2017.cmd` file to build for the `x86` and `x64` architectures. This also gives you the option to generate and build with an older version of `Visual Studio` such as `VS 2015` or `VS 2013`.

You can build by running these commands from the root of the repository:
```
cd build
win-vs-2017.cmd
```

### NMAKE

Expand Down
14 changes: 14 additions & 0 deletions build/win-vs-2017.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
cd ../
mkdir build32-vs2017
mkdir build64-vs2017
cd build32-vs2017
cmake -G "Visual Studio 15 2017" ../
cd ../
cd build64-vs2017
cmake -G "Visual Studio 15 2017 Win64" ../
cd ../
cmake --build build32-vs2017 --config Debug
cmake --build build32-vs2017 --config Release
cmake --build build64-vs2017 --config Debug
cmake --build build64-vs2017 --config Release
cd build

0 comments on commit 2c00c15

Please sign in to comment.