@@ -228,6 +228,74 @@ function(set_output_directory target bindir libdir)
228
228
endif ()
229
229
endfunction ()
230
230
231
+ # If on Windows and building with MSVC, add the resource script containing the
232
+ # VERSIONINFO data to the project. This embeds version resource information
233
+ # into the output .exe or .dll.
234
+ # TODO: Enable for MinGW Windows builds too.
235
+ #
236
+ function (add_windows_version_resource_file OUT_VAR)
237
+ set (sources ${ARGN} )
238
+ if (MSVC )
239
+ set (resource_file ${LLVM_SOURCE_DIR} /resources/windows_version_resource.rc)
240
+ set (sources ${sources} ${resource_file} )
241
+ source_group ("Resource Files" ${resource_file} )
242
+ set (windows_resource_file ${resource_file} PARENT_SCOPE)
243
+ endif (MSVC )
244
+
245
+ set (${OUT_VAR} ${sources} PARENT_SCOPE)
246
+ endfunction (add_windows_version_resource_file)
247
+
248
+ # set_windows_version_resource_properties(name resource_file...
249
+ # VERSION_MAJOR int
250
+ # Optional major version number (defaults to LLVM_VERSION_MAJOR)
251
+ # VERSION_MINOR int
252
+ # Optional minor version number (defaults to LLVM_VERSION_MINOR)
253
+ # VERSION_PATCHLEVEL int
254
+ # Optional patchlevel version number (defaults to LLVM_VERSION_PATCH)
255
+ # VERSION_STRING
256
+ # Optional version string (defaults to PACKAGE_VERSION)
257
+ # PRODUCT_NAME
258
+ # Optional product name string (defaults to "LLVM")
259
+ # )
260
+ function (set_windows_version_resource_properties name resource_file)
261
+ cmake_parse_arguments (ARG
262
+ ""
263
+ "VERSION_MAJOR;VERSION_MINOR;VERSION_PATCHLEVEL;VERSION_STRING;PRODUCT_NAME"
264
+ ""
265
+ ${ARGN} )
266
+
267
+ if (NOT DEFINED ARG_VERSION_MAJOR)
268
+ set (ARG_VERSION_MAJOR ${LLVM_VERSION_MAJOR} )
269
+ endif ()
270
+
271
+ if (NOT DEFINED ARG_VERSION_MINOR)
272
+ set (ARG_VERSION_MINOR ${LLVM_VERSION_MINOR} )
273
+ endif ()
274
+
275
+ if (NOT DEFINED ARG_VERSION_PATCHLEVEL)
276
+ set (ARG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH} )
277
+ endif ()
278
+
279
+ if (NOT DEFINED ARG_VERSION_STRING)
280
+ set (ARG_VERSION_STRING ${PACKAGE_VERSION} )
281
+ endif ()
282
+
283
+ if (NOT DEFINED ARG_PRODUCT_NAME)
284
+ set (ARG_PRODUCT_NAME "LLVM" )
285
+ endif ()
286
+
287
+ set_property (SOURCE ${resource_file}
288
+ PROPERTY COMPILE_DEFINITIONS
289
+ "RC_VERSION_FIELD_1=${ARG_VERSION_MAJOR} "
290
+ "RC_VERSION_FIELD_2=${ARG_VERSION_MINOR} "
291
+ "RC_VERSION_FIELD_3=${ARG_VERSION_PATCHLEVEL} "
292
+ "RC_VERSION_FIELD_4=0"
293
+ "RC_FILE_VERSION=\" ${ARG_VERSION_STRING} \" "
294
+ "RC_INTERNAL_NAME=\" ${name} \" "
295
+ "RC_PRODUCT_NAME=\" ${ARG_PRODUCT_NAME} \" "
296
+ "RC_PRODUCT_VERSION=\" ${ARG_VERSION_STRING} \" " )
297
+ endfunction (set_windows_version_resource_properties)
298
+
231
299
# llvm_add_library(name sources...
232
300
# SHARED;STATIC
233
301
# STATIC by default w/o BUILD_SHARED_LIBS.
@@ -316,10 +384,17 @@ function(llvm_add_library name)
316
384
if (ARG_MODULE)
317
385
add_library (${name} MODULE ${ALL_FILES} )
318
386
elseif (ARG_SHARED)
387
+ add_windows_version_resource_file(ALL_FILES ${ALL_FILES} )
319
388
add_library (${name} SHARED ${ALL_FILES} )
320
389
else ()
321
390
add_library (${name} STATIC ${ALL_FILES} )
322
391
endif ()
392
+
393
+ if (DEFINED windows_resource_file)
394
+ set_windows_version_resource_properties(${name} ${windows_resource_file} )
395
+ set (windows_resource_file ${windows_resource_file} PARENT_SCOPE)
396
+ endif ()
397
+
323
398
set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR} )
324
399
llvm_update_compile_flags(${name} )
325
400
add_link_opts( ${name} )
@@ -482,11 +557,18 @@ endmacro(add_llvm_loadable_module name)
482
557
483
558
macro (add_llvm_executable name )
484
559
llvm_process_sources( ALL_FILES ${ARGN} )
560
+ add_windows_version_resource_file(ALL_FILES ${ALL_FILES} )
561
+
485
562
if ( EXCLUDE_FROM_ALL )
486
563
add_executable (${name} EXCLUDE_FROM_ALL ${ALL_FILES} )
487
564
else ()
488
565
add_executable (${name} ${ALL_FILES} )
489
566
endif ()
567
+
568
+ if (DEFINED windows_resource_file)
569
+ set_windows_version_resource_properties(${name} ${windows_resource_file} )
570
+ endif ()
571
+
490
572
llvm_update_compile_flags(${name} )
491
573
add_link_opts( ${name} )
492
574
0 commit comments