Signed-off-by: Gregor Jasny <gja...@googlemail.com> --- Modules/XCTestUtilities.cmake | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Modules/XCTestUtilities.cmake
diff --git a/Modules/XCTestUtilities.cmake b/Modules/XCTestUtilities.cmake new file mode 100644 index 0000000..6b1de92 --- /dev/null +++ b/Modules/XCTestUtilities.cmake @@ -0,0 +1,58 @@ +function(add_xctest target testee) + + if(NOT CMAKE_OSX_SYSROOT) + message(STATUS "Adding XCTest bundles requires CMAKE_OSX_SYSROOT to be set.") + endif() + + # check that testee is a valid target type + get_target_property(TESTEE_TYPE ${testee} TYPE) + get_target_property(TESTEE_FRAMEWORK ${testee} FRAMEWORK) + if(TESTEE_TYPE STREQUAL "SHARED_LIBRARY" AND TESTEE_FRAMEWORK) + # found a framework + else() + message(FATAL_ERROR "Testee ${testee} is of unsupported type: ${TESTEE_TYPE}") + endif() + + add_library(${target} MODULE ${ARGN}) + + set_target_properties(${target} PROPERTIES + BUNDLE TRUE + XCTEST TRUE) + + find_library(FOUNDATION_LIBRARY Foundation) + if(NOT FOUNDATION_LIBRARY) + message(STATUS "Could not find Foundation Framework.") + endif() + + find_library(XCTEST_LIBRARY XCTest) + if(NOT XCTEST_LIBRARY) + message(STATUS "Could not find XCTest Framework.") + endif() + + target_link_libraries(${target} PRIVATE ${testee} ${FOUNDATION_LIBRARY} ${XCTEST_LIBRARY}) + + # set rpath to find testee + target_link_libraries(${target} PRIVATE "${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG}$<TARGET_LINKER_FILE_DIR:${testee}>") +endfunction(add_xctest) + +function(add_test_xctest target) + get_target_property(TARGET_TYPE ${target} TYPE) + get_target_property(TARGET_XCTEST ${target} XCTEST) + + if(NOT TARGET_TYPE STREQUAL "MODULE_LIBRARY" OR NOT TARGET_XCTEST) + message(FATAL_ERROR "Test ${target} is not a XCTest") + endif() + + execute_process( + COMMAND xcrun --find xctest + OUTPUT_VARIABLE XCTEST_EXECUTABLE + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if(NOT XCTEST_EXECUTABLE) + message(STATUS "Unable to finc xctest binary.") + endif() + + add_test( + NAME FrameworkExampleTests + COMMAND ${XCTEST_EXECUTABLE} $<TARGET_LINKER_FILE_DIR:${target}>/../..) +endfunction(add_test_xctest) \ No newline at end of file -- 2.3.0 -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: http://public.kitware.com/mailman/listinfo/cmake-developers