|
| 1 | +# Part of the EDG Compiler Project, under the Apache License v2.0 with LLVM |
| 2 | +# Exceptions. |
| 3 | +# See https://edgcpp.org/LICENSE.txt for license information. |
| 4 | +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 | + |
| 6 | +# Defaults derived from the host platform and compiler, so that a configure |
| 7 | +# which doesn't use a preset (e.g., an IDE's default CMake profile) makes the |
| 8 | +# same selections as the matching preset in CMakePresets.json. |
| 9 | + |
| 10 | +function(detect_host_defaults) |
| 11 | + # This function sets up the variables: |
| 12 | + # - EDG_HOST_MACRO_CONF: the debug macro configuration for this host and |
| 13 | + # compiler (the release configuration, if any, adds a "-release" |
| 14 | + # suffix), or "" if none is known. |
| 15 | + # - EDG_HOST_BASE: the default EDG_BASE directory, or "" if none is known. |
| 16 | + # - EDG_HOST_CPP_RT_LIBS: the default EDG_CPP_RT_LIBS list. |
| 17 | + set(macro_conf "") |
| 18 | + set(base "") |
| 19 | + set(cpp_rt_libs "") |
| 20 | + string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" processor) |
| 21 | + |
| 22 | + if(APPLE) |
| 23 | + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 24 | + if(processor MATCHES "^(arm64|aarch64)$") |
| 25 | + set(macro_conf "macos-arm-clang") |
| 26 | + set(base "cmake-native/macos-arm/clang") |
| 27 | + set(cpp_rt_libs "macos_arm64") |
| 28 | + elseif(processor STREQUAL "x86_64") |
| 29 | + set(macro_conf "macos-x86-clang") |
| 30 | + set(base "cmake-native/macos-x86_64/clang") |
| 31 | + set(cpp_rt_libs "macos_x86_64") |
| 32 | + endif() |
| 33 | + endif() |
| 34 | + elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") |
| 35 | + # The Linux configurations all target an x86_64 (or, for 32-bit builds, |
| 36 | + # i686) host. |
| 37 | + if(processor MATCHES "^(x86_64|amd64)$") |
| 38 | + if($CACHE{32BIT_BUILD}) |
| 39 | + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 40 | + set(macro_conf "linux-i686-gcc") |
| 41 | + set(base "docker/dev-env/gcc-i686") |
| 42 | + set(cpp_rt_libs "linux_i686 win32") |
| 43 | + endif() |
| 44 | + else() |
| 45 | + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 46 | + set(macro_conf "linux-gcc") |
| 47 | + set(base "docker/dev-env/gcc") |
| 48 | + elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") |
| 49 | + set(macro_conf "linux-clang") |
| 50 | + set(base "docker/dev-env/clang") |
| 51 | + endif() |
| 52 | + if(NOT macro_conf STREQUAL "") |
| 53 | + string(CONCAT cpp_rt_libs |
| 54 | + "linux_riscv64 linux_riscv32 linux_aarch64 linux_armv7 " |
| 55 | + "linux_i686 linux_x86_64 win32 win64") |
| 56 | + endif() |
| 57 | + endif() |
| 58 | + endif() |
| 59 | + elseif(WIN32 AND MSVC) |
| 60 | + if(processor MATCHES "^(x86_64|amd64)$") |
| 61 | + set(macro_conf "windows-msvc") |
| 62 | + endif() |
| 63 | + endif() |
| 64 | + |
| 65 | + if(NOT base STREQUAL "") |
| 66 | + set(base "${CMAKE_SOURCE_DIR}/bases/${base}") |
| 67 | + endif() |
| 68 | + |
| 69 | + # Export shared state. |
| 70 | + set(EDG_HOST_MACRO_CONF "${macro_conf}" PARENT_SCOPE) |
| 71 | + set(EDG_HOST_BASE "${base}" PARENT_SCOPE) |
| 72 | + set(EDG_HOST_CPP_RT_LIBS "${cpp_rt_libs}" PARENT_SCOPE) |
| 73 | +endfunction() |
| 74 | + |
| 75 | +function(host_macro_configuration result_var build_type) |
| 76 | + # Set result_var to the host's macro configuration for build_type, or to "" |
| 77 | + # if there isn't one. |
| 78 | + set(result "") |
| 79 | + if(NOT EDG_HOST_MACRO_CONF STREQUAL "") |
| 80 | + set(result "${EDG_HOST_MACRO_CONF}") |
| 81 | + string(TOUPPER "${build_type}" build_type) |
| 82 | + if(build_type MATCHES "^(RELEASE|RELWITHDEBINFO|MINSIZEREL)$") |
| 83 | + string(APPEND result "-release") |
| 84 | + endif() |
| 85 | + if(NOT IS_DIRECTORY "${CMAKE_SOURCE_DIR}/cmake/macro-conf/${result}") |
| 86 | + set(result "") |
| 87 | + endif() |
| 88 | + endif() |
| 89 | + set(${result_var} "${result}" PARENT_SCOPE) |
| 90 | +endfunction() |
0 commit comments