2012-12-19 20:33:39 +08:00
|
|
|
include(AddLLVM)
|
2014-05-10 06:11:03 +08:00
|
|
|
include(ExternalProject)
|
2012-12-19 20:33:39 +08:00
|
|
|
include(LLVMParseArguments)
|
2013-01-19 00:05:21 +08:00
|
|
|
include(CompilerRTUtils)
|
2012-12-19 20:33:39 +08:00
|
|
|
|
2013-01-19 00:05:21 +08:00
|
|
|
# Tries to add "object library" target for a given architecture
|
|
|
|
# with name "<name>.<arch>" if architecture can be targeted.
|
|
|
|
# add_compiler_rt_object_library(<name> <arch>
|
|
|
|
# SOURCES <source files>
|
2013-09-16 23:50:53 +08:00
|
|
|
# CFLAGS <compile flags>
|
|
|
|
# DEFS <compile definitions>)
|
2013-01-19 00:05:21 +08:00
|
|
|
macro(add_compiler_rt_object_library name arch)
|
|
|
|
if(CAN_TARGET_${arch})
|
2013-09-16 23:50:53 +08:00
|
|
|
parse_arguments(LIB "SOURCES;CFLAGS;DEFS" "" ${ARGN})
|
2013-01-19 00:05:21 +08:00
|
|
|
add_library(${name}.${arch} OBJECT ${LIB_SOURCES})
|
|
|
|
set_target_compile_flags(${name}.${arch}
|
|
|
|
${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
|
2013-09-16 23:50:53 +08:00
|
|
|
set_property(TARGET ${name}.${arch} APPEND PROPERTY
|
|
|
|
COMPILE_DEFINITIONS ${LIB_DEFS})
|
2013-01-19 00:05:21 +08:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Archtecture ${arch} can't be targeted")
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2013-11-07 18:08:19 +08:00
|
|
|
# Same as above, but adds universal osx library for either OSX or iOS simulator
|
|
|
|
# with name "<name>.<os>" targeting multiple architectures.
|
|
|
|
# add_compiler_rt_darwin_object_library(<name> <os> ARCH <architectures>
|
|
|
|
# SOURCES <source files>
|
|
|
|
# CFLAGS <compile flags>
|
|
|
|
# DEFS <compile definitions>)
|
|
|
|
macro(add_compiler_rt_darwin_object_library name os)
|
2013-09-16 23:50:53 +08:00
|
|
|
parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN})
|
2013-11-07 18:08:19 +08:00
|
|
|
set(libname "${name}.${os}")
|
2013-01-20 22:36:12 +08:00
|
|
|
add_library(${libname} OBJECT ${LIB_SOURCES})
|
2013-11-07 18:08:19 +08:00
|
|
|
set_target_compile_flags(${libname} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS})
|
2013-01-21 16:12:20 +08:00
|
|
|
set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCH}")
|
2013-09-16 23:50:53 +08:00
|
|
|
set_property(TARGET ${libname} APPEND PROPERTY
|
|
|
|
COMPILE_DEFINITIONS ${LIB_DEFS})
|
2013-01-20 22:36:12 +08:00
|
|
|
endmacro()
|
|
|
|
|
2014-03-31 21:45:36 +08: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>
|
|
|
|
# DEFS <compile definitions>)
|
|
|
|
macro(add_compiler_rt_runtime name arch type)
|
2013-01-20 21:58:10 +08:00
|
|
|
if(CAN_TARGET_${arch})
|
2014-04-01 21:16:30 +08:00
|
|
|
parse_arguments(LIB "SOURCES;CFLAGS;DEFS;OUTPUT_NAME" "" ${ARGN})
|
2014-03-31 21:45:36 +08:00
|
|
|
add_library(${name} ${type} ${LIB_SOURCES})
|
2013-01-20 21:58:10 +08:00
|
|
|
# Setup compile flags and definitions.
|
|
|
|
set_target_compile_flags(${name}
|
|
|
|
${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
|
2014-03-31 21:45:36 +08:00
|
|
|
set_target_link_flags(${name}
|
|
|
|
${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})
|
2013-01-20 21:58:10 +08: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 21:45:36 +08:00
|
|
|
ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
|
2014-04-01 21:16:30 +08:00
|
|
|
if (LIB_OUTPUT_NAME)
|
|
|
|
set_target_properties(${name} PROPERTIES
|
|
|
|
OUTPUT_NAME ${LIB_OUTPUT_NAME})
|
|
|
|
endif()
|
2013-01-20 21:58:10 +08:00
|
|
|
# Add installation command.
|
|
|
|
install(TARGETS ${name}
|
2014-03-31 21:45:36 +08:00
|
|
|
ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
|
|
|
|
LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
|
2013-01-20 21:58:10 +08:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Archtecture ${arch} can't be targeted")
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2014-03-31 21:45:36 +08:00
|
|
|
# Same as add_compiler_rt_runtime(... STATIC), but creates a universal library
|
2013-01-21 16:12:20 +08:00
|
|
|
# for several architectures.
|
|
|
|
# add_compiler_rt_osx_static_runtime(<name> ARCH <architectures>
|
|
|
|
# SOURCES <source files>
|
|
|
|
# CFLAGS <compile flags>
|
|
|
|
# DEFS <compile definitions>)
|
|
|
|
macro(add_compiler_rt_osx_static_runtime name)
|
|
|
|
parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN})
|
|
|
|
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
|
|
|
|
OSX_ARCHITECTURES "${LIB_ARCH}"
|
|
|
|
ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
|
|
|
|
install(TARGETS ${name}
|
|
|
|
ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
|
|
|
|
endmacro()
|
|
|
|
|
2013-11-07 18:08:19 +08:00
|
|
|
# Adds dynamic runtime library on osx/iossim, which supports multiple
|
|
|
|
# architectures.
|
|
|
|
# add_compiler_rt_darwin_dynamic_runtime(<name> <os>
|
|
|
|
# ARCH <architectures>
|
|
|
|
# SOURCES <source files>
|
|
|
|
# CFLAGS <compile flags>
|
|
|
|
# DEFS <compile definitions>
|
|
|
|
# LINKFLAGS <link flags>)
|
|
|
|
macro(add_compiler_rt_darwin_dynamic_runtime name os)
|
2013-01-21 16:12:20 +08:00
|
|
|
parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS;LINKFLAGS" "" ${ARGN})
|
|
|
|
add_library(${name} SHARED ${LIB_SOURCES})
|
2013-11-07 18:08:19 +08:00
|
|
|
set_target_compile_flags(${name} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS})
|
|
|
|
set_target_link_flags(${name} ${LIB_LINKFLAGS} ${DARWIN_${os}_LINKFLAGS})
|
2013-01-21 16:12:20 +08:00
|
|
|
set_property(TARGET ${name} APPEND PROPERTY
|
|
|
|
COMPILE_DEFINITIONS ${LIB_DEFS})
|
|
|
|
set_target_properties(${name} PROPERTIES
|
|
|
|
OSX_ARCHITECTURES "${LIB_ARCH}"
|
|
|
|
LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
|
|
|
|
install(TARGETS ${name}
|
|
|
|
LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
|
|
|
|
endmacro()
|
|
|
|
|
2013-01-19 00:05:21 +08:00
|
|
|
# Unittests support.
|
2012-12-19 20:33:39 +08:00
|
|
|
set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest)
|
2013-11-15 18:21:15 +08:00
|
|
|
set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/src/gtest-all.cc)
|
2014-03-24 21:29:20 +08:00
|
|
|
set(COMPILER_RT_GTEST_CFLAGS
|
2012-12-19 20:33:39 +08:00
|
|
|
-DGTEST_NO_LLVM_RAW_OSTREAM=1
|
|
|
|
-I${COMPILER_RT_GTEST_PATH}/include
|
2013-11-15 18:21:15 +08:00
|
|
|
-I${COMPILER_RT_GTEST_PATH}
|
2012-12-19 20:33:39 +08:00
|
|
|
)
|
|
|
|
|
2014-02-19 21:01:03 +08: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 20:33:39 +08:00
|
|
|
# test_suite.
|
|
|
|
# add_compiler_rt_test(<test_suite> <test_name>
|
|
|
|
# OBJECTS <object files>
|
|
|
|
# DEPS <deps (e.g. runtime libs)>
|
|
|
|
# LINK_FLAGS <link flags>)
|
|
|
|
macro(add_compiler_rt_test test_suite test_name)
|
|
|
|
parse_arguments(TEST "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN})
|
2013-01-28 15:16:22 +08:00
|
|
|
set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${test_name}")
|
2014-02-19 21:01:03 +08: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()
|
2013-01-28 17:07:30 +08:00
|
|
|
add_custom_target(${test_name}
|
2014-02-19 21:01:03 +08:00
|
|
|
COMMAND ${COMPILER_RT_TEST_COMPILER} ${TEST_OBJECTS} -o "${output_bin}"
|
2012-12-19 20:33:39 +08:00
|
|
|
${TEST_LINK_FLAGS}
|
2014-02-19 21:01:03 +08:00
|
|
|
DEPENDS ${TEST_DEPS})
|
2012-12-19 20:33:39 +08:00
|
|
|
# Make the test suite depend on the binary.
|
|
|
|
add_dependencies(${test_suite} ${test_name})
|
|
|
|
endmacro()
|
2013-05-21 21:48:27 +08:00
|
|
|
|
|
|
|
macro(add_compiler_rt_resource_file target_name file_name)
|
|
|
|
set(src_file "${CMAKE_CURRENT_SOURCE_DIR}/${file_name}")
|
2014-02-18 22:28:53 +08:00
|
|
|
set(dst_file "${COMPILER_RT_OUTPUT_DIR}/${file_name}")
|
2014-02-27 15:22:59 +08:00
|
|
|
add_custom_command(OUTPUT ${dst_file}
|
|
|
|
DEPENDS ${src_file}
|
2013-05-21 21:48:27 +08:00
|
|
|
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${src_file} ${dst_file}
|
2014-02-27 15:22:59 +08:00
|
|
|
COMMENT "Copying ${file_name}...")
|
|
|
|
add_custom_target(${target_name} DEPENDS ${dst_file})
|
2013-05-21 21:48:27 +08:00
|
|
|
# Install in Clang resource directory.
|
2014-02-18 22:28:53 +08:00
|
|
|
install(FILES ${file_name} DESTINATION ${COMPILER_RT_INSTALL_PATH})
|
2013-05-21 21:48:27 +08:00
|
|
|
endmacro()
|
2014-02-27 16:41:40 +08: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-10 06:11:03 +08: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()
|
|
|
|
|
|
|
|
parse_arguments(LIBCXX "DEPS;CFLAGS" "" ${ARGN})
|
|
|
|
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>
|
|
|
|
)
|
|
|
|
|
|
|
|
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()
|