aboutsummaryrefslogtreecommitdiffstats
path: root/cmake/modules
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/modules')
-rw-r--r--cmake/modules/AddLLVM.cmake101
-rw-r--r--cmake/modules/AddOCaml.cmake201
-rw-r--r--cmake/modules/CMakeLists.txt2
-rw-r--r--cmake/modules/CheckAtomic.cmake10
-rw-r--r--cmake/modules/FindOCaml.cmake103
-rw-r--r--cmake/modules/GetSVN.cmake80
-rw-r--r--cmake/modules/HandleLLVMOptions.cmake43
-rw-r--r--cmake/modules/LLVM-Config.cmake50
-rw-r--r--cmake/modules/LLVMConfig.cmake.in2
-rw-r--r--cmake/modules/LLVMProcessSources.cmake33
-rw-r--r--cmake/modules/Makefile3
11 files changed, 560 insertions, 68 deletions
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake
index bc26f06..7f63644 100644
--- a/cmake/modules/AddLLVM.cmake
+++ b/cmake/modules/AddLLVM.cmake
@@ -10,7 +10,7 @@ function(llvm_update_compile_flags name)
# LLVM_REQUIRES_EH is an internal flag that individual
# targets can use to force EH
- if(LLVM_REQUIRES_EH OR LLVM_ENABLE_EH)
+ if((LLVM_REQUIRES_EH OR LLVM_ENABLE_EH) AND NOT CLANG_CL)
if(NOT (LLVM_REQUIRES_RTTI OR LLVM_ENABLE_RTTI))
message(AUTHOR_WARNING "Exception handling requires RTTI. Enabling RTTI for ${name}")
set(LLVM_REQUIRES_RTTI ON)
@@ -22,6 +22,10 @@ function(llvm_update_compile_flags name)
list(APPEND LLVM_COMPILE_DEFINITIONS _HAS_EXCEPTIONS=0)
list(APPEND LLVM_COMPILE_FLAGS "/EHs-c-")
endif()
+ if (CLANG_CL)
+ # FIXME: Remove this once clang-cl supports SEH
+ list(APPEND LLVM_COMPILE_DEFINITIONS "GTEST_HAS_SEH=0")
+ endif()
endif()
# LLVM_REQUIRES_RTTI is an internal flag that individual
@@ -142,6 +146,17 @@ function(add_llvm_symbol_exports target_name export_file)
set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)
endfunction(add_llvm_symbol_exports)
+if(NOT WIN32 AND NOT APPLE)
+ execute_process(
+ COMMAND ${CMAKE_C_COMPILER} -Wl,--version
+ OUTPUT_VARIABLE stdout
+ ERROR_QUIET
+ )
+ if("${stdout}" MATCHES "GNU gold")
+ set(LLVM_LINKER_IS_GOLD ON)
+ endif()
+endif()
+
function(add_link_opts target_name)
# Pass -O3 to the linker. This enabled different optimizations on different
# linkers.
@@ -150,12 +165,20 @@ function(add_link_opts target_name)
LINK_FLAGS " -Wl,-O3")
endif()
+ if(LLVM_LINKER_IS_GOLD)
+ # With gold gc-sections is always safe.
+ set_property(TARGET ${target_name} APPEND_STRING PROPERTY
+ LINK_FLAGS " -Wl,--gc-sections")
+ # Note that there is a bug with -Wl,--icf=safe so it is not safe
+ # to enable. See https://sourceware.org/bugzilla/show_bug.cgi?id=17704.
+ endif()
+
if(NOT LLVM_NO_DEAD_STRIP)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# ld64's implementation of -dead_strip breaks tools that use plugins.
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-dead_strip")
- elseif(NOT WIN32)
+ elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD)
# Object files are compiled with -ffunction-data-sections.
# Versions of bfd ld < 2.23.1 have a bug in --gc-sections that breaks
# tools that use plugins. Always pass --gc-sections once we require
@@ -315,11 +338,11 @@ function(llvm_add_library name)
PREFIX ""
)
endif()
- if (MSVC)
- set_target_properties(${name}
- PROPERTIES
- IMPORT_SUFFIX ".imp")
- endif ()
+
+ set_target_properties(${name}
+ PROPERTIES
+ SOVERSION ${LLVM_VERSION_MAJOR}
+ VERSION ${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}${LLVM_VERSION_SUFFIX})
endif()
if(ARG_MODULE OR ARG_SHARED)
@@ -394,7 +417,16 @@ macro(add_llvm_library name)
EXPORT LLVMExports
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
+ ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}
+ COMPONENT ${name})
+
+ if (NOT CMAKE_CONFIGURATION_TYPES)
+ add_custom_target(install-${name}
+ DEPENDS ${name}
+ COMMAND "${CMAKE_COMMAND}"
+ -DCMAKE_INSTALL_COMPONENT=${name}
+ -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
+ endif()
endif()
set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name})
endif()
@@ -475,7 +507,16 @@ macro(add_llvm_tool name)
if( LLVM_BUILD_TOOLS )
install(TARGETS ${name}
EXPORT LLVMExports
- RUNTIME DESTINATION bin)
+ RUNTIME DESTINATION bin
+ COMPONENT ${name})
+
+ if (NOT CMAKE_CONFIGURATION_TYPES)
+ add_custom_target(install-${name}
+ DEPENDS ${name}
+ COMMAND "${CMAKE_COMMAND}"
+ -DCMAKE_INSTALL_COMPONENT=${name}
+ -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
+ endif()
endif()
endif()
if( LLVM_BUILD_TOOLS )
@@ -570,12 +611,6 @@ function(add_unittest test_suite test_name)
set(EXCLUDE_FROM_ALL ON)
endif()
- # Visual Studio 2012 only supports up to 8 template parameters in
- # std::tr1::tuple by default, but gtest requires 10
- if (MSVC AND MSVC_VERSION EQUAL 1700)
- list(APPEND LLVM_COMPILE_DEFINITIONS _VARIADIC_MAX=10)
- endif ()
-
include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include)
if (NOT LLVM_ENABLE_THREADS)
list(APPEND LLVM_COMPILE_DEFINITIONS GTEST_HAS_PTHREAD=0)
@@ -603,6 +638,36 @@ function(add_unittest test_suite test_name)
endif ()
endfunction()
+function(llvm_add_go_executable binary pkgpath)
+ cmake_parse_arguments(ARG "ALL" "" "DEPENDS;GOFLAGS" ${ARGN})
+
+ if(LLVM_BINDINGS MATCHES "go")
+ # FIXME: This should depend only on the libraries Go needs.
+ get_property(llvmlibs GLOBAL PROPERTY LLVM_LIBS)
+ set(binpath ${CMAKE_BINARY_DIR}/bin/${binary}${CMAKE_EXECUTABLE_SUFFIX})
+ set(cc "${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}")
+ set(cxx "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}")
+ set(cppflags "")
+ get_property(include_dirs DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
+ foreach(d ${include_dirs})
+ set(cppflags "${cppflags} -I${d}")
+ endforeach(d)
+ set(ldflags "${CMAKE_EXE_LINKER_FLAGS}")
+ add_custom_command(OUTPUT ${binpath}
+ COMMAND ${CMAKE_BINARY_DIR}/bin/llvm-go "cc=${cc}" "cxx=${cxx}" "cppflags=${cppflags}" "ldflags=${ldflags}"
+ ${ARG_GOFLAGS} build -o ${binpath} ${pkgpath}
+ DEPENDS llvm-config ${CMAKE_BINARY_DIR}/bin/llvm-go${CMAKE_EXECUTABLE_SUFFIX}
+ ${llvmlibs} ${ARG_DEPENDS}
+ COMMENT "Building Go executable ${binary}"
+ VERBATIM)
+ if (ARG_ALL)
+ add_custom_target(${binary} ALL DEPENDS ${binpath})
+ else()
+ add_custom_target(${binary} DEPENDS ${binpath})
+ endif()
+ endif()
+endfunction()
+
# This function provides an automatic way to 'configure'-like generate a file
# based on a set of common and custom variables, specifically targeting the
# variables needed for the 'lit.site.cfg' files. This function bundles the
@@ -675,18 +740,20 @@ function(add_lit_target target comment)
foreach(param ${ARG_PARAMS})
list(APPEND LIT_COMMAND --param ${param})
endforeach()
- if( ARG_DEPENDS )
+ if (ARG_DEFAULT_ARGS)
add_custom_target(${target}
COMMAND ${LIT_COMMAND} ${ARG_DEFAULT_ARGS}
COMMENT "${comment}"
${cmake_3_2_USES_TERMINAL}
)
- add_dependencies(${target} ${ARG_DEPENDS})
else()
add_custom_target(${target}
COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, no tools built.")
message(STATUS "${target} does nothing.")
endif()
+ if (ARG_DEPENDS)
+ add_dependencies(${target} ${ARG_DEPENDS})
+ endif()
# Tests should be excluded from "Build Solution".
set_target_properties(${target} PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD ON)
diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake
new file mode 100644
index 0000000..c58ac9c
--- /dev/null
+++ b/cmake/modules/AddOCaml.cmake
@@ -0,0 +1,201 @@
+# CMake build rules for the OCaml language.
+# Assumes FindOCaml is used.
+# http://ocaml.org/
+#
+# Example usage:
+#
+# add_ocaml_library(pkg_a OCAML mod_a OCAMLDEP pkg_b C mod_a_stubs PKG ctypes LLVM core)
+#
+# Unnamed parameters:
+#
+# * Library name.
+#
+# Named parameters:
+#
+# OCAML OCaml module names. Imply presence of a corresponding .ml and .mli files.
+# OCAMLDEP Names of libraries this library depends on.
+# C C stub sources. Imply presence of a corresponding .c file.
+# CFLAGS Additional arguments passed when compiling C stubs.
+# PKG Names of ocamlfind packages this library depends on.
+# LLVM Names of LLVM libraries this library depends on.
+# NOCOPY Do not automatically copy sources (.c, .ml, .mli) from the source directory,
+# e.g. if they are generated.
+#
+
+function(add_ocaml_library name)
+ CMAKE_PARSE_ARGUMENTS(ARG "NOCOPY" "" "OCAML;OCAMLDEP;C;CFLAGS;PKG;LLVM" ${ARGN})
+
+ set(src ${CMAKE_CURRENT_SOURCE_DIR})
+ set(bin ${CMAKE_CURRENT_BINARY_DIR})
+
+ set(ocaml_pkgs)
+ foreach( ocaml_pkg ${ARG_PKG} )
+ list(APPEND ocaml_pkgs "-package" "${ocaml_pkg}")
+ endforeach()
+
+ set(sources)
+
+ set(ocaml_inputs)
+
+ set(ocaml_outputs "${bin}/${name}.cma")
+ if( ARG_C )
+ list(APPEND ocaml_outputs
+ "${bin}/lib${name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
+ if ( BUILD_SHARED_LIBS )
+ list(APPEND ocaml_outputs
+ "${bin}/dll${name}${CMAKE_SHARED_LIBRARY_SUFFIX}")
+ endif()
+ endif()
+ if( HAVE_OCAMLOPT )
+ list(APPEND ocaml_outputs
+ "${bin}/${name}.cmxa"
+ "${bin}/${name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
+ endif()
+
+ set(ocaml_flags "-lstdc++" "-ldopt" "-L${LLVM_LIBRARY_DIR}"
+ "-ccopt" "-L\\$CAMLORIGIN/.."
+ "-ccopt" "-Wl,-rpath,\\$CAMLORIGIN/.."
+ ${ocaml_pkgs})
+
+ foreach( ocaml_dep ${ARG_OCAMLDEP} )
+ get_target_property(dep_ocaml_flags "ocaml_${ocaml_dep}" OCAML_FLAGS)
+ list(APPEND ocaml_flags ${dep_ocaml_flags})
+ endforeach()
+
+ if( NOT BUILD_SHARED_LIBS )
+ list(APPEND ocaml_flags "-custom")
+ endif()
+
+ explicit_map_components_to_libraries(llvm_libs ${ARG_LLVM})
+ foreach( llvm_lib ${llvm_libs} )
+ list(APPEND ocaml_flags "-l${llvm_lib}" )
+ endforeach()
+
+ get_property(system_libs TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS)
+ foreach(system_lib ${system_libs})
+ list(APPEND ocaml_flags "-l${system_lib}" )
+ endforeach()
+
+ string(REPLACE ";" " " ARG_CFLAGS "${ARG_CFLAGS}")
+ set(c_flags "${ARG_CFLAGS} ${LLVM_DEFINITIONS}")
+ foreach( include_dir ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR} )
+ set(c_flags "${c_flags} -I${include_dir}")
+ endforeach()
+
+ foreach( ocaml_file ${ARG_OCAML} )
+ list(APPEND sources "${ocaml_file}.mli" "${ocaml_file}.ml")
+
+ list(APPEND ocaml_inputs "${bin}/${ocaml_file}.mli" "${bin}/${ocaml_file}.ml")
+
+ list(APPEND ocaml_outputs "${bin}/${ocaml_file}.cmi" "${bin}/${ocaml_file}.cmo")
+ if( HAVE_OCAMLOPT )
+ list(APPEND ocaml_outputs
+ "${bin}/${ocaml_file}.cmx"
+ "${bin}/${ocaml_file}${CMAKE_C_OUTPUT_EXTENSION}")
+ endif()
+ endforeach()
+
+ foreach( c_file ${ARG_C} )
+ list(APPEND sources "${c_file}.c")
+
+ list(APPEND c_inputs "${bin}/${c_file}.c")
+ list(APPEND c_outputs "${bin}/${c_file}${CMAKE_C_OUTPUT_EXTENSION}")
+ endforeach()
+
+ if( NOT ARG_NOCOPY )
+ foreach( source ${sources} )
+ add_custom_command(
+ OUTPUT "${bin}/${source}"
+ COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${src}/${source}" "${bin}"
+ DEPENDS "${src}/${source}"
+ COMMENT "Copying ${source} to build area")
+ endforeach()
+ endif()
+
+ foreach( c_input ${c_inputs} )
+ get_filename_component(basename "${c_input}" NAME_WE)
+ add_custom_command(
+ OUTPUT "${basename}${CMAKE_C_OUTPUT_EXTENSION}"
+ COMMAND "${OCAMLFIND}" "ocamlc" "-c" "${c_input}" -ccopt ${c_flags}
+ DEPENDS "${c_input}"
+ COMMENT "Building OCaml stub object file ${basename}${CMAKE_C_OUTPUT_EXTENSION}"
+ VERBATIM)
+ endforeach()
+
+ set(ocaml_params)
+ foreach( ocaml_input ${ocaml_inputs} ${c_outputs})
+ get_filename_component(filename "${ocaml_input}" NAME)
+ list(APPEND ocaml_params "${filename}")
+ endforeach()
+
+ if( APPLE )
+ set(ocaml_rpath "@executable_path/../../lib")
+ elseif( UNIX )
+ set(ocaml_rpath "\\$ORIGIN/../../lib")
+ endif()
+ list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}")
+
+ add_custom_command(
+ OUTPUT ${ocaml_outputs}
+ COMMAND "${OCAMLFIND}" "ocamlmklib" "-o" "${name}" ${ocaml_flags} ${ocaml_params}
+ DEPENDS ${ocaml_inputs} ${c_outputs}
+ COMMENT "Building OCaml library ${name}"
+ VERBATIM)
+
+ add_custom_command(
+ OUTPUT "${bin}/${name}.odoc"
+ COMMAND "${OCAMLFIND}" "ocamldoc"
+ "-I" "${bin}"
+ "-I" "${LLVM_LIBRARY_DIR}/ocaml/"
+ "-dump" "${bin}/${name}.odoc"
+ ${ocaml_pkgs} ${ocaml_inputs}
+ DEPENDS ${ocaml_inputs}
+ COMMENT "Building OCaml documentation for ${name}"
+ VERBATIM)
+
+ add_custom_target("ocaml_${name}" ALL DEPENDS ${ocaml_outputs} "${bin}/${name}.odoc")
+
+ set_target_properties("ocaml_${name}" PROPERTIES
+ OCAML_FLAGS "-I;${bin}")
+ set_target_properties("ocaml_${name}" PROPERTIES
+ OCAML_ODOC "${bin}/${name}.odoc")
+
+ foreach( ocaml_dep ${ARG_OCAMLDEP} )
+ add_dependencies("ocaml_${name}" "ocaml_${ocaml_dep}")
+ endforeach()
+
+ foreach( llvm_lib ${llvm_libs} )
+ add_dependencies("ocaml_${name}" "${llvm_lib}")
+ endforeach()
+
+ set(install_files)
+ set(install_shlibs)
+ foreach( ocaml_output ${ocaml_outputs} )
+ get_filename_component(ext "${ocaml_output}" EXT)
+
+ if( NOT (ext STREQUAL ".cmo" OR
+ ext STREQUAL CMAKE_C_OUTPUT_EXTENSION OR
+ ext STREQUAL CMAKE_SHARED_LIBRARY_SUFFIX) )
+ list(APPEND install_files "${ocaml_output}")
+ elseif( ext STREQUAL CMAKE_SHARED_LIBRARY_SUFFIX)
+ list(APPEND install_shlibs "${ocaml_output}")
+ endif()
+ endforeach()
+
+ install(FILES ${install_files}
+ DESTINATION lib/ocaml)
+ install(FILES ${install_shlibs}
+ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ GROUP_READ GROUP_EXECUTE
+ WORLD_READ WORLD_EXECUTE
+ DESTINATION lib/ocaml)
+
+ foreach( install_file ${install_files} ${install_shlibs} )
+ get_filename_component(filename "${install_file}" NAME)
+ add_custom_command(TARGET "ocaml_${name}" POST_BUILD
+ COMMAND "${CMAKE_COMMAND}" "-E" "copy" "${install_file}"
+ "${LLVM_LIBRARY_DIR}/ocaml/"
+ COMMENT "Copying OCaml library component ${filename} to intermediate area"
+ VERBATIM)
+ endforeach()
+endfunction()
diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt
index c87193d..5f3f255 100644
--- a/cmake/modules/CMakeLists.txt
+++ b/cmake/modules/CMakeLists.txt
@@ -58,7 +58,7 @@ foreach(p ${_count})
get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)")
endforeach(p)
set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include")
-set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib")
+set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}")
set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin")
set(LLVM_CONFIG_EXPORTS_FILE "\${LLVM_CMAKE_DIR}/LLVMExports.cmake")
diff --git a/cmake/modules/CheckAtomic.cmake b/cmake/modules/CheckAtomic.cmake
index 2ed4819..30a5e31 100644
--- a/cmake/modules/CheckAtomic.cmake
+++ b/cmake/modules/CheckAtomic.cmake
@@ -2,9 +2,13 @@
INCLUDE(CheckCXXSourceCompiles)
-check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC)
-if (HAVE_LIBATOMIC)
- list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
+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")
+ endif()
endif()
CHECK_CXX_SOURCE_COMPILES("
diff --git a/cmake/modules/FindOCaml.cmake b/cmake/modules/FindOCaml.cmake
new file mode 100644
index 0000000..8eba212
--- /dev/null
+++ b/cmake/modules/FindOCaml.cmake
@@ -0,0 +1,103 @@
+# CMake find_package() module for the OCaml language.
+# Assumes ocamlfind will be used for compilation.
+# http://ocaml.org/
+#
+# Example usage:
+#
+# find_package(OCaml)
+#
+# If successful, the following variables will be defined:
+# OCAMLFIND
+# OCAML_VERSION
+# OCAML_STDLIB_PATH
+# HAVE_OCAMLOPT
+#
+# Also provides find_ocamlfind_package() macro.
+#
+# Example usage:
+#
+# find_ocamlfind_package(ctypes)
+#
+# In any case, the following variables are defined:
+#
+# HAVE_OCAML_${pkg}
+#
+# If successful, the following variables will be defined:
+#
+# OCAML_${pkg}_VERSION
+
+include( FindPackageHandleStandardArgs )
+
+find_program(OCAMLFIND
+ NAMES ocamlfind)
+
+if( OCAMLFIND )
+ execute_process(
+ COMMAND ${OCAMLFIND} ocamlc -version
+ OUTPUT_VARIABLE OCAML_VERSION
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ execute_process(
+ COMMAND ${OCAMLFIND} ocamlc -where
+ OUTPUT_VARIABLE OCAML_STDLIB_PATH
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ execute_process(
+ COMMAND ${OCAMLFIND} ocamlc -version
+ OUTPUT_QUIET
+ RESULT_VARIABLE find_ocaml_result)
+ if( find_ocaml_result EQUAL 0 )
+ set(HAVE_OCAMLOPT TRUE)
+ else()
+ set(HAVE_OCAMLOPT FALSE)
+ endif()
+endif()
+
+find_package_handle_standard_args( OCaml DEFAULT_MSG
+ OCAMLFIND
+ OCAML_VERSION
+ OCAML_STDLIB_PATH)
+
+mark_as_advanced(
+ OCAMLFIND)
+
+function(find_ocamlfind_package pkg)
+ CMAKE_PARSE_ARGUMENTS(ARG "OPTIONAL" "VERSION" "" ${ARGN})
+
+ execute_process(
+ COMMAND "${OCAMLFIND}" "query" "${pkg}" "-format" "%v"
+ RESULT_VARIABLE result
+ OUTPUT_VARIABLE version
+ ERROR_VARIABLE error
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_STRIP_TRAILING_WHITESPACE)
+
+ if( NOT result EQUAL 0 AND NOT ARG_OPTIONAL )
+ message(FATAL_ERROR ${error})
+ endif()
+
+ if( result EQUAL 0 )
+ set(found TRUE)
+ else()
+ set(found FALSE)
+ endif()
+
+ if( found AND ARG_VERSION )
+ if( version VERSION_LESS ARG_VERSION AND ARG_OPTIONAL )
+ # If it's optional and the constraint is not satisfied, pretend
+ # it wasn't found.
+ set(found FALSE)
+ elseif( version VERSION_LESS ARG_VERSION )
+ message(FATAL_ERROR
+ "ocamlfind package ${pkg} should have version ${ARG_VERSION} or newer")
+ endif()
+ endif()
+
+ string(TOUPPER ${pkg} pkg)
+
+ set(HAVE_OCAML_${pkg} ${found}
+ PARENT_SCOPE)
+
+ set(OCAML_${pkg}_VERSION ${version}
+ PARENT_SCOPE)
+endfunction()
diff --git a/cmake/modules/GetSVN.cmake b/cmake/modules/GetSVN.cmake
index 4e32c09..d512bd2 100644
--- a/cmake/modules/GetSVN.cmake
+++ b/cmake/modules/GetSVN.cmake
@@ -19,13 +19,83 @@ get_filename_component(LLVM_DIR "${LLVM_DIR}" PATH)
# Handle strange terminals
set(ENV{TERM} "dumb")
+macro(get_source_info_svn path revision repository)
+ # If svn is a bat file, find_program(Subversion) doesn't find it.
+ # Explicitly search for that here; Subversion_SVN_EXECUTABLE will override
+ # the find_program call in FindSubversion.cmake.
+ find_program(Subversion_SVN_EXECUTABLE NAMES svn svn.bat)
+
+ # FindSubversion does not work with symlinks. See PR 8437
+ if (NOT IS_SYMLINK "${path}")
+ find_package(Subversion)
+ endif()
+ if (Subversion_FOUND)
+ subversion_wc_info( ${path} Project )
+ if (Project_WC_REVISION)
+ set(${revision} ${Project_WC_REVISION} PARENT_SCOPE)
+ endif()
+ if (Project_WC_URL)
+ set(${repository} ${Project_WC_URL} PARENT_SCOPE)
+ endif()
+ endif()
+endmacro()
+
+macro(get_source_info_git_svn path revision repository)
+ find_program(git_executable NAMES git git.exe git.cmd)
+ if (git_executable)
+ execute_process(COMMAND ${git_executable} svn info
+ WORKING_DIRECTORY ${path}
+ TIMEOUT 5
+ RESULT_VARIABLE git_result
+ OUTPUT_VARIABLE git_output)
+ if (git_result EQUAL 0)
+ string(REGEX REPLACE "^(.*\n)?Revision: ([^\n]+).*"
+ "\\2" git_svn_rev "${git_output}")
+ set(${revision} ${git_svn_rev} PARENT_SCOPE)
+ string(REGEX REPLACE "^(.*\n)?URL: ([^\n]+).*"
+ "\\2" git_url "${git_output}")
+ set(${repository} ${git_url} PARENT_SCOPE)
+ endif()
+ endif()
+endmacro()
+
+macro(get_source_info_git path revision repository)
+ find_program(git_executable NAMES git git.exe git.cmd)
+ if (git_executable)
+ execute_process(COMMAND ${git_executable} log -1 --pretty=format:%H
+ WORKING_DIRECTORY ${path}
+ TIMEOUT 5
+ RESULT_VARIABLE git_result
+ OUTPUT_VARIABLE git_output)
+ if (git_result EQUAL 0)
+ set(${revision} ${git_output} PARENT_SCOPE)
+ endif()
+ execute_process(COMMAND ${git_executable} remote -v
+ WORKING_DIRECTORY ${path}
+ TIMEOUT 5
+ RESULT_VARIABLE git_result
+ OUTPUT_VARIABLE git_output)
+ if (git_result EQUAL 0)
+ string(REGEX REPLACE "^(.*\n)?[^ \t]+[ \t]+([^ \t\n]+)[ \t]+\\(fetch\\).*"
+ "\\2" git_url "${git_output}")
+ set(${repository} "${git_url}" PARENT_SCOPE)
+ endif()
+ endif()
+endmacro()
+
+function(get_source_info path revision repository)
+ if (EXISTS "${path}/.svn")
+ get_source_info_svn("${path}" revision repository)
+ elseif (EXISTS "${path}/.git/svn")
+ get_source_info_git_svn("${path}" revision repository)
+ elseif (EXISTS "${path}/.git")
+ get_source_info_git("${path}" revision repository)
+ endif()
+endfunction()
+
function(append_info name path)
- execute_process(COMMAND "${LLVM_DIR}/utils/GetSourceVersion" "${path}"
- OUTPUT_VARIABLE revision)
+ get_source_info("${path}" revision repository)
string(STRIP "${revision}" revision)
- execute_process(COMMAND "${LLVM_DIR}/utils/GetRepositoryPath" "${path}"
- OUTPUT_VARIABLE repository
- OUTPUT_STRIP_TRAILING_WHITESPACE)
string(STRIP "${repository}" repository)
file(APPEND "${HEADER_FILE}.txt"
"#define ${name}_REVISION \"${revision}\"\n")
diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake
index 6cc6d65..fdc4ea0 100644
--- a/cmake/modules/HandleLLVMOptions.cmake
+++ b/cmake/modules/HandleLLVMOptions.cmake
@@ -21,11 +21,16 @@ if(NOT LLVM_FORCE_USE_OLD_TOOLCHAIN)
message(FATAL_ERROR "Host Clang version must be at least 3.1!")
endif()
- # Also test that we aren't using too old of a version of libstdc++ with the
- # Clang compiler. This is tricky as there is no real way to check the
- # version of libstdc++ directly. Instead we test for a known bug in
- # libstdc++4.6 that is fixed in libstdc++4.7.
- if(NOT LLVM_ENABLE_LIBCXX)
+ if (CMAKE_CXX_SIMULATE_ID MATCHES "MSVC")
+ if (CMAKE_CXX_SIMULATE_VERSION VERSION_LESS 18.0)
+ message(FATAL_ERROR "Host Clang must have at least -fms-compatibility-version=18.0")
+ endif()
+ set(CLANG_CL 1)
+ elseif(NOT LLVM_ENABLE_LIBCXX)
+ # Otherwise, test that we aren't using too old of a version of libstdc++
+ # with the Clang compiler. This is tricky as there is no real way to
+ # check the version of libstdc++ directly. Instead we test for a known
+ # bug in libstdc++4.6 that is fixed in libstdc++4.7.
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
set(CMAKE_REQUIRED_FLAGS "-std=c++0x")
@@ -41,8 +46,11 @@ int main() { return (float)x; }"
set(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
- if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17.0)
- message(FATAL_ERROR "Host Visual Studio must be at least 2012 (MSVC 17.0)")
+ if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0)
+ message(FATAL_ERROR "Host Visual Studio must be at least 2013")
+ elseif(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0.31101)
+ message(WARNING "Host Visual Studio should at least be 2013 Update 4 (MSVC 18.0.31101)"
+ " due to miscompiles from earlier versions")
endif()
endif()
endif()
@@ -79,8 +87,6 @@ if(WIN32)
set(LLVM_ON_WIN32 1)
set(LLVM_ON_UNIX 0)
endif(CYGWIN)
- # Maximum path length is 160 for non-unicode paths
- set(MAXPATHLEN 160)
else(WIN32)
if(UNIX)
set(LLVM_ON_WIN32 0)
@@ -90,8 +96,6 @@ else(WIN32)
else(APPLE)
set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
endif(APPLE)
- # FIXME: Maximum path length is currently set to 'safe' fixed value
- set(MAXPATHLEN 2024)
else(UNIX)
MESSAGE(SEND_ERROR "Unable to determine platform")
endif(UNIX)
@@ -108,6 +112,15 @@ if(APPLE)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-flat_namespace -Wl,-undefined -Wl,suppress")
endif()
+# Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO
+# build might work on ELF but fail on MachO/COFF.
+if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32 OR
+ ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") AND
+ NOT LLVM_USE_SANITIZER)
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
+endif()
+
+
function(append value)
foreach(variable ${ARGN})
set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
@@ -399,12 +412,20 @@ if(LLVM_USE_SANITIZER)
elseif (LLVM_USE_SANITIZER STREQUAL "Thread")
append_common_sanitizer_flags()
append("-fsanitize=thread" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ elseif (LLVM_USE_SANITIZER STREQUAL "Address;Undefined" OR
+ LLVM_USE_SANITIZER STREQUAL "Undefined;Address")
+ append_common_sanitizer_flags()
+ append("-fsanitize=address,undefined -fno-sanitize=vptr,function -fno-sanitize-recover"
+ CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
else()
message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}")
endif()
else()
message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.")
endif()
+ if (LLVM_USE_SANITIZE_COVERAGE)
+ append("-fsanitize-coverage=4" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ endif()
endif()
# Turn on -gsplit-dwarf if requested
diff --git a/cmake/modules/LLVM-Config.cmake b/cmake/modules/LLVM-Config.cmake
index e8c42fc..b24c129 100644
--- a/cmake/modules/LLVM-Config.cmake
+++ b/cmake/modules/LLVM-Config.cmake
@@ -152,29 +152,39 @@ function(llvm_map_components_to_libnames out_libs)
set(${out_libs} ${expanded_components} PARENT_SCOPE)
endfunction()
+# Perform a post-order traversal of the dependency graph.
+# This duplicates the algorithm used by llvm-config, originally
+# in tools/llvm-config/llvm-config.cpp, function ComputeLibsForComponents.
+function(expand_topologically name required_libs visited_libs)
+ list(FIND visited_libs ${name} found)
+ if( found LESS 0 )
+ list(APPEND visited_libs ${name})
+ set(visited_libs ${visited_libs} PARENT_SCOPE)
+
+ get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${name})
+ foreach( lib_dep ${lib_deps} )
+ expand_topologically(${lib_dep} "${required_libs}" "${visited_libs}")
+ set(required_libs ${required_libs} PARENT_SCOPE)
+ set(visited_libs ${visited_libs} PARENT_SCOPE)
+ endforeach()
+
+ list(APPEND required_libs ${name})
+ set(required_libs ${required_libs} PARENT_SCOPE)
+ endif()
+endfunction()
+
# Expand dependencies while topologically sorting the list of libraries:
function(llvm_expand_dependencies out_libs)
set(expanded_components ${ARGN})
- list(LENGTH expanded_components lst_size)
- set(cursor 0)
- set(processed)
- while( cursor LESS lst_size )
- list(GET expanded_components ${cursor} lib)
- get_property(lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib})
- list(APPEND expanded_components ${lib_deps})
- # Remove duplicates at the front:
- list(REVERSE expanded_components)
- list(REMOVE_DUPLICATES expanded_components)
- list(REVERSE expanded_components)
- list(APPEND processed ${lib})
- # Find the maximum index that doesn't have to be re-processed:
- while(NOT "${expanded_components}" MATCHES "^${processed}.*" )
- list(REMOVE_AT processed -1)
- endwhile()
- list(LENGTH processed cursor)
- list(LENGTH expanded_components lst_size)
- endwhile( cursor LESS lst_size )
- set(${out_libs} ${expanded_components} PARENT_SCOPE)
+
+ set(required_libs)
+ set(visited_libs)
+ foreach( lib ${expanded_components} )
+ expand_topologically(${lib} "${required_libs}" "${visited_libs}")
+ endforeach()
+
+ list(REVERSE required_libs)
+ set(${out_libs} ${required_libs} PARENT_SCOPE)
endfunction()
function(explicit_map_components_to_libraries out_libs)
diff --git a/cmake/modules/LLVMConfig.cmake.in b/cmake/modules/LLVMConfig.cmake.in
index 780a608..9a9cd85 100644
--- a/cmake/modules/LLVMConfig.cmake.in
+++ b/cmake/modules/LLVMConfig.cmake.in
@@ -40,6 +40,8 @@ set(LLVM_ENABLE_PIC @LLVM_ENABLE_PIC@)
set(LLVM_ON_UNIX @LLVM_ON_UNIX@)
set(LLVM_ON_WIN32 @LLVM_ON_WIN32@)
+set(LLVM_LIBDIR_SUFFIX @LLVM_LIBDIR_SUFFIX@)
+
set(LLVM_INCLUDE_DIRS "@LLVM_CONFIG_INCLUDE_DIRS@")
set(LLVM_LIBRARY_DIRS "@LLVM_CONFIG_LIBRARY_DIRS@")
set(LLVM_DEFINITIONS "-D__STDC_LIMIT_MACROS" "-D__STDC_CONSTANT_MACROS")
diff --git a/cmake/modules/LLVMProcessSources.cmake b/cmake/modules/LLVMProcessSources.cmake
index 64ebce8..ae1921b 100644
--- a/cmake/modules/LLVMProcessSources.cmake
+++ b/cmake/modules/LLVMProcessSources.cmake
@@ -28,26 +28,39 @@ macro(add_td_sources srcs)
endif()
endmacro(add_td_sources)
+function(add_header_files_for_glob hdrs_out glob)
+ file(GLOB hds ${glob})
+ set(${hdrs_out} ${hds} PARENT_SCOPE)
+endfunction(add_header_files_for_glob)
-macro(add_header_files srcs)
- file(GLOB hds *.h)
- if( hds )
- set_source_files_properties(${hds} PROPERTIES HEADER_FILE_ONLY ON)
- list(APPEND ${srcs} ${hds})
- endif()
-endmacro(add_header_files)
+function(find_all_header_files hdrs_out additional_headerdirs)
+ add_header_files_for_glob(hds *.h)
+ list(APPEND all_headers ${hds})
+
+ foreach(additional_dir ${additional_headerdirs})
+ add_header_files_for_glob(hds "${additional_dir}/*.h")
+ list(APPEND all_headers ${hds})
+ add_header_files_for_glob(hds "${additional_dir}/*.inc")
+ list(APPEND all_headers ${hds})
+ endforeach(additional_dir)
+
+ set( ${hdrs_out} ${all_headers} PARENT_SCOPE )
+endfunction(find_all_header_files)
function(llvm_process_sources OUT_VAR)
- cmake_parse_arguments(ARG "" "" "ADDITIONAL_HEADERS" ${ARGN})
+ cmake_parse_arguments(ARG "" "" "ADDITIONAL_HEADERS;ADDITIONAL_HEADER_DIRS" ${ARGN})
set(sources ${ARG_UNPARSED_ARGUMENTS})
llvm_check_source_file_list( ${sources} )
if( MSVC_IDE OR XCODE )
# This adds .td and .h files to the Visual Studio solution:
add_td_sources(sources)
- add_header_files(sources)
+ find_all_header_files(hdrs "${ARG_ADDITIONAL_HEADER_DIRS}")
+ if (hdrs)
+ set_source_files_properties(${hdrs} PROPERTIES HEADER_FILE_ONLY ON)
+ endif()
set_source_files_properties(${ARG_ADDITIONAL_HEADERS} PROPERTIES HEADER_FILE_ONLY ON)
- list(APPEND sources ${ARG_ADDITIONAL_HEADERS})
+ list(APPEND sources ${ARG_ADDITIONAL_HEADERS} ${hdrs})
endif()
set( ${OUT_VAR} ${sources} PARENT_SCOPE )
diff --git a/cmake/modules/Makefile b/cmake/modules/Makefile
index dd31aa7..e38f5a6 100644
--- a/cmake/modules/Makefile
+++ b/cmake/modules/Makefile
@@ -48,7 +48,7 @@ endif
OBJMODS := LLVMConfig.cmake LLVMConfigVersion.cmake LLVMExports.cmake
-$(PROJ_OBJ_DIR)/LLVMConfig.cmake: LLVMConfig.cmake.in $(LLVMBuildCMakeFrag)
+$(PROJ_OBJ_DIR)/LLVMConfig.cmake: LLVMConfig.cmake.in Makefile $(LLVMBuildCMakeFrag)
$(Echo) 'Generating LLVM CMake package config file'
$(Verb) ( \
cat $< | sed \
@@ -73,6 +73,7 @@ $(PROJ_OBJ_DIR)/LLVMConfig.cmake: LLVMConfig.cmake.in $(LLVMBuildCMakeFrag)
-e 's/@LLVM_ENABLE_PIC@/'"$(ENABLE_PIC)"'/' \
-e 's/@LLVM_ON_UNIX@/'"$(LLVM_ON_UNIX)"'/' \
-e 's/@LLVM_ON_WIN32@/'"$(LLVM_ON_WIN32)"'/' \
+ -e 's/@LLVM_LIBDIR_SUFFIX@//' \
-e 's/@LLVM_CONFIG_INCLUDE_DIRS@/'"$(subst /,\/,$(PROJ_includedir))"'/' \
-e 's/@LLVM_CONFIG_LIBRARY_DIRS@/'"$(subst /,\/,$(PROJ_libdir))"'/' \
-e 's/@LLVM_CONFIG_CMAKE_DIR@/'"$(subst /,\/,$(PROJ_cmake))"'/' \