Move Protocol's derived classes commons in Protocol
[sdk/tools/netcoredbg.git] / clrdefinitions.cmake
1 function(clr_unknown_arch)
2   if (WIN32)
3     message(FATAL_ERROR "Only AMD64, ARM64, ARM and I386 are supported")
4   elseif(CLR_CROSS_COMPONENTS_BUILD)
5     message(FATAL_ERROR "Only AMD64, I386 host are supported for linux cross-architecture component")
6   else()
7     message(FATAL_ERROR "Only AMD64, ARM64 and ARM are supported")
8   endif()
9 endfunction()
10
11 #----------------------------------------
12 # Detect and set platform variable names
13 #     - for non-windows build platform & architecture is detected using inbuilt CMAKE variables and cross target component configure
14 #     - for windows we use the passed in parameter to CMAKE to determine build arch
15 #----------------------------------------
16 if(CMAKE_SYSTEM_NAME STREQUAL Linux)
17     set(CLR_CMAKE_PLATFORM_UNIX 1)
18     if(CLR_CROSS_COMPONENTS_BUILD)
19         # CMAKE_HOST_SYSTEM_PROCESSOR returns the value of `uname -p` on host.
20         if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL amd64)
21             if(CLR_CMAKE_TARGET_ARCH STREQUAL "arm")
22                 set(CLR_CMAKE_PLATFORM_UNIX_X86 1)
23             else()
24                 set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1)
25             endif()
26         elseif(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL i686)
27             set(CLR_CMAKE_PLATFORM_UNIX_X86 1)
28         else()
29             clr_unknown_arch()
30         endif()
31     else()
32         # CMAKE_SYSTEM_PROCESSOR returns the value of `uname -p` on target.
33         # For the AMD/Intel 64bit architecture two different strings are common.
34         # Linux and Darwin identify it as "x86_64" while FreeBSD and netbsd uses the
35         # "amd64" string. Accept either of the two here.
36         if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL amd64)
37             set(CLR_CMAKE_PLATFORM_UNIX_AMD64 1)
38         elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l)
39             set(CLR_CMAKE_PLATFORM_UNIX_ARM 1)
40         elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
41             set(CLR_CMAKE_PLATFORM_UNIX_ARM 1)
42         elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
43             set(CLR_CMAKE_PLATFORM_UNIX_ARM64 1)
44         elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686)
45             set(CLR_CMAKE_PLATFORM_UNIX_X86 1)
46         else()
47             clr_unknown_arch()
48         endif()
49     endif()
50     set(CLR_CMAKE_PLATFORM_LINUX 1)
51
52     # Detect Linux ID
53     if(DEFINED CLR_CMAKE_LINUX_ID)
54         if(CLR_CMAKE_LINUX_ID STREQUAL ubuntu)
55             set(CLR_CMAKE_TARGET_UBUNTU_LINUX 1)
56         elseif(CLR_CMAKE_LINUX_ID STREQUAL tizen)
57             set(CLR_CMAKE_TARGET_TIZEN_LINUX 1)
58         elseif(CLR_CMAKE_LINUX_ID STREQUAL alpine)
59             set(CLR_CMAKE_PLATFORM_ALPINE_LINUX 1)
60         endif()
61         if(CLR_CMAKE_LINUX_ID STREQUAL ubuntu)
62             set(CLR_CMAKE_PLATFORM_UBUNTU_LINUX 1)
63         endif()
64     endif(DEFINED CLR_CMAKE_LINUX_ID)
65 #else()
66 #    message(FATAL_ERROR "Currently only Linux is supported but you can try")
67 endif(CMAKE_SYSTEM_NAME STREQUAL Linux)
68
69 # Set HOST architecture variables
70 if(CLR_CMAKE_PLATFORM_UNIX_ARM)
71     set(CLR_CMAKE_PLATFORM_ARCH_ARM 1)
72     set(CLR_CMAKE_HOST_ARCH "arm")
73 elseif(CLR_CMAKE_PLATFORM_UNIX_ARM64)
74     set(CLR_CMAKE_PLATFORM_ARCH_ARM64 1)
75     set(CLR_CMAKE_HOST_ARCH "arm64")
76 elseif(CLR_CMAKE_PLATFORM_UNIX_AMD64)
77     set(CLR_CMAKE_PLATFORM_ARCH_AMD64 1)
78     set(CLR_CMAKE_HOST_ARCH "x64")
79 elseif(CLR_CMAKE_PLATFORM_UNIX_X86)
80     set(CLR_CMAKE_PLATFORM_ARCH_I386 1)
81     set(CLR_CMAKE_HOST_ARCH "x86")
82 elseif(WIN32)
83     # CLR_CMAKE_HOST_ARCH is passed in as param to cmake
84     if (CLR_CMAKE_HOST_ARCH STREQUAL x64)
85         set(CLR_CMAKE_PLATFORM_ARCH_AMD64 1)
86     elseif(CLR_CMAKE_HOST_ARCH STREQUAL x86)
87         set(CLR_CMAKE_PLATFORM_ARCH_I386 1)
88     elseif(CLR_CMAKE_HOST_ARCH STREQUAL arm)
89         set(CLR_CMAKE_PLATFORM_ARCH_ARM 1)
90     elseif(CLR_CMAKE_HOST_ARCH STREQUAL arm64)
91         set(CLR_CMAKE_PLATFORM_ARCH_ARM64 1)
92     else()
93         clr_unknown_arch()
94     endif()
95 endif()
96
97 # Set TARGET architecture variables
98 if(NOT DEFINED CLR_CMAKE_TARGET_ARCH OR CLR_CMAKE_TARGET_ARCH STREQUAL "" )
99   set(CLR_CMAKE_TARGET_ARCH ${CLR_CMAKE_HOST_ARCH})
100 endif()
101
102 # Set target architecture variables
103 if (CLR_CMAKE_TARGET_ARCH STREQUAL x64)
104     set(CLR_CMAKE_TARGET_ARCH_AMD64 1)
105   elseif(CLR_CMAKE_TARGET_ARCH STREQUAL x86)
106     set(CLR_CMAKE_TARGET_ARCH_I386 1)
107   elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm64)
108     set(CLR_CMAKE_TARGET_ARCH_ARM64 1)
109   elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm)
110     set(CLR_CMAKE_TARGET_ARCH_ARM 1)
111   else()
112     clr_unknown_arch()
113 endif()
114
115 # Definitions (for platform)
116 if (CLR_CMAKE_PLATFORM_ARCH_AMD64)
117   add_definitions(-D_AMD64_)
118   add_definitions(-D_WIN64)
119   add_definitions(-DAMD64)
120   add_definitions(-DBIT64=1)
121 elseif (CLR_CMAKE_PLATFORM_ARCH_I386)
122   add_definitions(-D_X86_)
123 elseif (CLR_CMAKE_PLATFORM_ARCH_ARM)
124   add_definitions(-D_ARM_)
125   add_definitions(-DARM)
126 elseif (CLR_CMAKE_PLATFORM_ARCH_ARM64)
127   add_definitions(-D_ARM64_)
128   add_definitions(-DARM64)
129   add_definitions(-D_WIN64)
130   add_definitions(-DBIT64=1)
131 else ()
132   clr_unknown_arch()
133 endif ()
134
135 # Definitions (for target)
136 if (CLR_CMAKE_TARGET_ARCH_AMD64)
137   if (CLR_CMAKE_PLATFORM_UNIX)
138     add_definitions(-DDBG_TARGET_AMD64_UNIX)
139   endif()
140   add_definitions(-D_TARGET_AMD64_=1)
141   add_definitions(-DDBG_TARGET_64BIT=1)
142   add_definitions(-DDBG_TARGET_AMD64=1)
143   add_definitions(-DDBG_TARGET_WIN64=1)
144 elseif (CLR_CMAKE_TARGET_ARCH_ARM64)
145   if (CLR_CMAKE_PLATFORM_UNIX)
146     add_definitions(-DDBG_TARGET_ARM64_UNIX)
147   endif()
148   add_definitions(-D_TARGET_ARM64_=1)
149   add_definitions(-DDBG_TARGET_64BIT=1)
150   add_definitions(-DDBG_TARGET_ARM64=1)
151   add_definitions(-DDBG_TARGET_WIN64=1)
152   add_definitions(-DFEATURE_MULTIREG_RETURN)
153 elseif (CLR_CMAKE_TARGET_ARCH_ARM)
154   if (CLR_CMAKE_PLATFORM_UNIX)
155     add_definitions(-DDBG_TARGET_ARM_UNIX)
156   elseif (WIN32 AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD)
157     # Set this to ensure we can use Arm SDK for Desktop binary linkage when doing native (Arm32) build
158     add_definitions(-D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1)
159     add_definitions(-D_ARM_WORKAROUND_)
160   endif (CLR_CMAKE_PLATFORM_UNIX)
161   add_definitions(-D_TARGET_ARM_=1)
162   add_definitions(-DDBG_TARGET_32BIT=1)
163   add_definitions(-DDBG_TARGET_ARM=1)
164 elseif (CLR_CMAKE_TARGET_ARCH_I386)
165   add_definitions(-D_TARGET_X86_=1)
166   add_definitions(-DDBG_TARGET_32BIT=1)
167   add_definitions(-DDBG_TARGET_X86=1)
168 else ()
169   clr_unknown_arch()
170 endif (CLR_CMAKE_TARGET_ARCH_AMD64)