brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.9 KiB · a810881 Raw
211 lines · plain
1#2#//===----------------------------------------------------------------------===//3#//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-exception7#//8#//===----------------------------------------------------------------------===//9#10 11# void libomp_say(string message_to_user);12# - prints out message_to_user13macro(libomp_say message_to_user)14  message(STATUS "LIBOMP: ${message_to_user}")15endmacro()16 17# void libomp_warning_say(string message_to_user);18# - prints out message_to_user with a warning19macro(libomp_warning_say message_to_user)20  message(WARNING "LIBOMP: ${message_to_user}")21endmacro()22 23# void libomp_error_say(string message_to_user);24# - prints out message_to_user with an error and exits cmake25macro(libomp_error_say message_to_user)26  message(FATAL_ERROR "LIBOMP: ${message_to_user}")27endmacro()28 29# libomp_append(<flag> <flags_list> [(IF_TRUE | IF_FALSE | IF_TRUE_1_0 ) BOOLEAN])30#31# libomp_append(<flag> <flags_list>)32#   - unconditionally appends <flag> to the list of definitions33#34# libomp_append(<flag> <flags_list> <BOOLEAN>)35#   - appends <flag> to the list of definitions if BOOLEAN is true36#37# libomp_append(<flag> <flags_list> IF_TRUE <BOOLEAN>)38#   - appends <flag> to the list of definitions if BOOLEAN is true39#40# libomp_append(<flag> <flags_list> IF_FALSE <BOOLEAN>)41#   - appends <flag> to the list of definitions if BOOLEAN is false42#43# libomp_append(<flag> <flags_list> IF_DEFINED <VARIABLE>)44#   - appends <flag> to the list of definitions if VARIABLE is defined45#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 otherwise48# e.g., libomp_append("-D USE_FEATURE" IF_TRUE_1_0 HAVE_FEATURE)49#     appends "-D USE_FEATURE=1" if HAVE_FEATURE is true50#     or "-D USE_FEATURE=0" if HAVE_FEATURE is false51macro(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")54  endif()55  if(${ARGC} EQUAL 2)56    list(APPEND ${flags} "${flag}")57  elseif(${ARGC} EQUAL 3)58    if(${ARGV2})59      list(APPEND ${flags} "${flag}")60    endif()61  else()62    if(${ARGV2} STREQUAL "IF_TRUE")63      if(${ARGV3})64        list(APPEND ${flags} "${flag}")65      endif()66    elseif(${ARGV2} STREQUAL "IF_FALSE")67      if(NOT ${ARGV3})68        list(APPEND ${flags} "${flag}")69      endif()70    elseif(${ARGV2} STREQUAL "IF_DEFINED")71      if(DEFINED ${ARGV3})72        list(APPEND ${flags} "${flag}")73      endif()74    elseif(${ARGV2} STREQUAL "IF_TRUE_1_0")75      if(${ARGV3})76        list(APPEND ${flags} "${flag}=1")77      else()78        list(APPEND ${flags} "${flag}=0")79      endif()80    else()81      libomp_error_say("libomp_append: third argument must be one of IF_TRUE, IF_FALSE, IF_DEFINED, IF_TRUE_1_0")82    endif()83  endif()84endmacro()85 86# void libomp_get_legal_arch(string* return_arch_string);87# - returns (through return_arch_string) the formal architecture88#   string or warns user of unknown architecture89function(libomp_get_legal_arch return_arch_string)90  if(${IA32})91    set(${return_arch_string} "IA-32" PARENT_SCOPE)92  elseif(${INTEL64})93    set(${return_arch_string} "Intel(R) 64" PARENT_SCOPE)94  elseif(${MIC})95    set(${return_arch_string} "Intel(R) Many Integrated Core Architecture" PARENT_SCOPE)96  elseif(${ARM})97    set(${return_arch_string} "ARM" PARENT_SCOPE)98  elseif(${PPC64BE})99    set(${return_arch_string} "PPC64BE" PARENT_SCOPE)100  elseif(${PPC64LE})101    set(${return_arch_string} "PPC64LE" PARENT_SCOPE)102  elseif(${AARCH64})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)108  elseif(${MIPS})109    set(${return_arch_string} "MIPS" PARENT_SCOPE)110  elseif(${MIPS64})111    set(${return_arch_string} "MIPS64" PARENT_SCOPE)112  elseif(${RISCV64})113    set(${return_arch_string} "RISCV64" PARENT_SCOPE)114  elseif(${LOONGARCH64})115    set(${return_arch_string} "LOONGARCH64" PARENT_SCOPE)116  elseif(${VE})117    set(${return_arch_string} "VE" PARENT_SCOPE)118  elseif(${S390X})119    set(${return_arch_string} "S390X" PARENT_SCOPE)120  elseif(${SPARC})121    set(${return_arch_string} "SPARC" PARENT_SCOPE)122  elseif(${SPARCV9})123    set(${return_arch_string} "SPARCV9" PARENT_SCOPE)124  else()125    set(${return_arch_string} "${LIBOMP_ARCH}" PARENT_SCOPE)126    libomp_warning_say("libomp_get_legal_arch(): Warning: Unknown architecture: Using ${LIBOMP_ARCH}")127  endif()128endfunction()129 130# void libomp_check_variable(string var, ...);131# - runs through all values checking if ${var} == value132# - uppercase and lowercase do not matter133# - if the var is found, then just print it out134# - if the var is not found, then error out135function(libomp_check_variable var)136  set(valid_flag 0)137  string(TOLOWER "${${var}}" var_lower)138  foreach(value IN LISTS ARGN)139    string(TOLOWER "${value}" value_lower)140    if("${var_lower}" STREQUAL "${value_lower}")141      set(valid_flag 1)142      set(the_value "${value}")143    endif()144  endforeach()145  if(${valid_flag} EQUAL 0)146    libomp_error_say("libomp_check_variable(): ${var} = ${${var}} is unknown")147  endif()148endfunction()149 150# void libomp_get_build_number(string src_dir, string* return_build_number);151# - grab the eight digit build number (or 00000000) from kmp_version.cpp152function(libomp_get_build_number src_dir return_build_number)153  # sets file_lines_list to a list of all lines in kmp_version.cpp154  file(STRINGS "${src_dir}/src/kmp_version.cpp" file_lines_list)155 156  # runs through each line in kmp_version.cpp157  foreach(line IN LISTS file_lines_list)158    # if the line begins with "#define KMP_VERSION_BUILD" then we take not of the build number159    string(REGEX MATCH "^[ \t]*#define[ \t]+KMP_VERSION_BUILD" valid "${line}")160    if(NOT "${valid}" STREQUAL "") # if we matched "#define KMP_VERSION_BUILD", then grab the build number161      string(REGEX REPLACE "^[ \t]*#define[ \t]+KMP_VERSION_BUILD[ \t]+([0-9]+)" "\\1"162           build_number "${line}"163      )164    endif()165  endforeach()166  set(${return_build_number} "${build_number}" PARENT_SCOPE) # return build number167endfunction()168 169# void libomp_get_legal_type(string* return_legal_type);170# - set the legal type name Performance/Profiling/Stub171function(libomp_get_legal_type return_legal_type)172  if(${NORMAL_LIBRARY})173    set(${return_legal_type} "Performance" PARENT_SCOPE)174  elseif(${PROFILE_LIBRARY})175    set(${return_legal_type} "Profiling" PARENT_SCOPE)176  elseif(${STUBS_LIBRARY})177    set(${return_legal_type} "Stub" PARENT_SCOPE)178  endif()179endfunction()180 181# void libomp_add_suffix(string suffix, list<string>* list_of_items);182# - returns list_of_items with suffix appended to all items183# - original list is modified184function(libomp_add_suffix suffix list_of_items)185  set(local_list "")186  foreach(item IN LISTS "${list_of_items}")187    if(NOT "${item}" STREQUAL "")188      list(APPEND local_list "${item}${suffix}")189    endif()190  endforeach()191  set(${list_of_items} "${local_list}" PARENT_SCOPE)192endfunction()193 194# void libomp_list_to_string(list<string> list_of_things, string* return_string);195# - converts a list to a space separated string196function(libomp_list_to_string list_of_things return_string)197  string(REPLACE ";" " " output_variable "${list_of_things}")198  set(${return_string} "${output_variable}" PARENT_SCOPE)199endfunction()200 201# void libomp_string_to_list(string str, list<string>* return_list);202# - converts a string to a semicolon separated list203# - what it really does is just string_replace all running whitespace to a semicolon204# - in cmake, a list is strings separated by semicolons: i.e., list of four items, list = "item1;item2;item3;item4"205function(libomp_string_to_list str return_list)206  set(outstr)207  string(REGEX REPLACE "[ \t]+" ";" outstr "${str}")208  set(${return_list} "${outstr}" PARENT_SCOPE)209endfunction()210 211