-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
74 lines (63 loc) · 2.37 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# CMakeLists.txt --- CMake project settings
# ex) cmake -G "Visual Studio 9 2008" .
# ex) cmake -DCMAKE_BUILD_TYPE=Release -G "MSYS Makefiles" .
##############################################################################
# CMake minimum version
cmake_minimum_required(VERSION 3.0)
# project name and languages
project(CBTHooker CXX RC)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# using Clang
set(CMAKE_C_FLAGS "-static")
set(CMAKE_CXX_FLAGS "-static")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# using GCC
set(CMAKE_C_FLAGS "-static")
set(CMAKE_CXX_FLAGS "-static")
elseif (MSVC)
# replace "/MD" with "/MT" (building without runtime DLLs)
set(CompilerFlags
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO)
foreach(CompilerFlags ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlags} "${${CompilerFlags}}")
endforeach()
endif()
##############################################################################
# Unicode support
add_definitions(-DUNICODE -D_UNICODE)
# Win64 support
option(SUPPORT_WIN64 "Win64 support" ON)
if(SUPPORT_WIN64)
add_definitions(-DSUPPORT_WIN64)
endif()
# dll32.dll and dll64.dll
add_library(dll SHARED dll/dll.cpp dll/dll.def)
target_link_libraries(dll PRIVATE)
set_target_properties(dll PROPERTIES PREFIX "")
target_compile_definitions(dll PRIVATE -DCBTHOOK_DLL)
# watcher32.exe and watcher64.exe
add_executable(watcher watcher/watcher.cpp)
target_link_libraries(watcher PRIVATE dll)
target_compile_definitions(watcher PRIVATE)
# 32-bit or 64-bit?
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set_target_properties(dll PROPERTIES OUTPUT_NAME "dll64")
set_target_properties(watcher PROPERTIES OUTPUT_NAME "watcher64")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set_target_properties(dll PROPERTIES OUTPUT_NAME "dll32")
set_target_properties(watcher PROPERTIES OUTPUT_NAME "watcher32")
# CBTHooker.exe
add_executable(CBTHooker WIN32 hooker/CBTHooker.cpp hooker/CBTHooker_res.rc)
target_link_libraries(CBTHooker PRIVATE comctl32 shlwapi)
target_compile_definitions(CBTHooker PRIVATE)
else()
message(FATAL_ERROR "You lose.")
endif()
##############################################################################