2 #//===----------------------------------------------------------------------===//
4 #// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 #// See https://llvm.org/LICENSE.txt for license information.
6 #// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 #//===----------------------------------------------------------------------===//
11 # void libomp_say(string message_to_user);
12 # - prints out message_to_user
13 macro(libomp_say message_to_user)
14 message(STATUS "LIBOMP: ${message_to_user}")
17 # void libomp_warning_say(string message_to_user);
18 # - prints out message_to_user with a warning
19 macro(libomp_warning_say message_to_user)
20 message(WARNING "LIBOMP: ${message_to_user}")
23 # void libomp_error_say(string message_to_user);
24 # - prints out message_to_user with an error and exits cmake
25 macro(libomp_error_say message_to_user)
26 message(FATAL_ERROR "LIBOMP: ${message_to_user}")
29 # libomp_append(<flag> <flags_list> [(IF_TRUE | IF_FALSE | IF_TRUE_1_0 ) BOOLEAN])
31 # libomp_append(<flag> <flags_list>)
32 # - unconditionally appends <flag> to the list of definitions
34 # libomp_append(<flag> <flags_list> <BOOLEAN>)
35 # - appends <flag> to the list of definitions if BOOLEAN is true
37 # libomp_append(<flag> <flags_list> IF_TRUE <BOOLEAN>)
38 # - appends <flag> to the list of definitions if BOOLEAN is true
40 # libomp_append(<flag> <flags_list> IF_FALSE <BOOLEAN>)
41 # - appends <flag> to the list of definitions if BOOLEAN is false
43 # libomp_append(<flag> <flags_list> IF_DEFINED <VARIABLE>)
44 # - appends <flag> to the list of definitions if VARIABLE is defined
46 # libomp_append(<flag> <flags_list> IF_TRUE_1_0 <BOOLEAN>)
47 # - appends <flag>=1 to the list of definitions if <BOOLEAN> is true, <flag>=0 otherwise
48 # e.g., libomp_append("-D USE_FEATURE" IF_TRUE_1_0 HAVE_FEATURE)
49 # appends "-D USE_FEATURE=1" if HAVE_FEATURE is true
50 # or "-D USE_FEATURE=0" if HAVE_FEATURE is false
51 macro(libomp_append flags flag)
52 if(NOT (${ARGC} EQUAL 2 OR ${ARGC} EQUAL 3 OR ${ARGC} EQUAL 4))
53 libomp_error_say("libomp_append: takes 2, 3, or 4 arguments")
56 list(APPEND ${flags} "${flag}")
57 elseif(${ARGC} EQUAL 3)
59 list(APPEND ${flags} "${flag}")
62 if(${ARGV2} STREQUAL "IF_TRUE")
64 list(APPEND ${flags} "${flag}")
66 elseif(${ARGV2} STREQUAL "IF_FALSE")
68 list(APPEND ${flags} "${flag}")
70 elseif(${ARGV2} STREQUAL "IF_DEFINED")
72 list(APPEND ${flags} "${flag}")
74 elseif(${ARGV2} STREQUAL "IF_TRUE_1_0")
76 list(APPEND ${flags} "${flag}=1")
78 list(APPEND ${flags} "${flag}=0")
81 libomp_error_say("libomp_append: third argument must be one of IF_TRUE, IF_FALSE, IF_DEFINED, IF_TRUE_1_0")
86 # void libomp_get_legal_arch(string* return_arch_string);
87 # - returns (through return_arch_string) the formal architecture
88 # string or warns user of unknown architecture
89 function(libomp_get_legal_arch return_arch_string)
91 set(${return_arch_string} "IA-32" PARENT_SCOPE)
93 set(${return_arch_string} "Intel(R) 64" PARENT_SCOPE)
95 set(${return_arch_string} "Intel(R) Many Integrated Core Architecture" PARENT_SCOPE)
97 set(${return_arch_string} "ARM" PARENT_SCOPE)
99 set(${return_arch_string} "PPC64BE" PARENT_SCOPE)
101 set(${return_arch_string} "PPC64LE" PARENT_SCOPE)
103 set(${return_arch_string} "AARCH64" PARENT_SCOPE)
104 elseif(${AARCH64_32})
105 set(${return_arch_string} "AARCH64_32" PARENT_SCOPE)
106 elseif(${AARCH64_A64FX})
107 set(${return_arch_string} "AARCH64_A64FX" PARENT_SCOPE)
109 set(${return_arch_string} "MIPS" PARENT_SCOPE)
111 set(${return_arch_string} "MIPS64" PARENT_SCOPE)
113 set(${return_arch_string} "RISCV64" PARENT_SCOPE)
114 elseif(${LOONGARCH64})
115 set(${return_arch_string} "LOONGARCH64" PARENT_SCOPE)
117 set(${return_arch_string} "VE" PARENT_SCOPE)
119 set(${return_arch_string} "S390X" PARENT_SCOPE)
121 set(${return_arch_string} "${LIBOMP_ARCH}" PARENT_SCOPE)
122 libomp_warning_say("libomp_get_legal_arch(): Warning: Unknown architecture: Using ${LIBOMP_ARCH}")
126 # void libomp_check_variable(string var, ...);
127 # - runs through all values checking if ${var} == value
128 # - uppercase and lowercase do not matter
129 # - if the var is found, then just print it out
130 # - if the var is not found, then error out
131 function(libomp_check_variable var)
133 string(TOLOWER "${${var}}" var_lower)
134 foreach(value IN LISTS ARGN)
135 string(TOLOWER "${value}" value_lower)
136 if("${var_lower}" STREQUAL "${value_lower}")
138 set(the_value "${value}")
141 if(${valid_flag} EQUAL 0)
142 libomp_error_say("libomp_check_variable(): ${var} = ${${var}} is unknown")
146 # void libomp_get_build_number(string src_dir, string* return_build_number);
147 # - grab the eight digit build number (or 00000000) from kmp_version.cpp
148 function(libomp_get_build_number src_dir return_build_number)
149 # sets file_lines_list to a list of all lines in kmp_version.cpp
150 file(STRINGS "${src_dir}/src/kmp_version.cpp" file_lines_list)
152 # runs through each line in kmp_version.cpp
153 foreach(line IN LISTS file_lines_list)
154 # if the line begins with "#define KMP_VERSION_BUILD" then we take not of the build number
155 string(REGEX MATCH "^[ \t]*#define[ \t]+KMP_VERSION_BUILD" valid "${line}")
156 if(NOT "${valid}" STREQUAL "") # if we matched "#define KMP_VERSION_BUILD", then grab the build number
157 string(REGEX REPLACE "^[ \t]*#define[ \t]+KMP_VERSION_BUILD[ \t]+([0-9]+)" "\\1"
158 build_number "${line}"
162 set(${return_build_number} "${build_number}" PARENT_SCOPE) # return build number
165 # void libomp_get_legal_type(string* return_legal_type);
166 # - set the legal type name Performance/Profiling/Stub
167 function(libomp_get_legal_type return_legal_type)
168 if(${NORMAL_LIBRARY})
169 set(${return_legal_type} "Performance" PARENT_SCOPE)
170 elseif(${PROFILE_LIBRARY})
171 set(${return_legal_type} "Profiling" PARENT_SCOPE)
172 elseif(${STUBS_LIBRARY})
173 set(${return_legal_type} "Stub" PARENT_SCOPE)
177 # void libomp_add_suffix(string suffix, list<string>* list_of_items);
178 # - returns list_of_items with suffix appended to all items
179 # - original list is modified
180 function(libomp_add_suffix suffix list_of_items)
182 foreach(item IN LISTS "${list_of_items}")
183 if(NOT "${item}" STREQUAL "")
184 list(APPEND local_list "${item}${suffix}")
187 set(${list_of_items} "${local_list}" PARENT_SCOPE)
190 # void libomp_list_to_string(list<string> list_of_things, string* return_string);
191 # - converts a list to a space separated string
192 function(libomp_list_to_string list_of_things return_string)
193 string(REPLACE ";" " " output_variable "${list_of_things}")
194 set(${return_string} "${output_variable}" PARENT_SCOPE)
197 # void libomp_string_to_list(string str, list<string>* return_list);
198 # - converts a string to a semicolon separated list
199 # - what it really does is just string_replace all running whitespace to a semicolon
200 # - in cmake, a list is strings separated by semicolons: i.e., list of four items, list = "item1;item2;item3;item4"
201 function(libomp_string_to_list str return_list)
203 string(REGEX REPLACE "[ \t]+" ";" outstr "${str}")
204 set(${return_list} "${outstr}" PARENT_SCOPE)