-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCMakeLists.txt
141 lines (116 loc) · 4.55 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
cmake_minimum_required(VERSION 3.12)
set(LIBHAT_VERSION_MAJOR 0)
set(LIBHAT_VERSION_MINOR 4)
set(LIBHAT_VERSION_PATCH 0)
set(LIBHAT_VERSION ${LIBHAT_VERSION_MAJOR}.${LIBHAT_VERSION_MINOR}.${LIBHAT_VERSION_PATCH})
project(libhat
VERSION ${LIBHAT_VERSION}
DESCRIPTION "A high-performance, modern, C++20 library designed around game hacking"
HOMEPAGE_URL "https://github.com/BasedInc/libhat"
LANGUAGES C CXX
)
include(CheckCXXCompilerFlag)
option(LIBHAT_STATIC_C_LIB "Build a static version of the C library" OFF)
option(LIBHAT_SHARED_C_LIB "Build a shared version of the C library" OFF)
option(LIBHAT_INSTALL_TARGET "Creates install rules for the libhat target" ON)
option(LIBHAT_DISABLE_SSE "Disables SSE scanning" OFF)
option(LIBHAT_DISABLE_AVX512 "Disables AVX512 scanning" OFF)
option(LIBHAT_TESTING "Enable tests" OFF)
option(LIBHAT_TESTING_ASAN "Enable address sanitizer when testing" ON)
option(LIBHAT_TESTING_SDE "Run tests using Intel Software Development Emulator" ON)
option(LIBHAT_HINT_X86_64 "Enables support for the x86_64 scan hint, requires a small (less than 1KB) data table" ON)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Just assume that the compiler accepts the required x86/x64 options if it'll accept -mmmx
# CMake architecture detection SUCKS!!!
check_cxx_compiler_flag("-mmmx" LIBHAT_COMPILER_X86_OPTIONS)
if(LIBHAT_COMPILER_X86_OPTIONS)
set_source_files_properties(src/arch/x86/SSE.cpp PROPERTIES COMPILE_FLAGS "-msse4.1")
set_source_files_properties(src/arch/x86/AVX2.cpp PROPERTIES COMPILE_FLAGS "-mavx -mavx2 -mbmi")
set_source_files_properties(src/arch/x86/AVX512.cpp PROPERTIES COMPILE_FLAGS "-mavx512f -mavx512bw -mbmi")
set_source_files_properties(src/arch/x86/System.cpp PROPERTIES COMPILE_FLAGS "-mxsave")
endif()
endif()
if(LIBHAT_TESTING AND LIBHAT_TESTING_ASAN)
if(MSVC AND NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options($<$<CONFIG:Debug>:/fsanitize=address>)
endif()
# TODO: Linux
endif()
set(LIBHAT_SRC
src/Scanner.cpp
src/System.cpp
src/os/linux/MemoryProtector.cpp
src/os/unix/Process.cpp
src/os/unix/System.cpp
src/os/win32/MemoryProtector.cpp
src/os/win32/Process.cpp
src/os/win32/Scanner.cpp
src/os/win32/System.cpp
src/arch/x86/SSE.cpp
src/arch/x86/AVX2.cpp
src/arch/x86/AVX512.cpp
src/arch/x86/System.cpp
src/arch/arm/System.cpp)
add_library(libhat STATIC ${LIBHAT_SRC})
add_library(libhat::libhat ALIAS libhat)
if(UNIX)
set_target_properties(libhat PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
target_compile_features(libhat PUBLIC cxx_std_20)
if (MSVC)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(libhat PRIVATE /clang:-Wall /clang:-Wextra /clang:-Wconversion /clang:-Werror)
else()
target_compile_options(libhat PRIVATE /W3 /WX)
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(libhat PRIVATE -Wall -Wextra -Wconversion -Werror
# temp fix for Mac OSX CI failing due to incorrect LIBHAT_COMPILER_X86_OPTIONS value
-Wno-unused-command-line-argument
)
endif()
target_include_directories(libhat PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:include>
)
target_compile_definitions(libhat PUBLIC
"$<$<BOOL:${LIBHAT_DISABLE_SSE}>:LIBHAT_DISABLE_SSE>"
"$<$<BOOL:${LIBHAT_DISABLE_AVX512}>:LIBHAT_DISABLE_AVX512>"
"$<$<BOOL:${LIBHAT_HINT_X86_64}>:LIBHAT_HINT_X86_64>"
)
if(LIBHAT_STATIC_C_LIB OR LIBHAT_SHARED_C_LIB)
set(LIBHAT_C_SOURCES
src/c/libhat.cpp
)
if(LIBHAT_STATIC_C_LIB)
add_library(libhat_c STATIC ${LIBHAT_C_SOURCES})
if(UNIX)
set_target_properties(libhat_c PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
else()
add_library(libhat_c SHARED ${LIBHAT_C_SOURCES})
target_compile_definitions(libhat_c
PRIVATE LIBHAT_BUILD_SHARED_LIB
INTERFACE LIBHAT_USE_SHARED_LIB
)
endif()
add_library(libhat::libhat_c ALIAS libhat_c)
target_link_libraries(libhat_c PRIVATE libhat)
target_include_directories(libhat_c PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>
$<INSTALL_INTERFACE:include>
)
endif()
if(LIBHAT_TESTING)
include(CTest)
enable_testing()
add_subdirectory(test)
endif()
if(LIBHAT_INSTALL_TARGET)
install(TARGETS libhat
EXPORT libhat-targets
RUNTIME DESTINATION "bin"
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
)
endif()