-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathcommon.cmake
131 lines (109 loc) · 4.27 KB
/
common.cmake
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
include_guard(DIRECTORY)
# Specify the addressing mode for the addons
set(EA64 ON CACHE BOOL "64-bits addressing")
# Specify the default MAXSTR string buffer size (obsolete)
set(MAXSTR 1024 CACHE STRING "MAXSTR value")
# Set and verify the SDK folder
if (DEFINED IDASDK)
set(IDASDK ${IDASDK} CACHE STRING "IDASDK location (via -D switch)")
elseif (DEFINED ENV{IDASDK})
set(IDASDK $ENV{IDASDK} CACHE STRING "IDASDK (environment variable)")
else()
message(FATAL_ERROR "IDA SDK folder not specified via the -D switch or the environment variable 'IDASDK'")
endif()
file(TO_NATIVE_PATH "${IDASDK}/include/pro.h" IDASDK_PRO_H)
if (NOT EXISTS "${IDASDK_PRO_H}")
message(FATAL_ERROR "IDA SDK folder '${IDASDK}' seems invalid")
endif()
# Set and verify the IDA installation folder
if (DEFINED IDABIN)
set(IDABIN ${IDABIN} CACHE STRING "IDA installation location")
message("-- Setting IDABIN folder to: ${IDABIN}")
elseif (DEFINED ENV{IDABIN})
set(IDABIN $ENV{IDABIN} CACHE STRING "IDA installation location (environment variable)")
else()
# Default IDA binary folder is in the SDK's bin folder
set(IDABIN ${IDASDK}/bin)
file(TO_NATIVE_PATH ${IDABIN} IDABIN)
message("-- Setting default IDABIN folder to: ${IDABIN}")
endif()
# Parse the SDK version
file(READ "${IDASDK_PRO_H}" IDASDK_PRO_H_CONTENT)
string(REGEX MATCH "IDA_SDK_VERSION *([0-9]+)" IDASDK_VERSION "${IDASDK_PRO_H_CONTENT}")
set(IDASDK_VERSION ${CMAKE_MATCH_1})
if ("${IDASDK_VERSION}" STREQUAL "")
set(IDASDK_VERSION "unknown")
endif()
message("-- Detected IDA SDK version: ${IDASDK_VERSION}")
# Set libraries path
if (WIN32 AND MSVC)
set(__NT__ 1)
set(IDAPROPLAT "__NT__")
set(IDALIBSUFFIX "lib")
set(IDALIBPATH32 "${IDASDK}/lib/x64_win_vc_32")
set(IDALIBPATH64 "${IDASDK}/lib/x64_win_vc_64")
# Static libraries
set(IDASLIBPATH32 "${IDASDK}/lib/x86_win_vc_32_s")
set(IDASLIBPATH64 "${IDASDK}/lib/x64_win_vc_64_s")
set(IDALIB32 ${IDALIBPATH32}/ida.lib)
set(IDALIB64 ${IDALIBPATH64}/ida.lib)
set(IDALIBLIB64 ${IDALIBPATH64}/idalib.lib)
set(IDAEXE ida.exe)
elseif(APPLE)
set(__MAC__ 1)
set(IDAPROPLAT "__MAC__")
set(IDALIBSUFFIX "dylib")
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
set(IDALIBPATH32 "${IDASDK}/lib/arm64_mac_clang_32")
set(IDALIBPATH64 "${IDASDK}/lib/arm64_mac_clang_64")
else()
set(IDALIBPATH32 "${IDASDK}/lib/x64_mac_clang_32")
set(IDALIBPATH64 "${IDASDK}/lib/x64_mac_clang_64")
endif()
set(IDALIB32 ${IDALIBPATH32}/libida.dylib)
set(IDALIB64 ${IDALIBPATH64}/libida.dylib)
set(IDALIBLIB64 ${IDALIBPATH64}/libidalib.dylib)
elseif(UNIX AND NOT APPLE)
set(__LINUX__ 1)
set(IDAPROPLAT "__LINUX__")
set(IDALIBSUFFIX "so")
set(IDALIBPATH32 "${IDASDK}/lib/x64_linux_gcc_32")
set(IDALIBPATH64 "${IDASDK}/lib/x64_linux_gcc_64")
set(IDASLIBPATH64 "${IDALIBPATH64}")
set(IDALIB32 ${IDALIBPATH32}/libida.so)
set(IDALIB64 ${IDALIBPATH64}/libida.so)
set(IDALIBLIB64 ${IDALIBPATH64}/libidalib.so)
else()
message(FATAL_ERROR "Unknown platform!")
endif()
if (${EA64})
set(IDAEA64 "__EA64__=1")
set(IDALIBPATH "${IDALIBPATH64}")
set(IDASLIBPATH "${IDASLIBPATH64}")
set(IDALIB "${IDALIB64}")
set(IDALIBLIB "${IDALIBLIB64}")
else()
set(IDALIBPATH "${IDALIBPATH32}")
set(IDASLIBPATH "${IDASLIBPATH32}")
set(IDALIB "${IDALIB32}")
set(IDAEA64 "")
endif()
set(IDAPROLIB "${IDASLIBPATH}/pro.${IDALIBSUFFIX}")
set(IDAPROINCLUDE "${IDASDK}/include")
# Convenience macro to include the addons script and create the proper targets
# The addons script can be included many times, each time it generates a new target
macro(generate)
if (DEFINED IDASDK)
include(${IDASDK}/ida-cmake/addons.cmake)
elseif (DEFINED ENV{IDASDK})
include($ENV{IDASDK}/ida-cmake/addons.cmake)
else()
message(FATAL_ERROR "IDA SDK folder not specified via the -D switch or the environment variable 'IDASDK'")
endif()
endmacro()
# For MSVC, disable some common IDA compilation warnings
function(disable_ida_warnings target)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
target_compile_options(${target} PRIVATE "/wd4267" "/wd4244" "/wd4018" "/wd4146")
endif()
endfunction()