|
| 1 | + |
| 2 | +include(AddSwift) |
| 3 | + |
| 4 | +add_custom_target(SwiftUnitTests) |
| 5 | + |
| 6 | +set_target_properties(SwiftUnitTests PROPERTIES FOLDER "Tests") |
| 7 | + |
| 8 | +function(add_swift_unittest test_dirname) |
| 9 | + # *NOTE* Even though "add_unittest" does not have llvm in its name, it is a |
| 10 | + # function defined by AddLLVM.cmake. |
| 11 | + add_unittest(SwiftUnitTests ${test_dirname} ${ARGN}) |
| 12 | + |
| 13 | + if(SWIFT_BUILT_STANDALONE AND NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".") |
| 14 | + # Replace target references with full paths, so that we use LLVM's |
| 15 | + # build configuration rather than Swift's. |
| 16 | + get_target_property(libnames ${test_dirname} LINK_LIBRARIES) |
| 17 | + |
| 18 | + set(new_libnames) |
| 19 | + foreach(dep ${libnames}) |
| 20 | + if("${dep}" MATCHES "^(LLVM|Clang|gtest)") |
| 21 | + list(APPEND new_libnames "${LLVM_LIBRARY_OUTPUT_INTDIR}/lib${dep}.a") |
| 22 | + else() |
| 23 | + list(APPEND new_libnames "${dep}") |
| 24 | + endif() |
| 25 | + endforeach() |
| 26 | + |
| 27 | + set_property(TARGET ${test_dirname} PROPERTY LINK_LIBRARIES ${new_libnames}) |
| 28 | + swift_common_llvm_config(${test_dirname} support) |
| 29 | + endif() |
| 30 | + |
| 31 | + if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") |
| 32 | + set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY |
| 33 | + LINK_FLAGS " -Xlinker -rpath -Xlinker ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/macosx") |
| 34 | + |
| 35 | + if(SWIFT_ANALYZE_CODE_COVERAGE) |
| 36 | + set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY |
| 37 | + LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping") |
| 38 | + endif() |
| 39 | + elseif(${SWIFT_ENABLE_GOLD_LINKER}) |
| 40 | + set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY |
| 41 | + LINK_FLAGS " -fuse-ld=gold") |
| 42 | + endif() |
| 43 | +endfunction() |
| 44 | + |
| 45 | + |
0 commit comments