Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 1 | # |
| 2 | #//===----------------------------------------------------------------------===// |
| 3 | #// |
| 4 | #// The LLVM Compiler Infrastructure |
| 5 | #// |
| 6 | #// This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | #// Source Licenses. See LICENSE.txt for details. |
| 8 | #// |
| 9 | #//===----------------------------------------------------------------------===// |
| 10 | # |
| 11 | |
| 12 | # void libomp_say(string message_to_user); |
| 13 | # - prints out message_to_user |
| 14 | macro(libomp_say message_to_user) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 15 | message(STATUS "LIBOMP: ${message_to_user}") |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 16 | endmacro() |
| 17 | |
| 18 | # void libomp_warning_say(string message_to_user); |
| 19 | # - prints out message_to_user with a warning |
| 20 | macro(libomp_warning_say message_to_user) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 21 | message(WARNING "LIBOMP: ${message_to_user}") |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 22 | endmacro() |
| 23 | |
| 24 | # void libomp_error_say(string message_to_user); |
| 25 | # - prints out message_to_user with an error and exits cmake |
| 26 | macro(libomp_error_say message_to_user) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 27 | message(FATAL_ERROR "LIBOMP: ${message_to_user}") |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 28 | endmacro() |
| 29 | |
| 30 | # libomp_append(<flag> <flags_list> [(IF_TRUE | IF_FALSE | IF_TRUE_1_0 ) BOOLEAN]) |
| 31 | # |
| 32 | # libomp_append(<flag> <flags_list>) |
| 33 | # - unconditionally appends <flag> to the list of definitions |
| 34 | # |
| 35 | # libomp_append(<flag> <flags_list> <BOOLEAN>) |
| 36 | # - appends <flag> to the list of definitions if BOOLEAN is true |
| 37 | # |
| 38 | # libomp_append(<flag> <flags_list> IF_TRUE <BOOLEAN>) |
| 39 | # - appends <flag> to the list of definitions if BOOLEAN is true |
| 40 | # |
| 41 | # libomp_append(<flag> <flags_list> IF_FALSE <BOOLEAN>) |
| 42 | # - appends <flag> to the list of definitions if BOOLEAN is false |
| 43 | # |
| 44 | # libomp_append(<flag> <flags_list> IF_DEFINED <VARIABLE>) |
| 45 | # - appends <flag> to the list of definitions if VARIABLE is defined |
| 46 | # |
| 47 | # libomp_append(<flag> <flags_list> IF_TRUE_1_0 <BOOLEAN>) |
| 48 | # - appends <flag>=1 to the list of definitions if <BOOLEAN> is true, <flag>=0 otherwise |
| 49 | # e.g., libomp_append("-D USE_FEATURE" IF_TRUE_1_0 HAVE_FEATURE) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 50 | # appends "-D USE_FEATURE=1" if HAVE_FEATURE is true |
| 51 | # or "-D USE_FEATURE=0" if HAVE_FEATURE is false |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 52 | macro(libomp_append flags flag) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 53 | if(NOT (${ARGC} EQUAL 2 OR ${ARGC} EQUAL 3 OR ${ARGC} EQUAL 4)) |
| 54 | libomp_error_say("libomp_append: takes 2, 3, or 4 arguments") |
| 55 | endif() |
| 56 | if(${ARGC} EQUAL 2) |
| 57 | list(APPEND ${flags} "${flag}") |
| 58 | elseif(${ARGC} EQUAL 3) |
| 59 | if(${ARGV2}) |
| 60 | list(APPEND ${flags} "${flag}") |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 61 | endif() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 62 | else() |
| 63 | if(${ARGV2} STREQUAL "IF_TRUE") |
| 64 | if(${ARGV3}) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 65 | list(APPEND ${flags} "${flag}") |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 66 | endif() |
| 67 | elseif(${ARGV2} STREQUAL "IF_FALSE") |
| 68 | if(NOT ${ARGV3}) |
| 69 | list(APPEND ${flags} "${flag}") |
| 70 | endif() |
| 71 | elseif(${ARGV2} STREQUAL "IF_DEFINED") |
| 72 | if(DEFINED ${ARGV3}) |
| 73 | list(APPEND ${flags} "${flag}") |
| 74 | endif() |
| 75 | elseif(${ARGV2} STREQUAL "IF_TRUE_1_0") |
| 76 | if(${ARGV3}) |
| 77 | list(APPEND ${flags} "${flag}=1") |
| 78 | else() |
| 79 | list(APPEND ${flags} "${flag}=0") |
| 80 | endif() |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 81 | else() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 82 | libomp_error_say("libomp_append: third argument must be one of IF_TRUE, IF_FALSE, IF_DEFINED, IF_TRUE_1_0") |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 83 | endif() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 84 | endif() |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 85 | endmacro() |
| 86 | |
| 87 | # void libomp_get_legal_arch(string* return_arch_string); |
| 88 | # - returns (through return_arch_string) the formal architecture |
| 89 | # string or warns user of unknown architecture |
| 90 | function(libomp_get_legal_arch return_arch_string) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 91 | if(${IA32}) |
| 92 | set(${return_arch_string} "IA-32" PARENT_SCOPE) |
| 93 | elseif(${INTEL64}) |
| 94 | set(${return_arch_string} "Intel(R) 64" PARENT_SCOPE) |
| 95 | elseif(${MIC}) |
| 96 | set(${return_arch_string} "Intel(R) Many Integrated Core Architecture" PARENT_SCOPE) |
| 97 | elseif(${ARM}) |
| 98 | set(${return_arch_string} "ARM" PARENT_SCOPE) |
| 99 | elseif(${PPC64BE}) |
| 100 | set(${return_arch_string} "PPC64BE" PARENT_SCOPE) |
| 101 | elseif(${PPC64LE}) |
| 102 | set(${return_arch_string} "PPC64LE" PARENT_SCOPE) |
| 103 | elseif(${AARCH64}) |
| 104 | set(${return_arch_string} "AARCH64" PARENT_SCOPE) |
Sylvestre Ledru | cd9d374 | 2016-12-08 09:22:24 +0000 | [diff] [blame] | 105 | elseif(${MIPS}) |
| 106 | set(${return_arch_string} "MIPS" PARENT_SCOPE) |
| 107 | elseif(${MIPS64}) |
| 108 | set(${return_arch_string} "MIPS64" PARENT_SCOPE) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 109 | else() |
| 110 | set(${return_arch_string} "${LIBOMP_ARCH}" PARENT_SCOPE) |
| 111 | libomp_warning_say("libomp_get_legal_arch(): Warning: Unknown architecture: Using ${LIBOMP_ARCH}") |
| 112 | endif() |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 113 | endfunction() |
| 114 | |
| 115 | # void libomp_check_variable(string var, ...); |
| 116 | # - runs through all values checking if ${var} == value |
| 117 | # - uppercase and lowercase do not matter |
| 118 | # - if the var is found, then just print it out |
| 119 | # - if the var is not found, then error out |
| 120 | function(libomp_check_variable var) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 121 | set(valid_flag 0) |
| 122 | string(TOLOWER "${${var}}" var_lower) |
| 123 | foreach(value IN LISTS ARGN) |
| 124 | string(TOLOWER "${value}" value_lower) |
| 125 | if("${var_lower}" STREQUAL "${value_lower}") |
| 126 | set(valid_flag 1) |
| 127 | set(the_value "${value}") |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 128 | endif() |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 129 | endforeach() |
| 130 | if(${valid_flag} EQUAL 0) |
| 131 | libomp_error_say("libomp_check_variable(): ${var} = ${${var}} is unknown") |
| 132 | endif() |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 133 | endfunction() |
| 134 | |
| 135 | # void libomp_get_build_number(string src_dir, string* return_build_number); |
Jonathan Peyton | 7cc577a | 2016-12-14 22:39:11 +0000 | [diff] [blame^] | 136 | # - grab the eight digit build number (or 00000000) from kmp_version.cpp |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 137 | function(libomp_get_build_number src_dir return_build_number) |
Jonathan Peyton | 7cc577a | 2016-12-14 22:39:11 +0000 | [diff] [blame^] | 138 | # sets file_lines_list to a list of all lines in kmp_version.cpp |
| 139 | file(STRINGS "${src_dir}/src/kmp_version.cpp" file_lines_list) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 140 | |
Jonathan Peyton | 7cc577a | 2016-12-14 22:39:11 +0000 | [diff] [blame^] | 141 | # runs through each line in kmp_version.cpp |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 142 | foreach(line IN LISTS file_lines_list) |
| 143 | # if the line begins with "#define KMP_VERSION_BUILD" then we take not of the build number |
| 144 | string(REGEX MATCH "^[ \t]*#define[ \t]+KMP_VERSION_BUILD" valid "${line}") |
| 145 | if(NOT "${valid}" STREQUAL "") # if we matched "#define KMP_VERSION_BUILD", then grab the build number |
| 146 | string(REGEX REPLACE "^[ \t]*#define[ \t]+KMP_VERSION_BUILD[ \t]+([0-9]+)" "\\1" |
| 147 | build_number "${line}" |
| 148 | ) |
| 149 | endif() |
| 150 | endforeach() |
| 151 | set(${return_build_number} "${build_number}" PARENT_SCOPE) # return build number |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 152 | endfunction() |
| 153 | |
| 154 | # void libomp_get_legal_type(string* return_legal_type); |
| 155 | # - set the legal type name Performance/Profiling/Stub |
| 156 | function(libomp_get_legal_type return_legal_type) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 157 | if(${NORMAL_LIBRARY}) |
| 158 | set(${return_legal_type} "Performance" PARENT_SCOPE) |
| 159 | elseif(${PROFILE_LIBRARY}) |
| 160 | set(${return_legal_type} "Profiling" PARENT_SCOPE) |
| 161 | elseif(${STUBS_LIBRARY}) |
| 162 | set(${return_legal_type} "Stub" PARENT_SCOPE) |
| 163 | endif() |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 164 | endfunction() |
| 165 | |
| 166 | # void libomp_add_suffix(string suffix, list<string>* list_of_items); |
| 167 | # - returns list_of_items with suffix appended to all items |
| 168 | # - original list is modified |
| 169 | function(libomp_add_suffix suffix list_of_items) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 170 | set(local_list "") |
| 171 | foreach(item IN LISTS "${list_of_items}") |
| 172 | if(NOT "${item}" STREQUAL "") |
| 173 | list(APPEND local_list "${item}${suffix}") |
| 174 | endif() |
| 175 | endforeach() |
| 176 | set(${list_of_items} "${local_list}" PARENT_SCOPE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 177 | endfunction() |
| 178 | |
| 179 | # void libomp_list_to_string(list<string> list_of_things, string* return_string); |
| 180 | # - converts a list to a space separated string |
| 181 | function(libomp_list_to_string list_of_things return_string) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 182 | string(REPLACE ";" " " output_variable "${list_of_things}") |
| 183 | set(${return_string} "${output_variable}" PARENT_SCOPE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 184 | endfunction() |
| 185 | |
| 186 | # void libomp_string_to_list(string str, list<string>* return_list); |
| 187 | # - converts a string to a semicolon separated list |
| 188 | # - what it really does is just string_replace all running whitespace to a semicolon |
| 189 | # - in cmake, a list is strings separated by semicolons: i.e., list of four items, list = "item1;item2;item3;item4" |
| 190 | function(libomp_string_to_list str return_list) |
Jonathan Peyton | 5b4acbd | 2015-07-15 16:57:19 +0000 | [diff] [blame] | 191 | set(outstr) |
| 192 | string(REGEX REPLACE "[ \t]+" ";" outstr "${str}") |
| 193 | set(${return_list} "${outstr}" PARENT_SCOPE) |
Jonathan Peyton | 2e01335 | 2015-07-15 16:05:30 +0000 | [diff] [blame] | 194 | endfunction() |
| 195 | |