-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathfunctions.cmake
More file actions
94 lines (86 loc) · 3.33 KB
/
functions.cmake
File metadata and controls
94 lines (86 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# wolfboot/cmake/functions.cmake
#
# Copyright (C) 2025 wolfSSL Inc.
#
# This file is part of wolfBoot.
#
# wolfBoot is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# wolfBoot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
# Ensure this file is only included and initialized once
if(CMAKE_VERSION VERSION_LESS 3.10)
# Fallback path for older CMake, and anything else that wants to detect is loaded
if(DEFINED FUNCTIONS_CMAKE_INCLUDED)
return()
endif()
set(FUNCTIONS_CMAKE_INCLUDED TRUE)
else()
include_guard(GLOBAL)
endif()
function(override_cache VAR VAL)
get_property(VAR_STRINGS CACHE ${VAR} PROPERTY STRINGS)
LIST(FIND VAR_STRINGS ${VAL} CK)
if(-1 EQUAL ${CK})
message(SEND_ERROR
"\"${VAL}\" is not valid override value for \"${VAR}\"."
" Please select value from \"${VAR_STRINGS}\"\n")
endif()
set_property(CACHE ${VAR} PROPERTY VALUE ${VAL})
endfunction()
function(add_option NAME HELP_STRING DEFAULT VALUES)
# Set the default value for the option.
set(${NAME} ${DEFAULT} CACHE STRING ${HELP_STRING})
# Set the list of allowed values for the option.
set_property(CACHE ${NAME} PROPERTY STRINGS ${VALUES})
if(DEFINED ${NAME})
list(FIND VALUES ${${NAME}} IDX)
#
# If the given value isn't in the list of allowed values for the option,
# reduce it to yes/no according to CMake's "if" logic:
# https://cmake.org/cmake/help/latest/command/if.html#basic-expressions
#
# This has no functional impact; it just makes the settings in
# CMakeCache.txt and cmake-gui easier to read.
#
if (${IDX} EQUAL -1)
if(${${NAME}})
override_cache(${NAME} "yes")
else()
override_cache(${NAME} "no")
endif()
endif()
endif()
endfunction()
function(print_env VAR)
if(DEFINED ENV{${VAR}} AND NOT "$ENV{${VAR}}" STREQUAL "")
message(STATUS "${VAR} = $ENV{${VAR}}")
else()
message(STATUS "${VAR} = (not set)")
endif()
endfunction()
# Sets <var_name> to <value_expr>.
# If <value_expr> points to an existing directory, prints a STATUS message.
function(set_and_echo_dir var_name value_expr)
set(_val "${value_expr}")
# Export to caller's scope
set(${var_name} "${_val}" PARENT_SCOPE)
if(IS_DIRECTORY "${_val}")
message(STATUS "-- set ${var_name}; Found directory: ${_val}")
else()
message(STATUS "-- Warning: set ${var_name}")
message(STATUS "-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
message(STATUS "-- Directory not found: ${_val}")
message(STATUS "-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
endif()
endfunction()
set(FUNCTIONS_CMAKE_INCLUDED true)