@@ -8,7 +8,7 @@ cmake_minimum_required(VERSION 2.8.11)
8
8
9
9
set (LLVM_IR_UTIL_VERSION_MAJOR "1" )
10
10
set (LLVM_IR_UTIL_VERSION_MINOR "0" )
11
- set (LLVM_IR_UTIL_VERSION_PATCH "1 " )
11
+ set (LLVM_IR_UTIL_VERSION_PATCH "2 " )
12
12
13
13
string (CONCAT LLVM_IR_UTIL_VERSION
14
14
${LLVM_IR_UTIL_VERSION_MAJOR} "."
@@ -57,6 +57,21 @@ function(fatal message_txt)
57
57
endfunction ()
58
58
59
59
60
+ function (debug message_txt )
61
+ if ($ENV{LLVMIR_CMAKE_DEBUG} )
62
+ message (STATUS "[DEBUG] ${message_txt} " )
63
+ endif ()
64
+ endfunction ()
65
+
66
+
67
+ macro (catuniq lst )
68
+ list (APPEND ${lst} ${ARGN} )
69
+ if (${lst} )
70
+ list (REMOVE_DUPLICATES ${lst} )
71
+ endif ()
72
+ endmacro ()
73
+
74
+
60
75
macro (SetLLVMIRCompiler linker_language )
61
76
if ("${LLVMIR_COMPILER} " STREQUAL "" )
62
77
set (LLVMIR_COMPILER ${CMAKE_${linker_language}_COMPILER} )
@@ -113,6 +128,155 @@ function(CheckLLVMIRTargetProperties trgt)
113
128
endfunction ()
114
129
115
130
131
+ function (ExtractCompileDefsProperties out_compile_defs from )
132
+ set (defs "" )
133
+ set (compile_defs "" )
134
+ set (prop_name "COMPILE_DEFINITIONS" )
135
+
136
+ # per directory
137
+ get_property (defs DIRECTORY PROPERTY ${prop_name} )
138
+ foreach (def ${defs} )
139
+ list (APPEND compile_defs -D${def} )
140
+ endforeach ()
141
+
142
+ get_property (defs DIRECTORY PROPERTY ${prop_name} _${CMAKE_BUILD_TYPE} )
143
+ foreach (def ${defs} )
144
+ list (APPEND compile_defs -D${def} )
145
+ endforeach ()
146
+
147
+ # per target
148
+ if (TARGET ${from} )
149
+ get_property (defs TARGET ${from} PROPERTY ${prop_name} )
150
+ foreach (def ${defs} )
151
+ list (APPEND compile_defs -D${def} )
152
+ endforeach ()
153
+
154
+ get_property (defs TARGET ${from} PROPERTY ${prop_name} _${CMAKE_BUILD_TYPE} )
155
+ foreach (def ${defs} )
156
+ list (APPEND compile_defs -D${def} )
157
+ endforeach ()
158
+
159
+ get_property (defs TARGET ${from} PROPERTY INTERFACE_${prop_name} )
160
+ foreach (def ${defs} )
161
+ list (APPEND compile_defs -D${def} )
162
+ endforeach ()
163
+ else ()
164
+ # per file
165
+ get_property (defs SOURCE ${from} PROPERTY ${prop_name} )
166
+ foreach (def ${defs} )
167
+ list (APPEND compile_defs -D${def} )
168
+ endforeach ()
169
+
170
+ get_property (defs SOURCE ${from} PROPERTY ${prop_name} _${CMAKE_BUILD_TYPE} )
171
+ foreach (def ${defs} )
172
+ list (APPEND compile_defs -D${def} )
173
+ endforeach ()
174
+ endif ()
175
+
176
+ list (REMOVE_DUPLICATES compile_defs )
177
+
178
+ debug ("@ExtractCompileDefsProperties ${from} : ${compile_defs} " )
179
+
180
+ set (${out_compile_defs} ${compile_defs} PARENT_SCOPE )
181
+ endfunction ()
182
+
183
+
184
+ function (ExtractCompileOptionProperties out_compile_options trgt )
185
+ set (options "" )
186
+ set (compile_options "" )
187
+ set (prop_name "COMPILE_OPTIONS" )
188
+
189
+ # per directory
190
+ get_property (options DIRECTORY PROPERTY ${prop_name} )
191
+ foreach (opt ${options} )
192
+ list (APPEND compile_options ${opt} )
193
+ endforeach ()
194
+
195
+ # per target
196
+ get_property (options TARGET ${trgt} PROPERTY ${prop_name} )
197
+ foreach (opt ${options} )
198
+ list (APPEND compile_options ${opt} )
199
+ endforeach ()
200
+
201
+ get_property (options TARGET ${trgt} PROPERTY INTERFACE_${prop_name} )
202
+ foreach (opt ${options} )
203
+ list (APPEND compile_options ${opt} )
204
+ endforeach ()
205
+
206
+ list (REMOVE_DUPLICATES compile_options )
207
+
208
+ debug ("@ExtractCompileOptionProperties ${trgt} : ${compile_options} " )
209
+
210
+ set (${out_compile_options} ${compile_options} PARENT_SCOPE )
211
+ endfunction ()
212
+
213
+
214
+ function (ExtractIncludeDirsProperties out_include_dirs trgt )
215
+ set (dirs "" )
216
+ set (prop_name "INCLUDE_DIRECTORIES" )
217
+
218
+ # per directory
219
+ get_property (dirs DIRECTORY PROPERTY ${prop_name} )
220
+ foreach (dir ${dirs} )
221
+ list (APPEND include_dirs -I${dir} )
222
+ endforeach ()
223
+
224
+ # per target
225
+ get_property (dirs TARGET ${trgt} PROPERTY ${prop_name} )
226
+ foreach (dir ${dirs} )
227
+ list (APPEND include_dirs -I${dir} )
228
+ endforeach ()
229
+
230
+ get_property (dirs TARGET ${trgt} PROPERTY INTERFACE_${prop_name} )
231
+ foreach (dir ${dirs} )
232
+ list (APPEND include_dirs -I${dir} )
233
+ endforeach ()
234
+
235
+ get_property (dirs TARGET ${trgt} PROPERTY INTERFACE_SYSTEM_${prop_name} )
236
+ foreach (dir ${dirs} )
237
+ list (APPEND include_dirs -I${dir} )
238
+ endforeach ()
239
+
240
+ list (REMOVE_DUPLICATES include_dirs )
241
+
242
+ debug ("@ExtractIncludeDirsProperties ${trgt} : ${include_dirs} " )
243
+
244
+ set (${out_include_dirs} ${include_dirs} PARENT_SCOPE )
245
+ endfunction ()
246
+
247
+
248
+ function (ExtractLangFlags out_lang_flags lang )
249
+ set (lang_flags "" )
250
+
251
+ list (APPEND lang_flags ${CMAKE_${lang}_FLAGS_${CMAKE_BUILD_TYPE}} )
252
+ list (APPEND lang_flags ${CMAKE_${lang}_FLAGS} )
253
+
254
+ list (REMOVE_DUPLICATES lang_flags )
255
+
256
+ debug ("@ExtractLangFlags ${lang} : ${lang_flags} " )
257
+
258
+ set (${out_lang_flags} ${out_lang_flags_tmp} PARENT_SCOPE )
259
+ endfunction ()
260
+
261
+
262
+ function (ExtractCompileFlags out_compile_flags from )
263
+ #message(DEPRECATION "COMPILE_FLAGS property is deprecated.")
264
+
265
+ set (compile_flags "" )
266
+ set (prop_name "COMPILE_FLAGS" )
267
+
268
+ # deprecated according to cmake docs
269
+ if (TARGET ${from} )
270
+ get_property (compile_flags TARGET ${from} PROPERTY ${prop_name} )
271
+ else ()
272
+ get_property (compile_flags SOURCE ${from} PROPERTY ${prop_name} )
273
+ endif ()
274
+
275
+ debug ("@ExtractCompileFlags ${from} : ${compile_flags} " )
276
+
277
+ set (${out_compile_flags} ${compile_flags} PARENT_SCOPE )
278
+ endfunction ()
279
+
116
280
#
117
281
118
282
LLVMIRSetup ()
@@ -139,83 +303,28 @@ function(attach_llvmir_bc_target OUT_TRGT IN_TRGT)
139
303
get_property (IN_FILES TARGET ${IN_TRGT} PROPERTY SOURCES )
140
304
get_property (LINKER_LANGUAGE TARGET ${IN_TRGT} PROPERTY LINKER_LANGUAGE )
141
305
306
+ debug ("@attach_llvmir_bc_target ${IN_TRGT} linker lang: ${LINKER_LANGUAGE} " )
307
+
142
308
SetLLVMIRCompiler (${LINKER_LANGUAGE} )
143
309
144
310
## command options
145
311
set (WORK_DIR "${CMAKE_CURRENT_BINARY_DIR} /${LLVMIR_DIR} /${OUT_TRGT} " )
146
312
file (MAKE_DIRECTORY ${WORK_DIR} )
147
313
148
314
# compile definitions
149
- set (SRC_DEFS "" )
150
-
151
- # per directory
152
- get_property (SRC_DEFS_TMP DIRECTORY PROPERTY COMPILE_DEFINITIONS )
153
- foreach (DEF ${SRC_DEFS_TMP} )
154
- list (APPEND SRC_DEFS -D${DEF} )
155
- endforeach ()
156
-
157
- get_property (SRC_DEFS_TMP DIRECTORY PROPERTY
158
- COMPILE_DEFINITIONS_${CMAKE_BUILD_TYPE} )
159
- foreach (DEF ${SRC_DEFS_TMP} )
160
- list (APPEND SRC_DEFS -D${DEF} )
161
- endforeach ()
162
-
163
- # per target
164
- get_property (SRC_DEFS_TMP TARGET ${IN_TRGT} PROPERTY COMPILE_DEFINITIONS )
165
- foreach (DEF ${SRC_DEFS_TMP} )
166
- list (APPEND SRC_DEFS -D${DEF} )
167
- endforeach ()
168
-
169
- get_property (SRC_DEFS_TMP TARGET ${IN_TRGT} PROPERTY
170
- COMPILE_DEFINITIONS_${CMAKE_BUILD_TYPE} )
171
- foreach (DEF ${SRC_DEFS_TMP} )
172
- list (APPEND SRC_DEFS -D${DEF} )
173
- endforeach ()
315
+ ExtractCompileDefsProperties (IN_DEFS ${IN_TRGT} )
174
316
175
- get_property (SRC_DEFS_TMP TARGET ${IN_TRGT} PROPERTY
176
- INTERFACE_COMPILE_DEFINITIONS )
177
- foreach (DEF ${SRC_DEFS_TMP} )
178
- list (APPEND SRC_DEFS -D${DEF} )
179
- endforeach ()
180
-
181
- list (REMOVE_DUPLICATES SRC_DEFS )
317
+ # includes
318
+ ExtractIncludeDirsProperties (IN_INCLUDES ${IN_TRGT} )
182
319
183
320
# compile options
184
- set (SRC_COMPILE_OPTIONS "" )
185
- get_property (SRC_COMPILE_OPTIONS TARGET ${IN_TRGT} PROPERTY COMPILE_OPTIONS )
186
-
187
- # compile lang flags
188
- set (SRC_LANG_FLAGS_TMP ${CMAKE_${LINKER_LANGUAGE}_FLAGS_${CMAKE_BUILD_TYPE}} )
189
- if (SRC_LANG_FLAGS_TMP STREQUAL "" )
190
- set (SRC_LANG_FLAGS_TMP ${CMAKE_${LINKER_LANGUAGE}_FLAGS} )
191
- endif ()
192
-
193
- # this transforms the string to a list and gets rid of the double quotes
194
- # when assembling the command arguments
195
- string (REPLACE " " ";" SRC_LANG_FLAGS "${SRC_LANG_FLAGS_TMP} " )
321
+ ExtractCompileOptionProperties (IN_COMPILE_OPTIONS ${IN_TRGT} )
196
322
197
323
# compile flags
198
- # deprecated according to cmake docs
199
- get_property (SRC_FLAGS_TMP TARGET ${IN_TRGT} PROPERTY COMPILE_FLAGS )
200
-
201
- # this transforms the string to a list and gets rid of the double quotes
202
- # when assembling the command arguments
203
- string (REPLACE " " ";" SRC_FLAGS "${SRC_FLAGS_TMP} " )
324
+ ExtractCompileFlags (IN_COMPILE_FLAGS ${IN_TRGT} )
204
325
205
- # includes
206
- set (SRC_INCLUDES "" )
207
-
208
- get_property (INC_DIRS TARGET ${IN_TRGT} PROPERTY INCLUDE_DIRECTORIES )
209
- foreach (DIR ${INC_DIRS} )
210
- list (APPEND SRC_INCLUDES -I${DIR} )
211
- endforeach ()
212
-
213
- get_property (INC_DIRS TARGET ${IN_TRGT} PROPERTY INTERFACE_INCLUDE_DIRECTORIES )
214
- foreach (DIR ${INC_DIRS} )
215
- list (APPEND SRC_INCLUDES -I${DIR} )
216
- endforeach ()
217
-
218
- list (REMOVE_DUPLICATES SRC_INCLUDES )
326
+ # compile lang flags
327
+ ExtractLangFlags (IN_LANG_FLAGS ${LINKER_LANGUAGE} )
219
328
220
329
## main operations
221
330
foreach (IN_FILE ${IN_FILES} )
@@ -225,29 +334,21 @@ function(attach_llvmir_bc_target OUT_TRGT IN_TRGT)
225
334
set (FULL_OUT_LLVMIR_FILE "${WORK_DIR} /${OUT_LLVMIR_FILE} " )
226
335
227
336
# compile definitions per source file
228
- set (SRC_FILE_DEFS "" )
229
-
230
- get_property (SRC_DEFS_TMP SOURCE ${INFILE} PROPERTY COMPILE_DEFINITIONS )
231
- foreach (DEF ${SRC_DEFS_TMP} )
232
- list (APPEND SRC_FILE_DEFS -D${DEF} )
233
- endforeach ()
234
-
235
- get_property (SRC_DEFS_TMP SOURCE ${IN_TRGT} PROPERTY
236
- COMPILE_DEFINITIONS_${CMAKE_BUILD_TYPE} )
237
- foreach (DEF ${SRC_DEFS_TMP} )
238
- list (APPEND SRC_FILE_DEFS -D${DEF} )
239
- endforeach ()
337
+ ExtractCompileDefsProperties (IN_FILE_DEFS ${IN_FILE} )
240
338
241
339
# compile flags per source file
242
- get_property (SRC_FLAGS_TMP SOURCE ${INFILE} PROPERTY COMPILE_FLAGS )
243
-
244
- # this transforms the string to a list and gets rid of the double quotes
245
- # when assembling the command arguments
246
- string (REPLACE " " ";" SRC_FILE_FLAGS "${SRC_FLAGS_TMP} " )
340
+ ExtractCompileFlags (IN_FILE_COMPILE_FLAGS ${IN_FILE} )
247
341
248
342
# stitch all args together
249
- set (CMD_ARGS -emit-llvm ${SRC_LANG_FLAGS} ${SRC_FLAGS} ${SRC_COMPILE_OPTIONS}
250
- ${SRC_FILE_FLAGS} ${SRC_FILE_DEFS} ${SRC_DEFS} ${SRC_INCLUDES} )
343
+ catuniq (CURRENT_DEFS ${IN_DEFS} ${IN_FILE_DEFS} )
344
+ debug ("@attach_llvmir_bc_target ${IN_TRGT} defs: ${CURRENT_DEFS} " )
345
+
346
+ catuniq (CURRENT_COMPILE_FLAGS ${IN_COMPILE_FLAGS} ${IN_FILE_COMPILE_FLAGS} )
347
+ debug ("@attach_llvmir_bc_target ${IN_TRGT} compile flags: \
348
+ ${CURRENT_COMPILE_FLAGS} " )
349
+
350
+ set (CMD_ARGS "-emit-llvm" ${IN_LANG_FLAGS} ${IN_COMPILE_OPTIONS}
351
+ ${CURRENT_COMPILE_FLAGS} ${CURRENT_DEFS} ${IN_INCLUDES} )
251
352
252
353
add_custom_command (OUTPUT ${FULL_OUT_LLVMIR_FILE}
253
354
COMMAND ${LLVMIR_COMPILER}
0 commit comments