Parcourir la source

XCTest: Add support for static frameworks

Fixes: #16636
Guillaume Campagna il y a 8 ans
Parent
commit
bfa92e5725

+ 4 - 0
Modules/FindXCTest.cmake

@@ -123,6 +123,10 @@ function(xctest_add_bundle target testee)
     # testee is a Framework
     target_link_libraries(${target} PRIVATE ${testee})
 
+  elseif(_testee_type STREQUAL "STATIC_LIBRARY")
+    # testee is a static library
+    target_link_libraries(${target} PRIVATE ${testee})
+
   elseif(_testee_type STREQUAL "EXECUTABLE" AND _testee_macosx_bundle)
     # testee is an App Bundle
     add_dependencies(${target} ${testee})

+ 16 - 0
Tests/XCTest/CMakeLists.txt

@@ -55,3 +55,19 @@ xctest_add_bundle(CocoaExampleTests CocoaExample
   CocoaExampleTests/CocoaExampleTests.m)
 
 xctest_add_test(XCTest.CocoaExample CocoaExampleTests)
+
+# Static lib
+
+add_library(StaticLibExample STATIC
+  StaticLibExample/StaticLibExample.h
+  StaticLibExample/StaticLibExample.c
+)
+
+target_include_directories(StaticLibExample PUBLIC .)
+
+# XCTest for Static lib
+
+xctest_add_bundle(StaticLibExampleTests StaticLibExample
+  StaticLibExampleTests/StaticLibExampleTests.m)
+
+xctest_add_test(XCTest.StaticLibExample StaticLibExampleTests)

+ 6 - 0
Tests/XCTest/StaticLibExample/StaticLibExample.c

@@ -0,0 +1,6 @@
+#include "StaticLibExample.h"
+
+int FourtyFour()
+{
+  return 44;
+}

+ 1 - 0
Tests/XCTest/StaticLibExample/StaticLibExample.h

@@ -0,0 +1 @@
+int FourtyFour();

+ 24 - 0
Tests/XCTest/StaticLibExampleTests/Info.plist

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>CFBundleDevelopmentRegion</key>
+	<string>en</string>
+	<key>CFBundleExecutable</key>
+	<string>StaticLibExampleTests</string>
+	<key>CFBundleIdentifier</key>
+	<string>org.cmake.StaticLibExampleTests</string>
+	<key>CFBundleInfoDictionaryVersion</key>
+	<string>6.0</string>
+	<key>CFBundleName</key>
+	<string>StaticLibExampleTests</string>
+	<key>CFBundlePackageType</key>
+	<string>BNDL</string>
+	<key>CFBundleShortVersionString</key>
+	<string>1.0</string>
+	<key>CFBundleSignature</key>
+	<string>????</string>
+	<key>CFBundleVersion</key>
+	<string>1</string>
+</dict>
+</plist>

+ 16 - 0
Tests/XCTest/StaticLibExampleTests/StaticLibExampleTests.m

@@ -0,0 +1,16 @@
+#import <XCTest/XCTest.h>
+
+#import "StaticLibExample/StaticLibExample.h"
+
+@interface StaticLibExampleTests : XCTestCase
+
+@end
+
+@implementation StaticLibExampleTests
+
+- (void)testFourtyFour {
+    // This is an example of a functional test case.
+    XCTAssertEqual(44, FourtyFour());
+}
+
+@end