• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2022 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# Common functions for add environment for compiling and cross-compiling.
14# Used by different toolchains.
15
16function(set_c_compiler c_compiler_id)
17    find_program(c_compiler ${c_compiler_id})
18    if(NOT c_compiler)
19        message(FATAL_ERROR "Unable to find C compiler ${c_compiler_id}")
20    endif()
21
22    set(CMAKE_C_COMPILER ${c_compiler} PARENT_SCOPE)
23endfunction()
24
25function(set_cxx_compiler cxx_compiler_id)
26    find_program(cxx_compiler ${cxx_compiler_id})
27    if(NOT cxx_compiler)
28        message(FATAL_ERROR "Unable to find C++ compiler ${cxx_compiler_id}")
29    endif()
30
31    set(CMAKE_CXX_COMPILER ${cxx_compiler} PARENT_SCOPE)
32endfunction()
33
34function(set_cross_amd64_x86)
35    if(NOT CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64")
36        message(FATAL_ERROR "Unsupported host processor ${CMAKE_HOST_SYSTEM_PROCESSOR}")
37    endif()
38
39    # Caveats about the code below:
40    # * The "if" is needed because the toolchain file is parsed twice.
41    # * add_compile_options is not used intentionally as it does not
42    #   propagate the options to the linker, which is needed.
43    #   TODO: Use add_compile_options + add_link_options for CMake 3.13+.
44    if (NOT PANDA_CROSS_AMD64_X86)
45        set(PANDA_CROSS_AMD64_X86 1 CACHE STRING "" FORCE)
46        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32" CACHE STRING "" FORCE)
47        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32" CACHE STRING "" FORCE)
48        set(CMAKE_ASM_FLAGS "${CMAKE_ASM_FLAGS} -m32" CACHE STRING "" FORCE)
49    endif()
50endfunction()
51
52if (NOT DEFINED QEMU_PREFIX)
53    set(QEMU_PREFIX "")
54endif()
55if (NOT "${QEMU_PREFIX}" STREQUAL "")
56    set(QEMU_PREFIX "${QEMU_PREFIX}/")
57endif()
58set(QEMU_ARM64_BIN "${QEMU_PREFIX}qemu-aarch64")
59set(QEMU_ARM32_BIN "${QEMU_PREFIX}qemu-arm")
60
61