fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Daniel Rainerformat: use 4-space indents in more filesc5e4fed02

master
3.0 KiB87 linesraw
1#[=======================================================================[.rst:
2Imported from Corrosion https://github.com/corrosion-rs/corrosion/
3
4Copyright (c) 2018 Andrew Gaspar
5
6Licensed under the MIT license
7
8However this is absolutely gutted and reduced to the bare minimum.
9#]=======================================================================]
10include(FindPackageHandleStandardArgs)
11
12cmake_minimum_required(VERSION 3.12)
13
14# List of user variables that will override any toolchain-provided setting
15set(_Rust_USER_VARS Rust_COMPILER Rust_CARGO Rust_CARGO_TARGET)
16foreach(_VAR ${_Rust_USER_VARS})
17    if (DEFINED "${_VAR}")
18        set(${_VAR}_CACHED "${${_VAR}}" CACHE INTERNAL "Internal cache of ${_VAR}")
19    else()
20        unset(${_VAR}_CACHED CACHE)
21    endif()
22endforeach()
23
24if (NOT DEFINED Rust_CARGO_CACHED)
25    find_program(Rust_CARGO_CACHED cargo PATHS "$ENV{HOME}/.cargo/bin")
26endif()
27
28if (NOT EXISTS "${Rust_CARGO_CACHED}")
29    message(FATAL_ERROR "The cargo executable ${Rust_CARGO_CACHED} was not found. "
30        "Consider setting `Rust_CARGO_CACHED` to the absolute path of `cargo`."
31    )
32endif()
33
34if (NOT DEFINED Rust_COMPILER_CACHED)
35    find_program(Rust_COMPILER_CACHED rustc PATHS "$ENV{HOME}/.cargo/bin")
36endif()
37
38
39if (NOT EXISTS "${Rust_COMPILER_CACHED}")
40    message(FATAL_ERROR "The rustc executable ${Rust_COMPILER} was not found. "
41        "Consider setting `Rust_COMPILER` to the absolute path of `rustc`."
42    )
43endif()
44
45# Figure out the target by just using the host target.
46# If you want to cross-compile, you'll have to set Rust_CARGO_TARGET
47if(NOT Rust_CARGO_TARGET_CACHED)
48    execute_process(
49        COMMAND "${Rust_COMPILER_CACHED}" --version --verbose
50        OUTPUT_VARIABLE _RUSTC_VERSION_RAW
51        RESULT_VARIABLE _RUSTC_VERSION_RESULT
52    )
53
54    if(NOT ( "${_RUSTC_VERSION_RESULT}" EQUAL "0" ))
55        message(FATAL_ERROR "Failed to get rustc version.\n"
56            "${Rust_COMPILER} --version failed with error: `${_RUSTC_VERSION_RESULT}`")
57    endif()
58
59    if (_RUSTC_VERSION_RAW MATCHES "host: ([a-zA-Z0-9_\\-]*)\n")
60        set(Rust_DEFAULT_HOST_TARGET "${CMAKE_MATCH_1}")
61    else()
62        message(FATAL_ERROR
63            "Failed to parse rustc host target. `rustc --version --verbose` evaluated to:\n${_RUSTC_VERSION_RAW}"
64        )
65    endif()
66
67    if(CMAKE_CROSSCOMPILING)
68        message(FATAL_ERROR "CMake is in cross-compiling mode."
69            "Manually set `Rust_CARGO_TARGET`."
70        )
71    endif()
72    set(Rust_CARGO_TARGET_CACHED "${Rust_DEFAULT_HOST_TARGET}" CACHE STRING "Target triple")
73endif()
74
75# Set the input variables as non-cache variables so that the variables are available after
76# `find_package`, even if the values were evaluated to defaults.
77foreach(_VAR ${_Rust_USER_VARS})
78    set(${_VAR} "${${_VAR}_CACHED}")
79    # Ensure cached variables have type INTERNAL
80    set(${_VAR}_CACHED "${${_VAR}_CACHED}" CACHE INTERNAL "Internal cache of ${_VAR}")
81endforeach()
82
83find_package_handle_standard_args(
84    Rust
85    REQUIRED_VARS Rust_COMPILER Rust_CARGO Rust_CARGO_TARGET
86)
87