Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 1 | include(AddLLVM) |
| 2 | include(LLVMParseArguments) |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 3 | include(CompilerRTUtils) |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 4 | |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 5 | # Tries to add "object library" target for a given architecture |
| 6 | # with name "<name>.<arch>" if architecture can be targeted. |
| 7 | # add_compiler_rt_object_library(<name> <arch> |
| 8 | # SOURCES <source files> |
| 9 | # CFLAGS <compile flags>) |
| 10 | macro(add_compiler_rt_object_library name arch) |
| 11 | if(CAN_TARGET_${arch}) |
| 12 | parse_arguments(LIB "SOURCES;CFLAGS" "" ${ARGN}) |
| 13 | add_library(${name}.${arch} OBJECT ${LIB_SOURCES}) |
| 14 | set_target_compile_flags(${name}.${arch} |
| 15 | ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) |
| 16 | else() |
| 17 | message(FATAL_ERROR "Archtecture ${arch} can't be targeted") |
| 18 | endif() |
| 19 | endmacro() |
| 20 | |
Alexey Samsonov | e16af95 | 2013-01-20 13:58:10 +0000 | [diff] [blame^] | 21 | # Adds static runtime for a given architecture and puts it in the proper |
| 22 | # directory in the build and install trees. |
| 23 | # add_compiler_rt_static_runtime(<name> <arch> |
| 24 | # SOURCES <source files> |
| 25 | # CFLAGS <compile flags> |
| 26 | # DEFS <compile definitions>) |
| 27 | macro(add_compiler_rt_static_runtime name arch) |
| 28 | if(CAN_TARGET_${arch}) |
| 29 | parse_arguments(LIB "SOURCES;CFLAGS;DEFS" "" ${ARGN}) |
| 30 | add_library(${name} STATIC ${LIB_SOURCES}) |
| 31 | # Setup compile flags and definitions. |
| 32 | set_target_compile_flags(${name} |
| 33 | ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) |
| 34 | set_property(TARGET ${name} APPEND PROPERTY |
| 35 | COMPILE_DEFINITIONS ${LIB_DEFS}) |
| 36 | # Setup correct output directory in the build tree. |
| 37 | set_target_properties(${name} PROPERTIES |
| 38 | ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) |
| 39 | # Add installation command. |
| 40 | install(TARGETS ${name} |
| 41 | ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) |
| 42 | else() |
| 43 | message(FATAL_ERROR "Archtecture ${arch} can't be targeted") |
| 44 | endif() |
| 45 | endmacro() |
| 46 | |
Alexey Samsonov | 392c50d | 2013-01-18 16:05:21 +0000 | [diff] [blame] | 47 | # Unittests support. |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 48 | set(COMPILER_RT_GTEST_PATH ${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest) |
| 49 | set(COMPILER_RT_GTEST_SOURCE ${COMPILER_RT_GTEST_PATH}/gtest-all.cc) |
| 50 | set(COMPILER_RT_GTEST_INCLUDE_CFLAGS |
| 51 | -DGTEST_NO_LLVM_RAW_OSTREAM=1 |
| 52 | -I${COMPILER_RT_GTEST_PATH}/include |
| 53 | ) |
| 54 | |
| 55 | # Use Clang to link objects into a single executable with just-built |
| 56 | # Clang, using specific link flags. Make executable a part of provided |
| 57 | # test_suite. |
| 58 | # add_compiler_rt_test(<test_suite> <test_name> |
| 59 | # OBJECTS <object files> |
| 60 | # DEPS <deps (e.g. runtime libs)> |
| 61 | # LINK_FLAGS <link flags>) |
| 62 | macro(add_compiler_rt_test test_suite test_name) |
| 63 | parse_arguments(TEST "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN}) |
| 64 | get_unittest_directory(OUTPUT_DIR) |
Evgeniy Stepanov | 49ca997 | 2012-12-20 14:34:09 +0000 | [diff] [blame] | 65 | file(MAKE_DIRECTORY ${OUTPUT_DIR}) |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 66 | set(output_bin "${OUTPUT_DIR}/${test_name}") |
| 67 | add_custom_command( |
| 68 | OUTPUT ${output_bin} |
| 69 | COMMAND clang ${TEST_OBJECTS} -o "${output_bin}" |
| 70 | ${TEST_LINK_FLAGS} |
Alexey Samsonov | 32b8991 | 2012-12-21 08:56:14 +0000 | [diff] [blame] | 71 | DEPENDS clang ${TEST_DEPS}) |
Alexey Samsonov | 02dcc63 | 2012-12-19 12:33:39 +0000 | [diff] [blame] | 72 | add_custom_target(${test_name} DEPENDS ${output_bin}) |
| 73 | # Make the test suite depend on the binary. |
| 74 | add_dependencies(${test_suite} ${test_name}) |
| 75 | endmacro() |