|
| 1 | +# |
| 2 | +# This file is part of AtomVM. |
| 3 | +# |
| 4 | +# Copyright 2025 Paul Guyot <[email protected]> |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | +# SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later |
| 19 | +# |
| 20 | + |
| 21 | +cmake_minimum_required(VERSION 3.13) |
| 22 | + |
| 23 | +find_program(ERLC_EXECUTABLE erlc) |
| 24 | +find_program(ERL_EXECUTABLE erl) |
| 25 | + |
| 26 | +if (ERLC_EXECUTABLE AND ERL_EXECUTABLE) |
| 27 | + execute_process(COMMAND erl -eval "io:put_chars(erlang:system_info(otp_release))." -s init stop -noshell OUTPUT_VARIABLE Erlang_VERSION) |
| 28 | +endif() |
| 29 | + |
| 30 | +include(FindPackageHandleStandardArgs) |
| 31 | + |
| 32 | +if (CMAKE_VERSION VERSION_LESS 3.19) |
| 33 | + # Handle version range ourselves |
| 34 | + if (Erlang_FIND_VERSION AND ERL_EXECUTABLE) |
| 35 | + string(REPLACE "..." ";" Erlang_FIND_VERSION_LIST ${Erlang_FIND_VERSION}) |
| 36 | + list(LENGTH Erlang_FIND_VERSION_LIST Erlang_FIND_VERSION_LIST_LEN) |
| 37 | + if (Erlang_FIND_VERSION_LIST_LEN EQUAL 1) |
| 38 | + find_package_handle_standard_args(Erlang |
| 39 | + FOUND_VAR Erlang_FOUND |
| 40 | + REQUIRED_VARS ERLC_EXECUTABLE ERL_EXECUTABLE |
| 41 | + VERSION_VAR Erlang_VERSION |
| 42 | + ) |
| 43 | + elseif(${Erlang_FIND_VERSION_LIST_LEN} EQUAL 2) |
| 44 | + list(GET Erlang_FIND_VERSION_LIST 0 Erlang_FIND_VERSION_MIN) |
| 45 | + list(GET Erlang_FIND_VERSION_LIST 1 Erlang_FIND_VERSION_MAX) |
| 46 | + if (${Erlang_VERSION} LESS Erlang_FIND_VERSION_MIN) |
| 47 | + message(FATAL_ERROR "-- Found Erlang: ${ERL_EXECUTABLE} but OTP Release ${Erlang_VERSION} is less than required ${Erlang_FIND_VERSION_MIN}") |
| 48 | + endif() |
| 49 | + if (${Erlang_VERSION} GREATER Erlang_FIND_VERSION_MAX) |
| 50 | + message(FATAL_ERROR "-- Found Erlang: ${ERL_EXECUTABLE} but OTP Release ${Erlang_VERSION} is greater than supported ${Erlang_FIND_VERSION_MAX}") |
| 51 | + endif() |
| 52 | + find_package_handle_standard_args(Erlang |
| 53 | + FOUND_VAR Erlang_FOUND |
| 54 | + REQUIRED_VARS ERLC_EXECUTABLE ERL_EXECUTABLE |
| 55 | + ) |
| 56 | + else() |
| 57 | + message(FATAL_ERROR "-- Found Erlang: ${ERL_EXECUTABLE} but version range syntax is incorrect ${Erlang_FIND_VERSION}") |
| 58 | + endif() |
| 59 | + else() |
| 60 | + find_package_handle_standard_args(Erlang |
| 61 | + FOUND_VAR Erlang_FOUND |
| 62 | + REQUIRED_VARS ERLC_EXECUTABLE ERL_EXECUTABLE |
| 63 | + ) |
| 64 | + endif() |
| 65 | +else() |
| 66 | + find_package_handle_standard_args(Erlang |
| 67 | + FOUND_VAR Erlang_FOUND |
| 68 | + HANDLE_VERSION_RANGE |
| 69 | + REQUIRED_VARS ERLC_EXECUTABLE ERL_EXECUTABLE |
| 70 | + VERSION_VAR Erlang_VERSION |
| 71 | + ) |
| 72 | +endif() |
0 commit comments