summaryrefslogtreecommitdiffstats
path: root/lib/libcxx/cmake/Modules
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2016-09-03 18:39:32 +0000
committerpatrick <patrick@openbsd.org>2016-09-03 18:39:32 +0000
commitfe1ccca2776129541f1c4f645e4d1de89a22a031 (patch)
tree8e4fd7a09a5a15a9498fd2d88dcddbd40e999c79 /lib/libcxx/cmake/Modules
parentFixed missing null check in switchctl.c (diff)
downloadwireguard-openbsd-fe1ccca2776129541f1c4f645e4d1de89a22a031.tar.xz
wireguard-openbsd-fe1ccca2776129541f1c4f645e4d1de89a22a031.zip
Import libc++ 3.9.0
Diffstat (limited to 'lib/libcxx/cmake/Modules')
-rw-r--r--lib/libcxx/cmake/Modules/CheckLibcxxAtomic.cmake41
-rw-r--r--lib/libcxx/cmake/Modules/CodeCoverage.cmake36
-rw-r--r--lib/libcxx/cmake/Modules/HandleLibCXXABI.cmake110
-rw-r--r--lib/libcxx/cmake/Modules/HandleLibcxxFlags.cmake194
-rw-r--r--lib/libcxx/cmake/Modules/HandleOutOfTreeLLVM.cmake130
-rw-r--r--lib/libcxx/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake18
6 files changed, 529 insertions, 0 deletions
diff --git a/lib/libcxx/cmake/Modules/CheckLibcxxAtomic.cmake b/lib/libcxx/cmake/Modules/CheckLibcxxAtomic.cmake
new file mode 100644
index 00000000000..4ff343236fe
--- /dev/null
+++ b/lib/libcxx/cmake/Modules/CheckLibcxxAtomic.cmake
@@ -0,0 +1,41 @@
+INCLUDE(CheckCXXSourceCompiles)
+
+# Sometimes linking against libatomic is required for atomic ops, if
+# the platform doesn't support lock-free atomics.
+#
+# We could modify LLVM's CheckAtomic module and have it check for 64-bit
+# atomics instead. However, we would like to avoid careless uses of 64-bit
+# atomics inside LLVM over time on 32-bit platforms.
+
+function(check_cxx_atomics varname)
+ set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
+ set(CMAKE_REQUIRED_FLAGS "-std=c++11 -nostdinc++ -isystem ${LIBCXX_SOURCE_DIR}/include")
+ if (${LIBCXX_GCC_TOOLCHAIN})
+ set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} --gcc-toolchain=${LIBCXX_GCC_TOOLCHAIN}")
+ endif()
+ check_cxx_source_compiles("
+#include <cstdint>
+#include <atomic>
+std::atomic<uintptr_t> x;
+std::atomic<uintmax_t> y;
+int main() {
+ return x + y;
+}
+" ${varname})
+ set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
+endfunction(check_cxx_atomics)
+
+check_cxx_atomics(LIBCXX_HAVE_CXX_ATOMICS_WITHOUT_LIB)
+check_library_exists(atomic __atomic_fetch_add_8 "" LIBCXX_HAS_ATOMIC_LIB)
+# If not, check if the library exists, and atomics work with it.
+if(NOT LIBCXX_HAVE_CXX_ATOMICS_WITHOUT_LIB)
+ if(LIBCXX_HAS_ATOMIC_LIB)
+ list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
+ check_cxx_atomics(LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB)
+ if (NOT LIBCXX_HAVE_CXX_ATOMICS_WITH_LIB)
+ message(WARNING "Host compiler must support std::atomic!")
+ endif()
+ else()
+ message(WARNING "Host compiler appears to require libatomic, but cannot find it.")
+ endif()
+endif()
diff --git a/lib/libcxx/cmake/Modules/CodeCoverage.cmake b/lib/libcxx/cmake/Modules/CodeCoverage.cmake
new file mode 100644
index 00000000000..addd10abdfe
--- /dev/null
+++ b/lib/libcxx/cmake/Modules/CodeCoverage.cmake
@@ -0,0 +1,36 @@
+find_program(CODE_COVERAGE_LCOV lcov)
+if (NOT CODE_COVERAGE_LCOV)
+ message(FATAL_ERROR "Cannot find lcov...")
+endif()
+
+find_program(CODE_COVERAGE_GENHTML genhtml)
+if (NOT CODE_COVERAGE_GENHTML)
+ message(FATAL_ERROR "Cannot find genhtml...")
+endif()
+
+set(CMAKE_CXX_FLAGS_COVERAGE "-g -O0 --coverage")
+
+function(setup_lcov_test_target_coverage target_name output_dir capture_dirs source_dirs)
+ file(MAKE_DIRECTORY ${output_dir})
+
+ set(CAPTURE_DIRS "")
+ foreach(cdir ${capture_dirs})
+ list(APPEND CAPTURE_DIRS "-d;${cdir}")
+ endforeach()
+
+ set(EXTRACT_DIRS "")
+ foreach(sdir ${source_dirs})
+ list(APPEND EXTRACT_DIRS "'${sdir}/*'")
+ endforeach()
+
+ message(STATUS "Capture Directories: ${CAPTURE_DIRS}")
+ message(STATUS "Extract Directories: ${EXTRACT_DIRS}")
+
+ add_custom_target(generate-lib${target_name}-coverage
+ COMMAND ${CODE_COVERAGE_LCOV} --capture ${CAPTURE_DIRS} -o test_coverage.info
+ COMMAND ${CODE_COVERAGE_LCOV} --extract test_coverage.info ${EXTRACT_DIRS} -o test_coverage.info
+ COMMAND ${CODE_COVERAGE_GENHTML} --demangle-cpp test_coverage.info -o test_coverage
+ COMMAND ${CMAKE_COMMAND} -E remove test_coverage.info
+ WORKING_DIRECTORY ${output_dir}
+ COMMENT "Generating coverage results")
+endfunction()
diff --git a/lib/libcxx/cmake/Modules/HandleLibCXXABI.cmake b/lib/libcxx/cmake/Modules/HandleLibCXXABI.cmake
new file mode 100644
index 00000000000..c655adff718
--- /dev/null
+++ b/lib/libcxx/cmake/Modules/HandleLibCXXABI.cmake
@@ -0,0 +1,110 @@
+
+#===============================================================================
+# Add an ABI library if appropriate
+#===============================================================================
+
+#
+# _setup_abi: Set up the build to use an ABI library
+#
+# Parameters:
+# abidefines: A list of defines needed to compile libc++ with the ABI library
+# abilib : The ABI library to link against.
+# abifiles : A list of files (which may be relative paths) to copy into the
+# libc++ build tree for the build. These files will also be
+# installed alongside the libc++ headers.
+# abidirs : A list of relative paths to create under an include directory
+# in the libc++ build directory.
+#
+macro(setup_abi_lib abidefines abilib abifiles abidirs)
+ list(APPEND LIBCXX_COMPILE_FLAGS ${abidefines})
+ set(LIBCXX_CXX_ABI_INCLUDE_PATHS "${LIBCXX_CXX_ABI_INCLUDE_PATHS}"
+ CACHE PATH
+ "Paths to C++ ABI header directories separated by ';'." FORCE
+ )
+ set(LIBCXX_CXX_ABI_LIBRARY_PATH "${LIBCXX_CXX_ABI_LIBRARY_PATH}"
+ CACHE PATH
+ "Paths to C++ ABI library directory"
+ )
+ set(LIBCXX_CXX_ABI_LIBRARY ${abilib})
+ set(LIBCXX_ABILIB_FILES ${abifiles})
+
+ file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include")
+ foreach(_d ${abidirs})
+ file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include/${_d}")
+ endforeach()
+
+ foreach(fpath ${LIBCXX_ABILIB_FILES})
+ set(found FALSE)
+ foreach(incpath ${LIBCXX_CXX_ABI_INCLUDE_PATHS})
+ if (EXISTS "${incpath}/${fpath}")
+ set(found TRUE)
+ get_filename_component(dstdir ${fpath} PATH)
+ get_filename_component(ifile ${fpath} NAME)
+ file(COPY "${incpath}/${fpath}"
+ DESTINATION "${CMAKE_BINARY_DIR}/include/${dstdir}"
+ )
+ if (LIBCXX_INSTALL_HEADERS)
+ install(FILES "${CMAKE_BINARY_DIR}/include/${fpath}"
+ DESTINATION include/c++/v1/${dstdir}
+ COMPONENT libcxx
+ PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
+ )
+ endif()
+ list(APPEND abilib_headers "${CMAKE_BINARY_DIR}/include/${fpath}")
+ endif()
+ endforeach()
+ if (NOT found)
+ message(WARNING "Failed to find ${fpath}")
+ endif()
+ endforeach()
+
+ add_custom_target(LIBCXX_CXX_ABI_DEPS DEPENDS ${abilib_headers})
+ include_directories("${CMAKE_BINARY_DIR}/include")
+
+endmacro()
+
+
+# Configure based on the selected ABI library.
+if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR
+ "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++")
+ set(_LIBSUPCXX_INCLUDE_FILES
+ cxxabi.h bits/c++config.h bits/os_defines.h bits/cpu_defines.h
+ bits/cxxabi_tweaks.h bits/cxxabi_forced.h
+ )
+ if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++")
+ set(_LIBSUPCXX_DEFINES "-DLIBSTDCXX")
+ set(_LIBSUPCXX_LIBNAME stdc++)
+ else()
+ set(_LIBSUPCXX_DEFINES "")
+ set(_LIBSUPCXX_LIBNAME supc++)
+ endif()
+ setup_abi_lib(
+ "-D__GLIBCXX__ ${_LIBSUPCXX_DEFINES}"
+ "${_LIBSUPCXX_LIBNAME}" "${_LIBSUPCXX_INCLUDE_FILES}" "bits"
+ )
+elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxabi")
+ if (LIBCXX_CXX_ABI_INTREE)
+ # Link against just-built "cxxabi" target.
+ if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY)
+ set(CXXABI_LIBNAME cxxabi_static)
+ else()
+ set(CXXABI_LIBNAME cxxabi_shared)
+ endif()
+ set(LIBCXX_LIBCPPABI_VERSION "2" PARENT_SCOPE)
+ else()
+ # Assume c++abi is installed in the system, rely on -lc++abi link flag.
+ set(CXXABI_LIBNAME "c++abi")
+ endif()
+ setup_abi_lib("-DLIBCXX_BUILDING_LIBCXXABI"
+ ${CXXABI_LIBNAME} "cxxabi.h;__cxxabi_config.h" ""
+ )
+elseif ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libcxxrt")
+ setup_abi_lib("-DLIBCXXRT"
+ "cxxrt" "cxxabi.h;unwind.h;unwind-arm.h;unwind-itanium.h" ""
+ )
+elseif (NOT "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "none")
+ message(FATAL_ERROR
+ "Currently libstdc++, libsupc++, libcxxabi, libcxxrt and none are "
+ "supported for c++ abi."
+ )
+endif ()
diff --git a/lib/libcxx/cmake/Modules/HandleLibcxxFlags.cmake b/lib/libcxx/cmake/Modules/HandleLibcxxFlags.cmake
new file mode 100644
index 00000000000..325c1bdf7bc
--- /dev/null
+++ b/lib/libcxx/cmake/Modules/HandleLibcxxFlags.cmake
@@ -0,0 +1,194 @@
+# HandleLibcxxFlags - A set of macros used to setup the flags used to compile
+# and link libc++. These macros add flags to the following CMake variables.
+# - LIBCXX_COMPILE_FLAGS: flags used to compile libc++
+# - LIBCXX_LINK_FLAGS: flags used to link libc++
+# - LIBCXX_LIBRARIES: libraries to link libc++ to.
+
+include(CheckCXXCompilerFlag)
+
+unset(add_flag_if_supported)
+
+# Mangle the name of a compiler flag into a valid CMake identifier.
+# Ex: --std=c++11 -> STD_EQ_CXX11
+macro(mangle_name str output)
+ string(STRIP "${str}" strippedStr)
+ string(REGEX REPLACE "^/" "" strippedStr "${strippedStr}")
+ string(REGEX REPLACE "^-+" "" strippedStr "${strippedStr}")
+ string(REGEX REPLACE "-+$" "" strippedStr "${strippedStr}")
+ string(REPLACE "-" "_" strippedStr "${strippedStr}")
+ string(REPLACE "=" "_EQ_" strippedStr "${strippedStr}")
+ string(REPLACE "+" "X" strippedStr "${strippedStr}")
+ string(TOUPPER "${strippedStr}" ${output})
+endmacro()
+
+# Remove a list of flags from all CMake variables that affect compile flags.
+# This can be used to remove unwanted flags specified on the command line
+# or added in other parts of LLVM's cmake configuration.
+macro(remove_flags)
+ foreach(var ${ARGN})
+ string(REPLACE "${var}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
+ string(REPLACE "${var}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
+ string(REPLACE "${var}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}")
+ string(REPLACE "${var}" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
+ string(REPLACE "${var}" "" CMAKE_SHARED_MODULE_FLAGS "${CMAKE_SHARED_MODULE_FLAGS}")
+ remove_definitions(${var})
+ endforeach()
+endmacro(remove_flags)
+
+macro(check_flag_supported flag)
+ mangle_name("${flag}" flagname)
+ check_cxx_compiler_flag("${flag}" "LIBCXX_SUPPORTS_${flagname}_FLAG")
+endmacro()
+
+# Add a macro definition if condition is true.
+macro(define_if condition def)
+ if (${condition})
+ add_definitions(${def})
+ endif()
+endmacro()
+
+# Add a macro definition if condition is not true.
+macro(define_if_not condition def)
+ if (NOT ${condition})
+ add_definitions(${def})
+ endif()
+endmacro()
+
+# Add a macro definition to the __config_site file if the specified condition
+# is 'true'. Note that '-D${def}' is not added. Instead it is expected that
+# the build include the '__config_site' header.
+macro(config_define_if condition def)
+ if (${condition})
+ set(${def} ON)
+ set(LIBCXX_NEEDS_SITE_CONFIG ON)
+ endif()
+endmacro()
+
+macro(config_define_if_not condition def)
+ if (NOT ${condition})
+ set(${def} ON)
+ set(LIBCXX_NEEDS_SITE_CONFIG ON)
+ endif()
+endmacro()
+
+macro(config_define value def)
+ set(${def} ${value})
+ set(LIBCXX_NEEDS_SITE_CONFIG ON)
+endmacro()
+
+# Add a list of flags to all of 'CMAKE_CXX_FLAGS', 'CMAKE_C_FLAGS',
+# 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'.
+macro(add_target_flags)
+ foreach(value ${ARGN})
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${value}")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${value}")
+ list(APPEND LIBCXX_COMPILE_FLAGS ${value})
+ list(APPEND LIBCXX_LINK_FLAGS ${value})
+ endforeach()
+endmacro()
+
+# If the specified 'condition' is true then add a list of flags to
+# all of 'CMAKE_CXX_FLAGS', 'CMAKE_C_FLAGS', 'LIBCXX_COMPILE_FLAGS'
+# and 'LIBCXX_LINK_FLAGS'.
+macro(add_target_flags_if condition)
+ if (${condition})
+ add_target_flags(${ARGN})
+ endif()
+endmacro()
+
+# Add a specified list of flags to both 'LIBCXX_COMPILE_FLAGS' and
+# 'LIBCXX_LINK_FLAGS'.
+macro(add_flags)
+ foreach(value ${ARGN})
+ list(APPEND LIBCXX_COMPILE_FLAGS ${value})
+ list(APPEND LIBCXX_LINK_FLAGS ${value})
+ endforeach()
+endmacro()
+
+# If the specified 'condition' is true then add a list of flags to both
+# 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'.
+macro(add_flags_if condition)
+ if (${condition})
+ add_flags(${ARGN})
+ endif()
+endmacro()
+
+# Add each flag in the list to LIBCXX_COMPILE_FLAGS and LIBCXX_LINK_FLAGS
+# if that flag is supported by the current compiler.
+macro(add_flags_if_supported)
+ foreach(flag ${ARGN})
+ mangle_name("${flag}" flagname)
+ check_cxx_compiler_flag("${flag}" "LIBCXX_SUPPORTS_${flagname}_FLAG")
+ add_flags_if(LIBCXX_SUPPORTS_${flagname}_FLAG ${flag})
+ endforeach()
+endmacro()
+
+# Add a list of flags to 'LIBCXX_COMPILE_FLAGS'.
+macro(add_compile_flags)
+ foreach(f ${ARGN})
+ list(APPEND LIBCXX_COMPILE_FLAGS ${f})
+ endforeach()
+endmacro()
+
+# If 'condition' is true then add the specified list of flags to
+# 'LIBCXX_COMPILE_FLAGS'
+macro(add_compile_flags_if condition)
+ if (${condition})
+ add_compile_flags(${ARGN})
+ endif()
+endmacro()
+
+# For each specified flag, add that flag to 'LIBCXX_COMPILE_FLAGS' if the
+# flag is supported by the C++ compiler.
+macro(add_compile_flags_if_supported)
+ foreach(flag ${ARGN})
+ mangle_name("${flag}" flagname)
+ check_cxx_compiler_flag("${flag}" "LIBCXX_SUPPORTS_${flagname}_FLAG")
+ add_compile_flags_if(LIBCXX_SUPPORTS_${flagname}_FLAG ${flag})
+ endforeach()
+endmacro()
+
+# Add a list of flags to 'LIBCXX_LINK_FLAGS'.
+macro(add_link_flags)
+ foreach(f ${ARGN})
+ list(APPEND LIBCXX_LINK_FLAGS ${f})
+ endforeach()
+endmacro()
+
+# If 'condition' is true then add the specified list of flags to
+# 'LIBCXX_LINK_FLAGS'
+macro(add_link_flags_if condition)
+ if (${condition})
+ add_link_flags(${ARGN})
+ endif()
+endmacro()
+
+# For each specified flag, add that flag to 'LIBCXX_LINK_FLAGS' if the
+# flag is supported by the C++ compiler.
+macro(add_link_flags_if_supported)
+ foreach(flag ${ARGN})
+ mangle_name("${flag}" flagname)
+ check_cxx_compiler_flag("${flag}" "LIBCXX_SUPPORTS_${flagname}_FLAG")
+ add_link_flags_if(LIBCXX_SUPPORTS_${flagname}_FLAG ${flag})
+ endforeach()
+endmacro()
+
+# Add a list of libraries or link flags to 'LIBCXX_LIBRARIES'.
+macro(add_library_flags)
+ foreach(lib ${ARGN})
+ list(APPEND LIBCXX_LIBRARIES ${lib})
+ endforeach()
+endmacro()
+
+# if 'condition' is true then add the specified list of libraries and flags
+# to 'LIBCXX_LIBRARIES'.
+macro(add_library_flags_if condition)
+ if(${condition})
+ add_library_flags(${ARGN})
+ endif()
+endmacro()
+
+# Turn a comma separated CMake list into a space separated string.
+macro(split_list listname)
+ string(REPLACE ";" " " ${listname} "${${listname}}")
+endmacro()
diff --git a/lib/libcxx/cmake/Modules/HandleOutOfTreeLLVM.cmake b/lib/libcxx/cmake/Modules/HandleOutOfTreeLLVM.cmake
new file mode 100644
index 00000000000..9c5dd810926
--- /dev/null
+++ b/lib/libcxx/cmake/Modules/HandleOutOfTreeLLVM.cmake
@@ -0,0 +1,130 @@
+macro(find_llvm_parts)
+# Rely on llvm-config.
+ set(CONFIG_OUTPUT)
+ find_program(LLVM_CONFIG "llvm-config")
+ if(DEFINED LLVM_PATH)
+ set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIR} CACHE PATH "Path to llvm/include")
+ set(LLVM_PATH ${LLVM_PATH} CACHE PATH "Path to LLVM source tree")
+ set(LLVM_MAIN_SRC_DIR ${LLVM_PATH})
+ set(LLVM_CMAKE_PATH "${LLVM_PATH}/cmake/modules")
+ elseif(LLVM_CONFIG)
+ message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
+ set(CONFIG_COMMAND ${LLVM_CONFIG}
+ "--includedir"
+ "--prefix"
+ "--src-root")
+ execute_process(
+ COMMAND ${CONFIG_COMMAND}
+ RESULT_VARIABLE HAD_ERROR
+ OUTPUT_VARIABLE CONFIG_OUTPUT
+ )
+ if(NOT HAD_ERROR)
+ string(REGEX REPLACE
+ "[ \t]*[\r\n]+[ \t]*" ";"
+ CONFIG_OUTPUT ${CONFIG_OUTPUT})
+ else()
+ string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}")
+ message(STATUS "${CONFIG_COMMAND_STR}")
+ message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
+ endif()
+
+ list(GET CONFIG_OUTPUT 0 INCLUDE_DIR)
+ list(GET CONFIG_OUTPUT 1 LLVM_OBJ_ROOT)
+ list(GET CONFIG_OUTPUT 2 MAIN_SRC_DIR)
+
+ set(LLVM_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to llvm/include")
+ set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree")
+ set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
+ set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
+ else()
+ set(LLVM_FOUND OFF)
+ return()
+ endif()
+
+ if (NOT EXISTS ${LLVM_MAIN_SRC_DIR})
+ set(LLVM_FOUND OFF)
+ message(WARNING "Not found: ${LLVM_MAIN_SRC_DIR}")
+ return()
+ endif()
+
+ if(NOT EXISTS ${LLVM_CMAKE_PATH})
+ set(LLVM_FOUND OFF)
+ message(WARNING "Not found: ${LLVM_CMAKE_PATH}")
+ return()
+ endif()
+
+ list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
+ list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules")
+
+ set(LLVM_FOUND ON)
+endmacro(find_llvm_parts)
+
+
+if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+ set(LIBCXX_BUILT_STANDALONE 1)
+ message(STATUS "Configuring for standalone build.")
+
+ find_llvm_parts()
+
+ # LLVM Options --------------------------------------------------------------
+ include(FindPythonInterp)
+ if( NOT PYTHONINTERP_FOUND )
+ message(WARNING "Failed to find python interpreter. "
+ "The libc++ test suite will be disabled.")
+ set(LLVM_INCLUDE_TESTS OFF)
+ endif()
+
+ if (NOT DEFINED LLVM_INCLUDE_TESTS)
+ set(LLVM_INCLUDE_TESTS ${LLVM_FOUND})
+ endif()
+ if (NOT DEFINED LLVM_INCLUDE_DOCS)
+ set(LLVM_INCLUDE_DOCS ${LLVM_FOUND})
+ endif()
+ if (NOT DEFINED LLVM_ENABLE_SPHINX)
+ set(LLVM_ENABLE_SPHINX OFF)
+ endif()
+
+ # Required LIT Configuration ------------------------------------------------
+ # Define the default arguments to use with 'lit', and an option for the user
+ # to override.
+ set(LIT_ARGS_DEFAULT "-sv --show-xfail --show-unsupported")
+ if (MSVC OR XCODE)
+ set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
+ endif()
+ set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
+
+ # Required doc configuration
+ if (LLVM_ENABLE_SPHINX)
+ message(STATUS "Sphinx enabled.")
+ find_package(Sphinx REQUIRED)
+ else()
+ message(STATUS "Sphinx disabled.")
+ endif()
+
+ # FIXME - This is cribbed from HandleLLVMOptions.cmake.
+ if(WIN32)
+ set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
+ if(CYGWIN)
+ set(LLVM_ON_WIN32 0)
+ set(LLVM_ON_UNIX 1)
+ else(CYGWIN)
+ set(LLVM_ON_WIN32 1)
+ set(LLVM_ON_UNIX 0)
+ endif(CYGWIN)
+ else(WIN32)
+ if(UNIX)
+ set(LLVM_ON_WIN32 0)
+ set(LLVM_ON_UNIX 1)
+ if(APPLE)
+ set(LLVM_HAVE_LINK_VERSION_SCRIPT 0)
+ else(APPLE)
+ set(LLVM_HAVE_LINK_VERSION_SCRIPT 1)
+ endif(APPLE)
+ else(UNIX)
+ MESSAGE(SEND_ERROR "Unable to determine platform")
+ endif(UNIX)
+ endif(WIN32)
+
+ # Add LLVM Functions --------------------------------------------------------
+ include(AddLLVM OPTIONAL)
+endif()
diff --git a/lib/libcxx/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake b/lib/libcxx/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake
new file mode 100644
index 00000000000..a0669365bf9
--- /dev/null
+++ b/lib/libcxx/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake
@@ -0,0 +1,18 @@
+# MACRO_ENSURE_OUT_OF_SOURCE_BUILD(<errorMessage>)
+
+macro( MACRO_ENSURE_OUT_OF_SOURCE_BUILD _errorMessage )
+
+string( COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" _insource )
+if( _insource )
+ message( SEND_ERROR "${_errorMessage}" )
+ message( FATAL_ERROR
+ "In-source builds are not allowed.
+ CMake would overwrite the makefiles distributed with Compiler-RT.
+ Please create a directory and run cmake from there, passing the path
+ to this source directory as the last argument.
+ This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
+ Please delete them."
+ )
+endif( _insource )
+
+endmacro( MACRO_ENSURE_OUT_OF_SOURCE_BUILD )