This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
llvm_utils.cmake
180 lines (156 loc) · 10.6 KB
/
llvm_utils.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#===================== begin_copyright_notice ==================================
#
# Copyright (c) 2018 Intel Corporation.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
#
# ======================= end_copyright_notice ==================================
#
# Macro to set python interpreter for LLVM
#
macro(llvm_utils_python_set)
# Unset directory scope PYTHON_EXECUTABLE variable
unset(PYTHON_EXECUTABLE)
# Check for cached PYTHON_EXECUTABLE variable
if(PYTHON_EXECUTABLE)
# If cached PYTHON_EXECUTABLE already exists save it to restore
set(PYTHON_EXECUTABLE_BACKUP ${PYTHON_EXECUTABLE})
endif()
# Set python interpreter for LLVM
set(PYTHON_EXECUTABLE ${PYTHON} CACHE PATH "desc" FORCE)
message(STATUS "[LLVM] PYTHON_EXECUTABLE = ${PYTHON_EXECUTABLE}")
endmacro()
#
# Macro to restore python interpreter
#
macro(llvm_utils_python_restore)
if(PYTHON_EXECUTABLE_BACKUP)
# Restore python interpreter
set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE_BACKUP} CACHE PATH "desc" FORCE)
else()
# Clear python interpreter for LLVM
unset(PYTHON_EXECUTABLE CACHE)
endif()
endmacro()
#
# Macro to clear and backup build flags already set
#
macro(llvm_utils_push_build_flags)
message(STATUS "[LLVM] Clearing build system compilation flags")
set(CMAKE_C_FLAGS_BACKUP ${CMAKE_C_FLAGS})
set(CMAKE_CXX_FLAGS_BACKUP ${CMAKE_CXX_FLAGS})
set(CMAKE_SHARED_LINKER_FLAGS_BACKUP ${CMAKE_SHARED_LINKER_FLAGS})
set(CMAKE_EXE_LINKER_FLAGS_BACKUP ${CMAKE_EXE_LINKER_FLAGS})
set(CMAKE_STATIC_LINKER_FLAGS_BACKUP ${CMAKE_STATIC_LINKER_FLAGS})
set(CMAKE_LOCAL_LINKER_FLAGS_BACKUP ${CMAKE_LOCAL_LINKER_FLAGS})
set(CMAKE_MODULE_LINKER_FLAGS_BACKUP ${CMAKE_MODULE_LINKER_FLAGS})
if(PRINT_DEBUG)
message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}")
message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")
message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_SHARED_LINKER_FLAGS = ${CMAKE_SHARED_LINKER_FLAGS}")
message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}")
message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_STATIC_LINKER_FLAGS = ${CMAKE_STATIC_LINKER_FLAGS}")
message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_LOCAL_LINKER_FLAGS = ${CMAKE_LOCAL_LINKER_FLAGS}")
message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_MODULE_LINKER_FLAGS = ${CMAKE_MODULE_LINKER_FLAGS}")
endif()
unset(CMAKE_C_FLAGS)
unset(CMAKE_CXX_FLAGS)
unset(CMAKE_SHARED_LINKER_FLAGS)
unset(CMAKE_EXE_LINKER_FLAGS)
unset(CMAKE_STATIC_LINKER_FLAGS)
unset(CMAKE_LOCAL_LINKER_FLAGS)
unset(CMAKE_MODULE_LINKER_FLAGS)
foreach(configuration_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
string(TOUPPER ${configuration_type} capitalized_configuration_type)
set(CMAKE_C_FLAGS_${capitalized_configuration_type}_BACKUP ${CMAKE_C_FLAGS_${capitalized_configuration_type}})
set(CMAKE_CXX_FLAGS_${capitalized_configuration_type}_BACKUP ${CMAKE_CXX_FLAGS_${capitalized_configuration_type}})
set(CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP ${CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type}})
set(CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP ${CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type}})
set(CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP ${CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type}})
set(CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP ${CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type}})
if(PRINT_DEBUG)
message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_C_FLAGS_${capitalized_configuration_type} = ${CMAKE_C_FLAGS_${capitalized_configuration_type}}")
message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_CXX_FLAGS_${capitalized_configuration_type} = ${CMAKE_CXX_FLAGS_${capitalized_configuration_type}}")
message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type}}")
message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type}}")
message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type}}")
message(STATUS "[LLVM] llvm_utils_push_build_flags() CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type}}")
endif()
unset(CMAKE_C_FLAGS_${capitalized_configuration_type})
unset(CMAKE_CXX_FLAGS_${capitalized_configuration_type})
unset(CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type})
unset(CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type})
unset(CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type})
unset(CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type})
endforeach()
endmacro()
#
# Macro to restore build flags set previously
#
macro(llvm_utils_pop_build_flags)
message(STATUS "[LLVM] Restoring build system compilation flags")
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_BACKUP})
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS_BACKUP})
set(CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS_BACKUP})
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS_BACKUP})
set(CMAKE_STATIC_LINKER_FLAGS ${CMAKE_STATIC_LINKER_FLAGS_BACKUP})
set(CMAKE_LOCAL_LINKER_FLAGS ${CMAKE_LOCAL_LINKER_FLAGS_BACKUP})
set(CMAKE_MODULE_LINKER_FLAGS ${CMAKE_MODULE_LINKER_FLAGS_BACKUP})
if(PRINT_DEBUG)
message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}")
message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")
message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_SHARED_LINKER_FLAGS = ${CMAKE_SHARED_LINKER_FLAGS}")
message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}")
message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_STATIC_LINKER_FLAGS = ${CMAKE_STATIC_LINKER_FLAGS}")
message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_LOCAL_LINKER_FLAGS = ${CMAKE_LOCAL_LINKER_FLAGS}")
message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_MODULE_LINKER_FLAGS = ${CMAKE_MODULE_LINKER_FLAGS}")
endif()
unset(CMAKE_C_FLAGS_BACKUP)
unset(CMAKE_CXX_FLAGS_BACKUP)
unset(CMAKE_SHARED_LINKER_FLAGS_BACKUP)
unset(CMAKE_EXE_LINKER_FLAGS_BACKUP)
unset(CMAKE_STATIC_LINKER_FLAGS_BACKUP)
unset(CMAKE_LOCAL_LINKER_FLAGS_BACKUP)
unset(CMAKE_MODULE_LINKER_FLAGS_BACKUP)
foreach(configuration_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
string(TOUPPER ${configuration_type} capitalized_configuration_type)
set(CMAKE_C_FLAGS_${capitalized_configuration_type} ${CMAKE_C_FLAGS_${capitalized_configuration_type}_BACKUP})
set(CMAKE_CXX_FLAGS_${capitalized_configuration_type} ${CMAKE_CXX_FLAGS_${capitalized_configuration_type}_BACKUP})
set(CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type} ${CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP})
set(CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type} ${CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP})
set(CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type} ${CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP})
set(CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type} ${CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP})
if(PRINT_DEBUG)
message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_C_FLAGS_${capitalized_configuration_type} = ${CMAKE_C_FLAGS_${capitalized_configuration_type}}")
message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_CXX_FLAGS_${capitalized_configuration_type} = ${CMAKE_CXX_FLAGS_${capitalized_configuration_type}}")
message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type}}")
message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type}}")
message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type}}")
message(STATUS "[LLVM] llvm_utils_pop_build_flags() CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type} = ${CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type}}")
endif()
unset(CMAKE_C_FLAGS_${capitalized_configuration_type}_BACKUP)
unset(CMAKE_CXX_FLAGS_${capitalized_configuration_type}_BACKUP)
unset(CMAKE_SHARED_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP)
unset(CMAKE_EXE_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP)
unset(CMAKE_STATIC_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP)
unset(CMAKE_MODULE_LINKER_FLAGS_${capitalized_configuration_type}_BACKUP)
endforeach()
endmacro()