1# Copyright (c) 2021 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14if(CMAKE_SYSTEM_NAME STREQUAL Linux) 15 set(PANDA_TARGET_LINUX 1) 16 set(PANDA_TARGET_UNIX 1) 17if (NOT PANDA_ENABLE_ADDRESS_SANITIZER) 18 set(PANDA_USE_FUTEX 1) 19endif() 20 add_definitions(-DPANDA_TARGET_LINUX) 21 add_definitions(-DPANDA_TARGET_UNIX) 22if (NOT PANDA_ENABLE_ADDRESS_SANITIZER) 23 add_definitions(-DPANDA_USE_FUTEX) 24endif() 25elseif(CMAKE_SYSTEM_NAME STREQUAL OHOS) 26 set(PANDA_TARGET_OHOS 1) 27 set(PANDA_TARGET_UNIX 1) 28 add_definitions(-DPANDA_TARGET_OHOS) 29 add_definitions(-DPANDA_TARGET_UNIX) 30elseif(CMAKE_SYSTEM_NAME STREQUAL Windows) 31 set(PANDA_TARGET_WINDOWS 1) 32 add_definitions(-DPANDA_TARGET_WINDOWS) 33elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin) 34 set(PANDA_TARGET_MACOS 1) 35 set(PANDA_TARGET_UNIX 1) 36 add_definitions(-DPANDA_TARGET_MACOS) 37 add_definitions(-DPANDA_TARGET_UNIX) 38else() 39 message(FATAL_ERROR "Platform ${CMAKE_SYSTEM_NAME} is not supported") 40endif() 41 42if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") 43 if(NOT PANDA_CROSS_AMD64_X86) 44 set(PANDA_TARGET_AMD64 1) 45 add_definitions(-DPANDA_TARGET_AMD64) 46 else() 47 set(PANDA_TARGET_X86 1) 48 add_definitions(-DPANDA_TARGET_X86) 49 endif() 50elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i[356]86") 51 set(PANDA_TARGET_X86 1) 52 add_definitions(-DPANDA_TARGET_X86) 53elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64") 54 set(PANDA_TARGET_ARM64 1) 55 add_definitions(-DPANDA_TARGET_ARM64) 56elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm") 57 set(PANDA_TARGET_ARM32 1) 58 add_definitions(-DPANDA_TARGET_ARM32) 59 if(PANDA_TARGET_ARM32_ABI_SOFT) 60 add_definitions(-DPANDA_TARGET_ARM32_ABI_SOFT) 61 elseif(PANDA_TARGET_ARM32_ABI_HARD) 62 add_definitions(-DPANDA_TARGET_ARM32_ABI_HARD) 63 else() 64 message(FATAL_ERROR "PANDA_TARGET_ARM32_ABI_* is not set") 65 endif() 66else() 67 message(FATAL_ERROR "Processor ${CMAKE_SYSTEM_PROCESSOR} is not supported") 68endif() 69 70if(PANDA_TARGET_AMD64 OR PANDA_TARGET_ARM64) 71 set(PANDA_TARGET_64 1) 72 add_definitions(-DPANDA_TARGET_64) 73elseif(PANDA_TARGET_X86 OR PANDA_TARGET_ARM32) 74 set(PANDA_TARGET_32 1) 75 add_definitions(-DPANDA_TARGET_32) 76else() 77 message(FATAL_ERROR "Unknown bitness of the target platform") 78endif() 79 80if (PANDA_TRACK_INTERNAL_ALLOCATIONS) 81 message(STATUS "Track internal allocations") 82 add_definitions(-DTRACK_INTERNAL_ALLOCATIONS=${PANDA_TRACK_INTERNAL_ALLOCATIONS}) 83endif() 84 85# Enable global register variables usage only for clang >= 9.0.0 and gcc >= 8.0.0. 86# Clang 8.0.0 doesn't support all necessary options -ffixed-<reg>. Gcc 7.5.0 freezes 87# when compiling release interpreter. 88# 89# Also calling conventions of funtions that use global register variables are different: 90# clang stores and restores registers that are used for global variables in the prolog 91# and epilog of such functions and gcc doesn't do it. So it's necessary to inline all 92# function that refers to global register variables to interpreter loop. 93 94# For this reason we disable global register variables usage for clang debug builds as 95# ALWAYS_INLINE macro expands to nothing in this mode and we cannot garantee that all 96# necessary function will be inlined. 97# 98if(PANDA_TARGET_ARM64 AND ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang" 99 AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0.0 100 AND CMAKE_BUILD_TYPE MATCHES Release) 101 OR 102 (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" 103 AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0.0))) 104 set(PANDA_ENABLE_GLOBAL_REGISTER_VARIABLES 1) 105 add_definitions(-DPANDA_ENABLE_GLOBAL_REGISTER_VARIABLES) 106endif() 107 108if(CMAKE_BUILD_TYPE MATCHES Debug) 109 # Additional debug information about fp in each frame 110 add_compile_options(-fno-omit-frame-pointer) 111endif() 112 113if (PANDA_PGO_INSTRUMENT OR PANDA_PGO_OPTIMIZE) 114 if (NOT PANDA_TARGET_MOBILE OR NOT PANDA_TARGET_ARM64) 115 message(FATAL_ERROR "PGO supported is not supported on this target") 116 endif() 117 118 set(PANDA_ENABLE_LTO true) 119endif() 120 121if(PANDA_TARGET_64) 122 set(PANDA_USE_32_BIT_POINTER 1) 123 add_definitions(-DPANDA_USE_32_BIT_POINTER) 124endif() 125 126if(PANDA_TARGET_LINUX) 127 execute_process(COMMAND grep PRETTY_NAME= /etc/os-release 128 OUTPUT_VARIABLE PANDA_TARGET_LINUX_DISTRO 129 OUTPUT_STRIP_TRAILING_WHITESPACE 130 ) 131 if(PANDA_TARGET_LINUX_DISTRO MATCHES "Ubuntu") 132 set(PANDA_TARGET_LINUX_UBUNTU 1) 133 add_definitions(-DPANDA_TARGET_LINUX_UBUNTU) 134 endif() 135 136 if(PANDA_TARGET_LINUX_DISTRO MATCHES "Ubuntu 18\\.04") 137 set(PANDA_TARGET_LINUX_UBUNTU_18_04 1) 138 add_definitions(-DPANDA_TARGET_LINUX_UBUNTU_18_04) 139 elseif(PANDA_TARGET_LINUX_DISTRO MATCHES "Ubuntu 20\\.04") 140 set(PANDA_TARGET_LINUX_UBUNTU_20_04 1) 141 add_definitions(-DPANDA_TARGET_LINUX_UBUNTU_20_04) 142 endif() 143endif() 144 145set(PANDA_WITH_RUNTIME true) 146set(PANDA_WITH_TOOLCHAIN true) 147set(PANDA_WITH_TESTS true) 148set(PANDA_WITH_BENCHMARKS true) 149set(PANDA_DEFAULT_LIB_TYPE "SHARED") 150set(DONT_USE_RAPIDCHECK true) 151 152option(PANDA_ARK_JS_VM "Build with C intepreter in ecmascript folder" OFF) 153 154if(PANDA_TARGET_WINDOWS) 155 set(PANDA_WITH_BENCHMARKS false) 156 set(PANDA_DEFAULT_LIB_TYPE "STATIC") 157endif() 158 159if(PANDA_TARGET_MACOS) 160 set(PANDA_DEFAULT_LIB_TYPE "STATIC") 161 #introduced for "std::filesystem::create_directories" 162 add_compile_options(-mmacosx-version-min=10.15) 163endif() 164 165if(PANDA_TARGET_OHOS) 166 set(PANDA_WITH_BENCHMARKS false) 167endif() 168 169if(CMAKE_BUILD_TYPE STREQUAL FastVerify) 170 add_definitions(-DFAST_VERIFY) 171endif() 172 173# The definition is set for the build which will be delivered to customers. 174# Currently this build doesn't contain dependencies to debug libraries 175# (like libdwarf.so) 176if (NOT DEFINED PANDA_PRODUCT_BUILD) 177 set(PANDA_PRODUCT_BUILD false) 178endif() 179 180if (PANDA_PRODUCT_BUILD) 181 add_definitions(-DPANDA_PRODUCT_BUILD) 182endif() 183 184message(STATUS "PANDA_TARGET_UNIX = ${PANDA_TARGET_UNIX}") 185message(STATUS "PANDA_TARGET_LINUX = ${PANDA_TARGET_LINUX}") 186message(STATUS "PANDA_TARGET_MOBILE = ${PANDA_TARGET_MOBILE}") 187message(STATUS "PANDA_USE_FUTEX = ${PANDA_USE_FUTEX}") 188message(STATUS "PANDA_TARGET_WINDOWS = ${PANDA_TARGET_WINDOWS}") 189message(STATUS "PANDA_TARGET_OHOS = ${PANDA_TARGET_OHOS}") 190message(STATUS "PANDA_TARGET_MACOS = ${PANDA_TARGET_MACOS}") 191message(STATUS "PANDA_CROSS_AMD64_X86 = ${PANDA_CROSS_AMD64_X86}") 192message(STATUS "PANDA_TARGET_AMD64 = ${PANDA_TARGET_AMD64}") 193message(STATUS "PANDA_TARGET_X86 = ${PANDA_TARGET_X86}") 194message(STATUS "PANDA_TARGET_ARM64 = ${PANDA_TARGET_ARM64}") 195message(STATUS "PANDA_TARGET_ARM32 = ${PANDA_TARGET_ARM32}") 196if(PANDA_TARGET_ARM32) 197message(STATUS "PANDA_TARGET_ARM32_ABI_SOFT = ${PANDA_TARGET_ARM32_ABI_SOFT}") 198message(STATUS "PANDA_TARGET_ARM32_ABI_HARD = ${PANDA_TARGET_ARM32_ABI_HARD}") 199endif() 200message(STATUS "PANDA_TARGET_64 = ${PANDA_TARGET_64}") 201message(STATUS "PANDA_TARGET_32 = ${PANDA_TARGET_32}") 202message(STATUS "PANDA_ENABLE_GLOBAL_REGISTER_VARIABLES = ${PANDA_ENABLE_GLOBAL_REGISTER_VARIABLES}") 203message(STATUS "PANDA_ENABLE_LTO = ${PANDA_ENABLE_LTO}") 204if(PANDA_TARGET_MOBILE) 205message(STATUS "PANDA_LLVM_REGALLOC = ${PANDA_LLVM_REGALLOC}") 206endif() 207message(STATUS "PANDA_WITH_RUNTIME = ${PANDA_WITH_RUNTIME}") 208message(STATUS "PANDA_WITH_COMPILER = ${PANDA_WITH_COMPILER}") 209message(STATUS "PANDA_WITH_TOOLCHAIN = ${PANDA_WITH_TOOLCHAIN}") 210message(STATUS "PANDA_WITH_TESTS = ${PANDA_WITH_TESTS}") 211message(STATUS "PANDA_WITH_BENCHMARKS = ${PANDA_WITH_BENCHMARKS}") 212message(STATUS "PANDA_PGO_INSTRUMENT = ${PANDA_PGO_INSTRUMENT}") 213message(STATUS "PANDA_PGO_OPTIMIZE = ${PANDA_PGO_OPTIMIZE}") 214message(STATUS "PANDA_PRODUCT_BUILD = ${PANDA_PRODUCT_BUILD}") 215