2012-12-19 12:33:39 +00:00
|
|
|
include(AddLLVM)
|
2014-05-09 22:11:03 +00:00
|
|
|
include(ExternalProject)
|
2013-01-18 16:05:21 +00:00
|
|
|
include(CompilerRTUtils)
|
2012-12-19 12:33:39 +00:00
|
|
|
|
2015-06-10 23:55:07 +00:00
|
|
|
# Tries to add an "object library" target for a given list of OSs and/or
|
|
|
|
# architectures with name "<name>.<arch>" for non-Darwin platforms if
|
|
|
|
# architecture can be targeted, and "<name>.<os>" for Darwin platforms.
|
|
|
|
# add_compiler_rt_object_libraries(<name>
|
2015-06-19 03:39:24 +00:00
|
|
|
# OS <os names>
|
|
|
|
# ARCHS <architectures>
|
2015-06-10 23:55:07 +00:00
|
|
|
# SOURCES <source files>
|
|
|
|
# CFLAGS <compile flags>
|
|
|
|
# DEFS <compile definitions>)
|
|
|
|
function(add_compiler_rt_object_libraries name)
|
2015-06-19 03:39:24 +00:00
|
|
|
cmake_parse_arguments(LIB "" "" "OS;ARCHS;SOURCES;CFLAGS;DEFS" ${ARGN})
|
2015-06-10 23:55:07 +00:00
|
|
|
set(libnames)
|
|
|
|
if(APPLE)
|
|
|
|
foreach(os ${LIB_OS})
|
|
|
|
set(libname "${name}.${os}")
|
|
|
|
set(libnames ${libnames} ${libname})
|
|
|
|
set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS})
|
|
|
|
endforeach()
|
2013-01-18 16:05:21 +00:00
|
|
|
else()
|
2015-06-19 03:39:24 +00:00
|
|
|
foreach(arch ${LIB_ARCHS})
|
2015-06-10 23:55:07 +00:00
|
|
|
set(libname "${name}.${arch}")
|
|
|
|
set(libnames ${libnames} ${libname})
|
|
|
|
set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS})
|
|
|
|
if(NOT CAN_TARGET_${arch})
|
2015-08-10 18:26:29 +00:00
|
|
|
message(FATAL_ERROR "Architecture ${arch} can't be targeted")
|
2015-06-10 23:55:07 +00:00
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2013-01-18 16:05:21 +00:00
|
|
|
endif()
|
2015-06-10 23:55:07 +00:00
|
|
|
|
|
|
|
foreach(libname ${libnames})
|
|
|
|
add_library(${libname} OBJECT ${LIB_SOURCES})
|
|
|
|
set_target_compile_flags(${libname}
|
|
|
|
${CMAKE_CXX_FLAGS} ${extra_cflags_${libname}} ${LIB_CFLAGS})
|
|
|
|
set_property(TARGET ${libname} APPEND PROPERTY
|
|
|
|
COMPILE_DEFINITIONS ${LIB_DEFS})
|
|
|
|
if(APPLE)
|
2015-06-19 03:39:24 +00:00
|
|
|
set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCHS}")
|
2015-06-10 23:55:07 +00:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|
2013-01-20 14:36:12 +00:00
|
|
|
|
2014-03-31 13:45:36 +00:00
|
|
|
# Adds static or shared runtime for a given architecture and puts it in the
|
|
|
|
# proper directory in the build and install trees.
|
|
|
|
# add_compiler_rt_runtime(<name> <arch> {STATIC,SHARED}
|
|
|
|
# SOURCES <source files>
|
|
|
|
# CFLAGS <compile flags>
|
2014-09-29 13:18:55 +00:00
|
|
|
# DEFS <compile definitions>
|
|
|
|
# OUTPUT_NAME <output library name>)
|
2014-03-31 13:45:36 +00:00
|
|
|
macro(add_compiler_rt_runtime name arch type)
|
2013-01-20 13:58:10 +00:00
|
|
|
if(CAN_TARGET_${arch})
|
2015-06-19 03:39:24 +00:00
|
|
|
cmake_parse_arguments(LIB "" "OUTPUT_NAME" "SOURCES;CFLAGS;LINKFLAGS;DEFS" ${ARGN})
|
2014-03-31 13:45:36 +00:00
|
|
|
add_library(${name} ${type} ${LIB_SOURCES})
|
2013-01-20 13:58:10 +00:00
|
|
|
# Setup compile flags and definitions.
|
|
|
|
set_target_compile_flags(${name}
|
|
|
|
${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
|
2014-10-29 19:25:20 +00:00
|
|
|
set_target_link_flags(${name}
|
2015-05-05 20:13:39 +00:00
|
|
|
${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS} ${LIB_LINKFLAGS})
|
2013-01-20 13:58:10 +00:00
|
|
|
set_property(TARGET ${name} APPEND PROPERTY
|
|
|
|
COMPILE_DEFINITIONS ${LIB_DEFS})
|
|
|
|
# Setup correct output directory in the build tree.
|
|
|
|
set_target_properties(${name} PROPERTIES
|
2014-03-31 13:45:36 +00:00
|
|
|
ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
|
2014-12-04 21:01:49 +00:00
|
|
|
LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
|
2014-09-29 13:18:55 +00:00
|
|
|
if ("${LIB_OUTPUT_NAME}" STREQUAL "")
|
|
|
|
set_target_properties(${name} PROPERTIES
|
|
|
|
OUTPUT_NAME ${name}${COMPILER_RT_OS_SUFFIX})
|
|
|
|
else()
|
2014-04-01 13:16:30 +00:00
|
|
|
set_target_properties(${name} PROPERTIES
|
|
|
|
OUTPUT_NAME ${LIB_OUTPUT_NAME})
|
|
|
|
endif()
|
2013-01-20 13:58:10 +00:00
|
|
|
# Add installation command.
|
|
|
|
install(TARGETS ${name}
|
2014-03-31 13:45:36 +00:00
|
|
|
ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
|
2014-12-04 21:01:49 +00:00
|
|
|
LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
|
|
|
|
RUNTIME DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
|
2013-01-20 13:58:10 +00:00
|
|
|
else()
|
2015-08-10 18:26:29 +00:00
|
|
|
message(FATAL_ERROR "Architecture ${arch} can't be targeted")
|
2013-01-20 13:58:10 +00:00
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2014-03-31 13:45:36 +00:00
|
|
|
# Same as add_compiler_rt_runtime(... STATIC), but creates a universal library
|
2013-01-21 08:12:20 +00:00
|
|
|
# for several architectures.
|
2015-06-19 03:39:24 +00:00
|
|
|
# add_compiler_rt_osx_static_runtime(<name> ARCHS <architectures>
|
2013-01-21 08:12:20 +00:00
|
|
|
# SOURCES <source files>
|
|
|
|
# CFLAGS <compile flags>
|
|
|
|
# DEFS <compile definitions>)
|
|
|
|
macro(add_compiler_rt_osx_static_runtime name)
|
2015-06-19 03:39:24 +00:00
|
|
|
cmake_parse_arguments(LIB "" "" "ARCHS;SOURCES;CFLAGS;DEFS" ${ARGN})
|
2013-01-21 08:12:20 +00:00
|
|
|
add_library(${name} STATIC ${LIB_SOURCES})
|
|
|
|
set_target_compile_flags(${name} ${LIB_CFLAGS})
|
|
|
|
set_property(TARGET ${name} APPEND PROPERTY
|
|
|
|
COMPILE_DEFINITIONS ${LIB_DEFS})
|
|
|
|
set_target_properties(${name} PROPERTIES
|
2015-06-19 03:39:24 +00:00
|
|
|
OSX_ARCHITECTURES "${LIB_ARCHS}"
|
2013-01-21 08:12:20 +00:00
|
|
|
ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
|
|
|
|
install(TARGETS ${name}
|
|
|
|
ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
|
|
|
|
endmacro()
|
|
|
|
|
2013-11-07 10:08:19 +00:00
|
|
|
# Adds dynamic runtime library on osx/iossim, which supports multiple
|
|
|
|
# architectures.
|
|
|
|
# add_compiler_rt_darwin_dynamic_runtime(<name> <os>
|
2015-06-19 03:39:24 +00:00
|
|
|
# ARCHS <architectures>
|
2013-11-07 10:08:19 +00:00
|
|
|
# SOURCES <source files>
|
|
|
|
# CFLAGS <compile flags>
|
|
|
|
# DEFS <compile definitions>
|
|
|
|
# LINKFLAGS <link flags>)
|
|
|
|
macro(add_compiler_rt_darwin_dynamic_runtime name os)
|
2015-06-19 03:39:24 +00:00
|
|
|
cmake_parse_arguments(LIB "" "" "ARCHS;SOURCES;CFLAGS;DEFS;LINKFLAGS" ${ARGN})
|
2013-01-21 08:12:20 +00:00
|
|
|
add_library(${name} SHARED ${LIB_SOURCES})
|
2013-11-07 10:08:19 +00:00
|
|
|
set_target_compile_flags(${name} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS})
|
|
|
|
set_target_link_flags(${name} ${LIB_LINKFLAGS} ${DARWIN_${os}_LINKFLAGS})
|
2013-01-21 08:12:20 +00:00
|
|
|
set_property(TARGET ${name} APPEND PROPERTY
|
|
|
|
COMPILE_DEFINITIONS ${LIB_DEFS})
|
|
|
|
set_target_properties(${name} PROPERTIES
|
2015-06-19 03:39:24 +00:00
|
|
|
OSX_ARCHITECTURES "${LIB_ARCHS}"
|
2013-01-21 08:12:20 +00:00
|
|
|
LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
|
|
|
|
install(TARGETS ${name}
|
|
|
|
LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
|
|
|
|
endmacro()
|
|
|
|
|
2014-05-30 12:42:57 +00:00
|
|
|
set(COMPILER_RT_TEST_CFLAGS)
|
|
|
|
|
2013-01-18 16:05:21 +00:00
|
|
|
# Unittests support.
|
2012-12-19 12:33:39 +00:00
|
|
|
set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest)
|
2013-11-15 10:21:15 +00:00
|
|
|
set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/src/gtest-all.cc)
|
2014-03-24 13:29:20 +00:00
|
|
|
set(COMPILER_RT_GTEST_CFLAGS
|
2012-12-19 12:33:39 +00:00
|
|
|
-DGTEST_NO_LLVM_RAW_OSTREAM=1
|
2014-05-28 08:38:13 +00:00
|
|
|
-DGTEST_HAS_RTTI=0
|
2012-12-19 12:33:39 +00:00
|
|
|
-I${COMPILER_RT_GTEST_PATH}/include
|
2013-11-15 10:21:15 +00:00
|
|
|
-I${COMPILER_RT_GTEST_PATH}
|
2012-12-19 12:33:39 +00:00
|
|
|
)
|
|
|
|
|
2015-01-06 20:58:40 +00:00
|
|
|
append_list_if(COMPILER_RT_DEBUG -DSANITIZER_DEBUG=1 COMPILER_RT_TEST_CFLAGS)
|
|
|
|
|
2014-05-28 08:38:13 +00:00
|
|
|
if(MSVC)
|
2014-05-30 12:42:57 +00:00
|
|
|
# clang doesn't support exceptions on Windows yet.
|
2015-01-06 20:58:40 +00:00
|
|
|
list(APPEND COMPILER_RT_TEST_CFLAGS -D_HAS_EXCEPTIONS=0)
|
2014-05-30 12:42:57 +00:00
|
|
|
|
|
|
|
# We should teach clang to understand "#pragma intrinsic", see PR19898.
|
|
|
|
list(APPEND COMPILER_RT_TEST_CFLAGS -Wno-undefined-inline)
|
|
|
|
|
2014-05-28 08:38:13 +00:00
|
|
|
# Clang doesn't support SEH on Windows yet.
|
|
|
|
list(APPEND COMPILER_RT_GTEST_CFLAGS -DGTEST_HAS_SEH=0)
|
2014-05-30 12:42:57 +00:00
|
|
|
|
|
|
|
# gtest use a lot of stuff marked as deprecated on Windows.
|
|
|
|
list(APPEND COMPILER_RT_GTEST_CFLAGS -Wno-deprecated-declarations)
|
2014-09-15 11:33:50 +00:00
|
|
|
|
|
|
|
# Visual Studio 2012 only supports up to 8 template parameters in
|
|
|
|
# std::tr1::tuple by default, but gtest requires 10
|
|
|
|
if(MSVC_VERSION EQUAL 1700)
|
2014-09-25 20:42:49 +00:00
|
|
|
list(APPEND COMPILER_RT_GTEST_CFLAGS -D_VARIADIC_MAX=10)
|
2014-09-15 11:33:50 +00:00
|
|
|
endif()
|
2014-05-28 08:38:13 +00:00
|
|
|
endif()
|
|
|
|
|
2014-02-19 13:01:03 +00:00
|
|
|
# Link objects into a single executable with COMPILER_RT_TEST_COMPILER,
|
|
|
|
# using specified link flags. Make executable a part of provided
|
2012-12-19 12:33:39 +00:00
|
|
|
# test_suite.
|
|
|
|
# add_compiler_rt_test(<test_suite> <test_name>
|
2014-12-17 23:14:01 +00:00
|
|
|
# SUBDIR <subdirectory for binary>
|
2012-12-19 12:33:39 +00:00
|
|
|
# OBJECTS <object files>
|
|
|
|
# DEPS <deps (e.g. runtime libs)>
|
|
|
|
# LINK_FLAGS <link flags>)
|
|
|
|
macro(add_compiler_rt_test test_suite test_name)
|
2015-06-19 03:39:24 +00:00
|
|
|
cmake_parse_arguments(TEST "" "SUBDIR" "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN})
|
2014-12-17 23:14:01 +00:00
|
|
|
if(TEST_SUBDIR)
|
|
|
|
set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${TEST_SUBDIR}/${test_name}")
|
|
|
|
else()
|
|
|
|
set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}")
|
|
|
|
endif()
|
2015-01-22 14:54:22 +00:00
|
|
|
if(MSVC)
|
|
|
|
set(output_bin "${output_bin}.exe")
|
|
|
|
endif()
|
2014-02-19 13:01:03 +00:00
|
|
|
# Use host compiler in a standalone build, and just-built Clang otherwise.
|
|
|
|
if(NOT COMPILER_RT_STANDALONE_BUILD)
|
|
|
|
list(APPEND TEST_DEPS clang)
|
|
|
|
endif()
|
2014-05-15 16:33:58 +00:00
|
|
|
# If we're not on MSVC, include the linker flags from CMAKE but override them
|
|
|
|
# with the provided link flags. This ensures that flags which are required to
|
|
|
|
# link programs at all are included, but the changes needed for the test
|
|
|
|
# trump. With MSVC we can't do that because CMake is set up to run link.exe
|
|
|
|
# when linking, not the compiler. Here, we hack it to use the compiler
|
|
|
|
# because we want to use -fsanitize flags.
|
|
|
|
if(NOT MSVC)
|
|
|
|
set(TEST_LINK_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TEST_LINK_FLAGS}")
|
|
|
|
separate_arguments(TEST_LINK_FLAGS)
|
|
|
|
endif()
|
2013-01-28 09:07:30 +00:00
|
|
|
add_custom_target(${test_name}
|
2014-05-12 08:55:20 +00:00
|
|
|
COMMAND ${COMPILER_RT_TEST_COMPILER} ${TEST_OBJECTS}
|
2014-05-28 08:38:13 +00:00
|
|
|
-o "${output_bin}"
|
2012-12-19 12:33:39 +00:00
|
|
|
${TEST_LINK_FLAGS}
|
2014-02-19 13:01:03 +00:00
|
|
|
DEPENDS ${TEST_DEPS})
|
2012-12-19 12:33:39 +00:00
|
|
|
# Make the test suite depend on the binary.
|
|
|
|
add_dependencies(${test_suite} ${test_name})
|
|
|
|
endmacro()
|
2013-05-21 13:48:27 +00:00
|
|
|
|
|
|
|
macro(add_compiler_rt_resource_file target_name file_name)
|
|
|
|
set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}")
|
2014-02-18 14:28:53 +00:00
|
|
|
set(dst_file "${COMPILER_RT_OUTPUT_DIR}/${file_name}")
|
2014-02-27 07:22:59 +00:00
|
|
|
add_custom_command(OUTPUT ${dst_file}
|
|
|
|
DEPENDS ${src_file}
|
2013-05-21 13:48:27 +00:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file}
|
2014-02-27 07:22:59 +00:00
|
|
|
COMMENT "Copying ${file_name}...")
|
|
|
|
add_custom_target(${target_name} DEPENDS ${dst_file})
|
2013-05-21 13:48:27 +00:00
|
|
|
# Install in Clang resource directory.
|
2014-02-18 14:28:53 +00:00
|
|
|
install(FILES ${file_name} DESTINATION ${COMPILER_RT_INSTALL_PATH})
|
2013-05-21 13:48:27 +00:00
|
|
|
endmacro()
|
2014-02-27 08:41:40 +00:00
|
|
|
|
|
|
|
macro(add_compiler_rt_script name)
|
|
|
|
set(dst ${COMPILER_RT_EXEC_OUTPUT_DIR}/${name})
|
|
|
|
set(src ${CMAKE_CURRENT_SOURCE_DIR}/${name})
|
|
|
|
add_custom_command(OUTPUT ${dst}
|
|
|
|
DEPENDS ${src}
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src} ${dst}
|
|
|
|
COMMENT "Copying ${name}...")
|
|
|
|
add_custom_target(${name} DEPENDS ${dst})
|
|
|
|
install(FILES ${dst}
|
|
|
|
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
|
|
|
|
DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin)
|
|
|
|
endmacro(add_compiler_rt_script src name)
|
2014-05-09 22:11:03 +00:00
|
|
|
|
|
|
|
# Builds custom version of libc++ and installs it in <prefix>.
|
|
|
|
# Can be used to build sanitized versions of libc++ for running unit tests.
|
|
|
|
# add_custom_libcxx(<name> <prefix>
|
|
|
|
# DEPS <list of build deps>
|
|
|
|
# CFLAGS <list of compile flags>)
|
|
|
|
macro(add_custom_libcxx name prefix)
|
|
|
|
if(NOT COMPILER_RT_HAS_LIBCXX_SOURCES)
|
|
|
|
message(FATAL_ERROR "libcxx not found!")
|
|
|
|
endif()
|
|
|
|
|
2015-06-19 03:39:24 +00:00
|
|
|
cmake_parse_arguments(LIBCXX "" "" "DEPS;CFLAGS" ${ARGN})
|
2014-05-09 22:11:03 +00:00
|
|
|
foreach(flag ${LIBCXX_CFLAGS})
|
|
|
|
set(flagstr "${flagstr} ${flag}")
|
|
|
|
endforeach()
|
|
|
|
set(LIBCXX_CFLAGS ${flagstr})
|
|
|
|
|
|
|
|
if(NOT COMPILER_RT_STANDALONE_BUILD)
|
|
|
|
list(APPEND LIBCXX_DEPS clang)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
ExternalProject_Add(${name}
|
|
|
|
PREFIX ${prefix}
|
|
|
|
SOURCE_DIR ${COMPILER_RT_LIBCXX_PATH}
|
|
|
|
CMAKE_ARGS -DCMAKE_C_COMPILER=${COMPILER_RT_TEST_COMPILER}
|
|
|
|
-DCMAKE_CXX_COMPILER=${COMPILER_RT_TEST_COMPILER}
|
|
|
|
-DCMAKE_C_FLAGS=${LIBCXX_CFLAGS}
|
|
|
|
-DCMAKE_CXX_FLAGS=${LIBCXX_CFLAGS}
|
|
|
|
-DCMAKE_BUILD_TYPE=Release
|
|
|
|
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
|
2014-05-12 21:07:28 +00:00
|
|
|
LOG_BUILD 1
|
|
|
|
LOG_CONFIGURE 1
|
|
|
|
LOG_INSTALL 1
|
2014-05-09 22:11:03 +00:00
|
|
|
)
|
2015-07-16 21:20:05 +00:00
|
|
|
set_target_properties(${name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
2014-05-09 22:11:03 +00:00
|
|
|
|
|
|
|
ExternalProject_Add_Step(${name} force-reconfigure
|
|
|
|
DEPENDERS configure
|
|
|
|
ALWAYS 1
|
|
|
|
)
|
|
|
|
|
|
|
|
ExternalProject_Add_Step(${name} clobber
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E remove_directory <BINARY_DIR>
|
|
|
|
COMMAND ${CMAKE_COMMAND} -E make_directory <BINARY_DIR>
|
|
|
|
COMMENT "Clobberring ${name} build directory..."
|
|
|
|
DEPENDERS configure
|
|
|
|
DEPENDS ${LIBCXX_DEPS}
|
|
|
|
)
|
|
|
|
endmacro()
|