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_A64FX})
105 set(${return_arch_string} "AARCH64_A64FX" PARENT_SCOPE)
107 set(${return_arch_string} "MIPS" PARENT_SCOPE)
109 set(${return_arch_string} "MIPS64" PARENT_SCOPE)
111 set(${return_arch_string} "RISCV64" PARENT_SCOPE)
112 elseif(${LOONGARCH64})
113 set(${return_arch_string} "LOONGARCH64" PARENT_SCOPE)
115 set(${return_arch_string} "VE" PARENT_SCOPE)
117 set(${return_arch_string} "${LIBOMP_ARCH}" PARENT_SCOPE)
118 libomp_warning_say("libomp_get_legal_arch(): Warning: Unknown architecture: Using ${LIBOMP_ARCH}")
122 # void libomp_check_variable(string var, ...);
123 # - runs through all values checking if ${var} == value
124 # - uppercase and lowercase do not matter
125 # - if the var is found, then just print it out
126 # - if the var is not found, then error out
127 function(libomp_check_variable var)
129 string(TOLOWER "${${var}}" var_lower)
130 foreach(value IN LISTS ARGN)
131 string(TOLOWER "${value}" value_lower)
132 if("${var_lower}" STREQUAL "${value_lower}")
134 set(the_value "${value}")
137 if(${valid_flag} EQUAL 0)
138 libomp_error_say("libomp_check_variable(): ${var} = ${${var}} is unknown")
142 # void libomp_get_build_number(string src_dir, string* return_build_number);
143 # - grab the eight digit build number (or 00000000) from kmp_version.cpp
144 function(libomp_get_build_number src_dir return_build_number)
145 # sets file_lines_list to a list of all lines in kmp_version.cpp
146 file(STRINGS "${src_dir}/src/kmp_version.cpp" file_lines_list)
148 # runs through each line in kmp_version.cpp
149 foreach(line IN LISTS file_lines_list)
150 # if the line begins with "#define KMP_VERSION_BUILD" then we take not of the build number
151 string(REGEX MATCH "^[ \t]*#define[ \t]+KMP_VERSION_BUILD" valid "${line}")
152 if(NOT "${valid}" STREQUAL "") # if we matched "#define KMP_VERSION_BUILD", then grab the build number
153 string(REGEX REPLACE "^[ \t]*#define[ \t]+KMP_VERSION_BUILD[ \t]+([0-9]+)" "\\1"
154 build_number "${line}"
158 set(${return_build_number} "${build_number}" PARENT_SCOPE) # return build number
161 # void libomp_get_legal_type(string* return_legal_type);
162 # - set the legal type name Performance/Profiling/Stub
163 function(libomp_get_legal_type return_legal_type)
164 if(${NORMAL_LIBRARY})
165 set(${return_legal_type} "Performance" PARENT_SCOPE)
166 elseif(${PROFILE_LIBRARY})
167 set(${return_legal_type} "Profiling" PARENT_SCOPE)
168 elseif(${STUBS_LIBRARY})
169 set(${return_legal_type} "Stub" PARENT_SCOPE)
173 # void libomp_add_suffix(string suffix, list<string>* list_of_items);
174 # - returns list_of_items with suffix appended to all items
175 # - original list is modified
176 function(libomp_add_suffix suffix list_of_items)
178 foreach(item IN LISTS "${list_of_items}")
179 if(NOT "${item}" STREQUAL "")
180 list(APPEND local_list "${item}${suffix}")
183 set(${list_of_items} "${local_list}" PARENT_SCOPE)
186 # void libomp_list_to_string(list<string> list_of_things, string* return_string);
187 # - converts a list to a space separated string
188 function(libomp_list_to_string list_of_things return_string)
189 string(REPLACE ";" " " output_variable "${list_of_things}")
190 set(${return_string} "${output_variable}" PARENT_SCOPE)
193 # void libomp_string_to_list(string str, list<string>* return_list);
194 # - converts a string to a semicolon separated list
195 # - what it really does is just string_replace all running whitespace to a semicolon
196 # - in cmake, a list is strings separated by semicolons: i.e., list of four items, list = "item1;item2;item3;item4"
197 function(libomp_string_to_list str return_list)
199 string(REGEX REPLACE "[ \t]+" ";" outstr "${str}")
200 set(${return_list} "${outstr}" PARENT_SCOPE)