Anton Komlev | 6be1603 | 2021-10-13 21:51:23 +0100 | [diff] [blame^] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2017-2019, Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | |
| 9 | #Print a message and exit with failure |
| 10 | # |
| 11 | #Examples: |
| 12 | # failure("Something is wrong!") |
| 13 | |
| 14 | function(failure) |
| 15 | message(FATAL_ERROR "${ARGN}") |
| 16 | endfunction() |
| 17 | |
| 18 | #Convert \ directory separators to / on windows systems |
| 19 | # |
| 20 | #Convert the directory separators to forward slash on windows. Avoid |
| 21 | #conversion if path contains any forward slashes to avoid mixing up cygwin or |
| 22 | #mingw paths where an extra caharacter is escaped (i.e. "/c/Program\ Files/") |
| 23 | # |
| 24 | #Examples: |
| 25 | # set(MY_PATH "C:\foo\bar") |
| 26 | # win_fix_dir_sep(PATH MY_PATH) |
| 27 | # |
| 28 | #INPUTS: |
| 29 | # PATH - (mandatory) - name of the string variable to operate on |
| 30 | # |
| 31 | #OUTPUTS |
| 32 | # PATH is modified as needed. |
| 33 | # |
| 34 | function(win_fix_dir_sep) |
| 35 | #Parse our arguments |
| 36 | set( _OPTIONS_ARGS ) #No option (on/off) arguments (e.g. IGNORE_CASE) |
| 37 | set( _ONE_VALUE_ARGS PATH ) #Single option arguments (e.g. PATH "./foo/bar") |
| 38 | set( _MULTI_VALUE_ARGS ) #List arguments (e.g. LANGUAGES C ASM CXX) |
| 39 | cmake_parse_arguments(_MY_PARAMS "${_OPTIONS_ARGS}" "${_ONE_VALUE_ARGS}" "${_MULTI_VALUE_ARGS}" ${ARGN} ) |
| 40 | |
| 41 | #Check mandatory parameters |
| 42 | if(NOT _MY_PARAMS_PATH) |
| 43 | failure("win_fix_dir_sep(): Missing mandatory parameter PATH!") |
| 44 | endif() |
| 45 | set(_PATH ${_MY_PARAMS_PATH}) |
| 46 | |
| 47 | #To avoid trouble on windows change directory separator. |
| 48 | if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") |
| 49 | #Do not convert directory separator if there are forward slashes |
| 50 | #present. This is to avoid mixing up escaped characters in cygwin |
| 51 | #or mingw paths (i.e. c:/Program\ Files/something) |
| 52 | string(FIND "${${_PATH}}" "/" _is_found) |
| 53 | if (_is_found LESS 0) |
| 54 | string(REPLACE "\\" "/" ${_PATH} "${${_PATH}}") |
| 55 | set(${_PATH} "${${_PATH}}" PARENT_SCOPE) |
| 56 | endif() |
| 57 | endif() |
| 58 | endfunction() |