aboutsummaryrefslogtreecommitdiff
path: root/cmake/modules
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/modules')
-rwxr-xr-xcmake/modules/AddLLVM.cmake101
-rw-r--r--cmake/modules/CheckAtomic.cmake42
-rw-r--r--cmake/modules/LLVMParseArguments.cmake80
3 files changed, 129 insertions, 94 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})
diff --git a/cmake/modules/CheckAtomic.cmake b/cmake/modules/CheckAtomic.cmake
index a03788ec9f93..551de6ade84c 100644
--- a/cmake/modules/CheckAtomic.cmake
+++ b/cmake/modules/CheckAtomic.cmake
@@ -2,15 +2,45 @@
INCLUDE(CheckCXXSourceCompiles)
-check_function_exists(__atomic_fetch_add_4 HAVE___ATOMIC_FETCH_ADD_4)
-if( NOT HAVE___ATOMIC_FETCH_ADD_4 )
- check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC)
- set(HAVE_LIBATOMIC False)
- if( HAVE_LIBATOMIC )
- list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
+# Sometimes linking against libatomic is required for atomic ops, if
+# the platform doesn't support lock-free atomics.
+
+function(check_working_cxx_atomics varname)
+ set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
+ set(CMAKE_REQUIRED_FLAGS "-std=c++11")
+ CHECK_CXX_SOURCE_COMPILES("
+#include <atomic>
+std::atomic<int> x;
+int main() {
+ return x;
+}
+" ${varname})
+ set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
+endfunction(check_working_cxx_atomics)
+
+# This isn't necessary on MSVC, so avoid command-line switch annoyance
+# by only running on GCC-like hosts.
+if (LLVM_COMPILER_IS_GCC_COMPATIBLE)
+ # First check if atomics work without the library.
+ check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB)
+ # If not, check if the library exists, and atomics work with it.
+ if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
+ check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC)
+ if( HAVE_LIBATOMIC )
+ list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
+ check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB)
+ if (NOT HAVE_CXX_ATOMICS_WITH_LIB)
+ message(FATAL_ERROR "Host compiler must support std::atomic!")
+ endif()
+ else()
+ message(FATAL_ERROR "Host compiler appears to require libatomic, but cannot find it.")
+ endif()
endif()
endif()
+## TODO: This define is only used for the legacy atomic operations in
+## llvm's Atomic.h, which should be replaced. Other code simply
+## assumes C++11 <atomic> works.
CHECK_CXX_SOURCE_COMPILES("
#ifdef _MSC_VER
#include <Intrin.h> /* Workaround for PR19898. */
diff --git a/cmake/modules/LLVMParseArguments.cmake b/cmake/modules/LLVMParseArguments.cmake
deleted file mode 100644
index ce19be114b31..000000000000
--- a/cmake/modules/LLVMParseArguments.cmake
+++ /dev/null
@@ -1,80 +0,0 @@
-# Copied from http://www.itk.org/Wiki/CMakeMacroParseArguments under
-# http://creativecommons.org/licenses/by/2.5/.
-#
-# The PARSE_ARGUMENTS macro will take the arguments of another macro and define
-# several variables. The first argument to PARSE_ARGUMENTS is a prefix to put on
-# all variables it creates. The second argument is a list of names, and the
-# third argument is a list of options. Both of these lists should be quoted. The
-# rest of PARSE_ARGUMENTS are arguments from another macro to be parsed.
-#
-# PARSE_ARGUMENTS(prefix arg_names options arg1 arg2...)
-#
-# For each item in options, PARSE_ARGUMENTS will create a variable with that
-# name, prefixed with prefix_. So, for example, if prefix is MY_MACRO and
-# options is OPTION1;OPTION2, then PARSE_ARGUMENTS will create the variables
-# MY_MACRO_OPTION1 and MY_MACRO_OPTION2. These variables will be set to true if
-# the option exists in the command line or false otherwise.
-#
-#For each item in arg_names, PARSE_ARGUMENTS will create a variable with that
-#name, prefixed with prefix_. Each variable will be filled with the arguments
-#that occur after the given arg_name is encountered up to the next arg_name or
-#the end of the arguments. All options are removed from these
-#lists. PARSE_ARGUMENTS also creates a prefix_DEFAULT_ARGS variable containing
-#the list of all arguments up to the first arg_name encountered.
-#
-#Here is a simple, albeit impractical, example of using PARSE_ARGUMENTS that
-#demonstrates its behavior.
-#
-# SET(arguments
-# hello OPTION3 world
-# LIST3 foo bar
-# OPTION2
-# LIST1 fuz baz
-# )
-#
-# PARSE_ARGUMENTS(ARG "LIST1;LIST2;LIST3" "OPTION1;OPTION2;OPTION3" ${arguments})
-#
-# PARSE_ARGUMENTS creates 7 variables and sets them as follows:
-# ARG_DEFAULT_ARGS: hello;world
-# ARG_LIST1: fuz;baz
-# ARG_LIST2:
-# ARG_LIST3: foo;bar
-# ARG_OPTION1: FALSE
-# ARG_OPTION2: TRUE
-# ARG_OPTION3: TRUE
-#
-# If you don't have any options, use an empty string in its place.
-# PARSE_ARGUMENTS(ARG "LIST1;LIST2;LIST3" "" ${arguments})
-# Likewise if you have no lists.
-# PARSE_ARGUMENTS(ARG "" "OPTION1;OPTION2;OPTION3" ${arguments})
-
-MACRO(PARSE_ARGUMENTS prefix arg_names option_names)
- SET(DEFAULT_ARGS)
- FOREACH(arg_name ${arg_names})
- SET(${prefix}_${arg_name})
- ENDFOREACH(arg_name)
- FOREACH(option ${option_names})
- SET(${prefix}_${option} FALSE)
- ENDFOREACH(option)
-
- SET(current_arg_name DEFAULT_ARGS)
- SET(current_arg_list)
- FOREACH(arg ${ARGN})
- SET(larg_names ${arg_names})
- LIST(FIND larg_names "${arg}" is_arg_name)
- IF (is_arg_name GREATER -1)
- SET(${prefix}_${current_arg_name} ${current_arg_list})
- SET(current_arg_name ${arg})
- SET(current_arg_list)
- ELSE (is_arg_name GREATER -1)
- SET(loption_names ${option_names})
- LIST(FIND loption_names "${arg}" is_option)
- IF (is_option GREATER -1)
- SET(${prefix}_${arg} TRUE)
- ELSE (is_option GREATER -1)
- SET(current_arg_list ${current_arg_list} ${arg})
- ENDIF (is_option GREATER -1)
- ENDIF (is_arg_name GREATER -1)
- ENDFOREACH(arg)
- SET(${prefix}_${current_arg_name} ${current_arg_list})
-ENDMACRO(PARSE_ARGUMENTS)