blob: ba81a6c79e23f12a62f6d63e74209771c03de156 [file] [log] [blame]
Jonathan Peyton2e013352015-07-15 16:05:30 +00001#
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
14macro(libomp_say message_to_user)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000015 message(STATUS "LIBOMP: ${message_to_user}")
Jonathan Peyton2e013352015-07-15 16:05:30 +000016endmacro()
17
18# void libomp_warning_say(string message_to_user);
19# - prints out message_to_user with a warning
20macro(libomp_warning_say message_to_user)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000021 message(WARNING "LIBOMP: ${message_to_user}")
Jonathan Peyton2e013352015-07-15 16:05:30 +000022endmacro()
23
24# void libomp_error_say(string message_to_user);
25# - prints out message_to_user with an error and exits cmake
26macro(libomp_error_say message_to_user)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000027 message(FATAL_ERROR "LIBOMP: ${message_to_user}")
Jonathan Peyton2e013352015-07-15 16:05:30 +000028endmacro()
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 Peyton5b4acbd2015-07-15 16:57:19 +000050# appends "-D USE_FEATURE=1" if HAVE_FEATURE is true
51# or "-D USE_FEATURE=0" if HAVE_FEATURE is false
Jonathan Peyton2e013352015-07-15 16:05:30 +000052macro(libomp_append flags flag)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000053 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 Peyton2e013352015-07-15 16:05:30 +000061 endif()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000062 else()
63 if(${ARGV2} STREQUAL "IF_TRUE")
64 if(${ARGV3})
Jonathan Peyton2e013352015-07-15 16:05:30 +000065 list(APPEND ${flags} "${flag}")
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000066 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 Peyton2e013352015-07-15 16:05:30 +000081 else()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000082 libomp_error_say("libomp_append: third argument must be one of IF_TRUE, IF_FALSE, IF_DEFINED, IF_TRUE_1_0")
Jonathan Peyton2e013352015-07-15 16:05:30 +000083 endif()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000084 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +000085endmacro()
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
90function(libomp_get_legal_arch return_arch_string)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +000091 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)
105 else()
106 set(${return_arch_string} "${LIBOMP_ARCH}" PARENT_SCOPE)
107 libomp_warning_say("libomp_get_legal_arch(): Warning: Unknown architecture: Using ${LIBOMP_ARCH}")
108 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000109endfunction()
110
111# void libomp_check_variable(string var, ...);
112# - runs through all values checking if ${var} == value
113# - uppercase and lowercase do not matter
114# - if the var is found, then just print it out
115# - if the var is not found, then error out
116function(libomp_check_variable var)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000117 set(valid_flag 0)
118 string(TOLOWER "${${var}}" var_lower)
119 foreach(value IN LISTS ARGN)
120 string(TOLOWER "${value}" value_lower)
121 if("${var_lower}" STREQUAL "${value_lower}")
122 set(valid_flag 1)
123 set(the_value "${value}")
Jonathan Peyton2e013352015-07-15 16:05:30 +0000124 endif()
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000125 endforeach()
126 if(${valid_flag} EQUAL 0)
127 libomp_error_say("libomp_check_variable(): ${var} = ${${var}} is unknown")
128 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000129endfunction()
130
131# void libomp_get_build_number(string src_dir, string* return_build_number);
132# - grab the eight digit build number (or 00000000) from kmp_version.c
133function(libomp_get_build_number src_dir return_build_number)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000134 # sets file_lines_list to a list of all lines in kmp_version.c
135 file(STRINGS "${src_dir}/src/kmp_version.c" file_lines_list)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000136
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000137 # runs through each line in kmp_version.c
138 foreach(line IN LISTS file_lines_list)
139 # if the line begins with "#define KMP_VERSION_BUILD" then we take not of the build number
140 string(REGEX MATCH "^[ \t]*#define[ \t]+KMP_VERSION_BUILD" valid "${line}")
141 if(NOT "${valid}" STREQUAL "") # if we matched "#define KMP_VERSION_BUILD", then grab the build number
142 string(REGEX REPLACE "^[ \t]*#define[ \t]+KMP_VERSION_BUILD[ \t]+([0-9]+)" "\\1"
143 build_number "${line}"
144 )
145 endif()
146 endforeach()
147 set(${return_build_number} "${build_number}" PARENT_SCOPE) # return build number
Jonathan Peyton2e013352015-07-15 16:05:30 +0000148endfunction()
149
150# void libomp_get_legal_type(string* return_legal_type);
151# - set the legal type name Performance/Profiling/Stub
152function(libomp_get_legal_type return_legal_type)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000153 if(${NORMAL_LIBRARY})
154 set(${return_legal_type} "Performance" PARENT_SCOPE)
155 elseif(${PROFILE_LIBRARY})
156 set(${return_legal_type} "Profiling" PARENT_SCOPE)
157 elseif(${STUBS_LIBRARY})
158 set(${return_legal_type} "Stub" PARENT_SCOPE)
159 endif()
Jonathan Peyton2e013352015-07-15 16:05:30 +0000160endfunction()
161
162# void libomp_add_suffix(string suffix, list<string>* list_of_items);
163# - returns list_of_items with suffix appended to all items
164# - original list is modified
165function(libomp_add_suffix suffix list_of_items)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000166 set(local_list "")
167 foreach(item IN LISTS "${list_of_items}")
168 if(NOT "${item}" STREQUAL "")
169 list(APPEND local_list "${item}${suffix}")
170 endif()
171 endforeach()
172 set(${list_of_items} "${local_list}" PARENT_SCOPE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000173endfunction()
174
175# void libomp_list_to_string(list<string> list_of_things, string* return_string);
176# - converts a list to a space separated string
177function(libomp_list_to_string list_of_things return_string)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000178 string(REPLACE ";" " " output_variable "${list_of_things}")
179 set(${return_string} "${output_variable}" PARENT_SCOPE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000180endfunction()
181
182# void libomp_string_to_list(string str, list<string>* return_list);
183# - converts a string to a semicolon separated list
184# - what it really does is just string_replace all running whitespace to a semicolon
185# - in cmake, a list is strings separated by semicolons: i.e., list of four items, list = "item1;item2;item3;item4"
186function(libomp_string_to_list str return_list)
Jonathan Peyton5b4acbd2015-07-15 16:57:19 +0000187 set(outstr)
188 string(REGEX REPLACE "[ \t]+" ";" outstr "${str}")
189 set(${return_list} "${outstr}" PARENT_SCOPE)
Jonathan Peyton2e013352015-07-15 16:05:30 +0000190endfunction()
191