diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-06-21 13:59:01 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-06-21 13:59:01 +0000 |
commit | 3a0822f094b578157263e04114075ad7df81db41 (patch) | |
tree | bc48361fe2cd1ca5f93ac01b38b183774468fc79 /cmake/modules/AddLLVM.cmake | |
parent | 85d8b2bbe386bcfe669575d05b61482d7be07e5d (diff) |
Diffstat (limited to 'cmake/modules/AddLLVM.cmake')
-rwxr-xr-x | cmake/modules/AddLLVM.cmake | 101 |
1 files changed, 93 insertions, 8 deletions
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake index 85a09845b2ef..d80fcd71516e 100755 --- a/cmake/modules/AddLLVM.cmake +++ b/cmake/modules/AddLLVM.cmake @@ -1,4 +1,3 @@ -include(LLVMParseArguments) include(LLVMProcessSources) include(LLVM-Config) @@ -228,6 +227,78 @@ function(set_output_directory target bindir libdir) endif() endfunction() +# If on Windows and building with MSVC, add the resource script containing the +# VERSIONINFO data to the project. This embeds version resource information +# into the output .exe or .dll. +# TODO: Enable for MinGW Windows builds too. +# +function(add_windows_version_resource_file OUT_VAR) + set(sources ${ARGN}) + if (MSVC) + set(resource_file ${LLVM_SOURCE_DIR}/resources/windows_version_resource.rc) + if(EXISTS ${resource_file}) + set(sources ${sources} ${resource_file}) + source_group("Resource Files" ${resource_file}) + set(windows_resource_file ${resource_file} PARENT_SCOPE) + endif() + endif(MSVC) + + set(${OUT_VAR} ${sources} PARENT_SCOPE) +endfunction(add_windows_version_resource_file) + +# set_windows_version_resource_properties(name resource_file... +# VERSION_MAJOR int +# Optional major version number (defaults to LLVM_VERSION_MAJOR) +# VERSION_MINOR int +# Optional minor version number (defaults to LLVM_VERSION_MINOR) +# VERSION_PATCHLEVEL int +# Optional patchlevel version number (defaults to LLVM_VERSION_PATCH) +# VERSION_STRING +# Optional version string (defaults to PACKAGE_VERSION) +# PRODUCT_NAME +# Optional product name string (defaults to "LLVM") +# ) +function(set_windows_version_resource_properties name resource_file) + cmake_parse_arguments(ARG + "" + "VERSION_MAJOR;VERSION_MINOR;VERSION_PATCHLEVEL;VERSION_STRING;PRODUCT_NAME" + "" + ${ARGN}) + + if (NOT DEFINED ARG_VERSION_MAJOR) + set(ARG_VERSION_MAJOR ${LLVM_VERSION_MAJOR}) + endif() + + if (NOT DEFINED ARG_VERSION_MINOR) + set(ARG_VERSION_MINOR ${LLVM_VERSION_MINOR}) + endif() + + if (NOT DEFINED ARG_VERSION_PATCHLEVEL) + set(ARG_VERSION_PATCHLEVEL ${LLVM_VERSION_PATCH}) + endif() + + if (NOT DEFINED ARG_VERSION_STRING) + set(ARG_VERSION_STRING ${PACKAGE_VERSION}) + endif() + + if (NOT DEFINED ARG_PRODUCT_NAME) + set(ARG_PRODUCT_NAME "LLVM") + endif() + + set_property(SOURCE ${resource_file} + PROPERTY COMPILE_FLAGS /nologo) + set_property(SOURCE ${resource_file} + PROPERTY COMPILE_DEFINITIONS + "RC_VERSION_FIELD_1=${ARG_VERSION_MAJOR}" + "RC_VERSION_FIELD_2=${ARG_VERSION_MINOR}" + "RC_VERSION_FIELD_3=${ARG_VERSION_PATCHLEVEL}" + "RC_VERSION_FIELD_4=0" + "RC_FILE_VERSION=\"${ARG_VERSION_STRING}\"" + "RC_INTERNAL_NAME=\"${name}\"" + "RC_PRODUCT_NAME=\"${ARG_PRODUCT_NAME}\"" + "RC_PRODUCT_VERSION=\"${ARG_VERSION_STRING}\"") +endfunction(set_windows_version_resource_properties) + # llvm_add_library(name sources... # SHARED;STATIC # STATIC by default w/o BUILD_SHARED_LIBS. @@ -316,10 +387,17 @@ function(llvm_add_library name) if(ARG_MODULE) add_library(${name} MODULE ${ALL_FILES}) elseif(ARG_SHARED) + add_windows_version_resource_file(ALL_FILES ${ALL_FILES}) add_library(${name} SHARED ${ALL_FILES}) else() add_library(${name} STATIC ${ALL_FILES}) endif() + + if(DEFINED windows_resource_file) + set_windows_version_resource_properties(${name} ${windows_resource_file}) + set(windows_resource_file ${windows_resource_file} PARENT_SCOPE) + endif() + set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR}) llvm_update_compile_flags(${name}) add_link_opts( ${name} ) @@ -482,11 +560,18 @@ endmacro(add_llvm_loadable_module name) macro(add_llvm_executable name) llvm_process_sources( ALL_FILES ${ARGN} ) + add_windows_version_resource_file(ALL_FILES ${ALL_FILES}) + if( EXCLUDE_FROM_ALL ) add_executable(${name} EXCLUDE_FROM_ALL ${ALL_FILES}) else() add_executable(${name} ${ALL_FILES}) endif() + + if(DEFINED windows_resource_file) + set_windows_version_resource_properties(${name} ${windows_resource_file}) + endif() + llvm_update_compile_flags(${name}) add_link_opts( ${name} ) @@ -761,7 +846,7 @@ endfunction() # A raw function to create a lit target. This is used to implement the testuite # management functions. function(add_lit_target target comment) - parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN}) + cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN}) set(LIT_ARGS "${ARG_ARGS} ${LLVM_LIT_ARGS}") separate_arguments(LIT_ARGS) if (NOT CMAKE_CFG_INTDIR STREQUAL ".") @@ -776,9 +861,9 @@ function(add_lit_target target comment) foreach(param ${ARG_PARAMS}) list(APPEND LIT_COMMAND --param ${param}) endforeach() - if (ARG_DEFAULT_ARGS) + if (ARG_UNPARSED_ARGUMENTS) add_custom_target(${target} - COMMAND ${LIT_COMMAND} ${ARG_DEFAULT_ARGS} + COMMAND ${LIT_COMMAND} ${ARG_UNPARSED_ARGUMENTS} COMMENT "${comment}" ${cmake_3_2_USES_TERMINAL} ) @@ -797,12 +882,12 @@ endfunction() # A function to add a set of lit test suites to be driven through 'check-*' targets. function(add_lit_testsuite target comment) - parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN}) + cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN}) # EXCLUDE_FROM_ALL excludes the test ${target} out of check-all. if(NOT EXCLUDE_FROM_ALL) # Register the testsuites, params and depends for the global check rule. - set_property(GLOBAL APPEND PROPERTY LLVM_LIT_TESTSUITES ${ARG_DEFAULT_ARGS}) + set_property(GLOBAL APPEND PROPERTY LLVM_LIT_TESTSUITES ${ARG_UNPARSED_ARGUMENTS}) set_property(GLOBAL APPEND PROPERTY LLVM_LIT_PARAMS ${ARG_PARAMS}) set_property(GLOBAL APPEND PROPERTY LLVM_LIT_DEPENDS ${ARG_DEPENDS}) set_property(GLOBAL APPEND PROPERTY LLVM_LIT_EXTRA_ARGS ${ARG_ARGS}) @@ -810,7 +895,7 @@ function(add_lit_testsuite target comment) # Produce a specific suffixed check rule. add_lit_target(${target} ${comment} - ${ARG_DEFAULT_ARGS} + ${ARG_UNPARSED_ARGUMENTS} PARAMS ${ARG_PARAMS} DEPENDS ${ARG_DEPENDS} ARGS ${ARG_ARGS} @@ -819,7 +904,7 @@ endfunction() function(add_lit_testsuites project directory) if (NOT CMAKE_CONFIGURATION_TYPES) - parse_arguments(ARG "PARAMS;DEPENDS;ARGS" "" ${ARGN}) + cmake_parse_arguments(ARG "" "" "PARAMS;DEPENDS;ARGS" ${ARGN}) file(GLOB_RECURSE litCfg ${directory}/lit*.cfg) set(lit_suites) foreach(f ${litCfg}) |