summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2015-07-06 20:15:49 (GMT)
committerBrad King <brad.king@kitware.com>2015-07-06 20:15:49 (GMT)
commitbf11253163b54f7c18b001cb00973a6341ee859b (patch)
treeadf50cd777722e5c08168025889c08a2e7ce68da /Tests
parent8fbd9584af44100bbddd0f4031b57c5bc2530837 (diff)
downloadCMake-bf11253163b54f7c18b001cb00973a6341ee859b.zip
CMake-bf11253163b54f7c18b001cb00973a6341ee859b.tar.gz
CMake-bf11253163b54f7c18b001cb00973a6341ee859b.tar.bz2
Add rudimentary support for the Apple Swift language with Xcode
Allow the `Swift` language to be enabled with the Xcode generator for Xcode >= 6.1. Reject it on other generators and with older Xcode versions. Since Apple is the only vendor implementing the language right now, the compiler id can be just `Apple`.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/CMakeLists.txt6
-rw-r--r--Tests/RunCMake/CMakeLists.txt5
-rw-r--r--Tests/RunCMake/Swift/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/Swift/Enable-stdout.txt1
-rw-r--r--Tests/RunCMake/Swift/Enable.cmake1
-rw-r--r--Tests/RunCMake/Swift/NotSupported-result.txt1
-rw-r--r--Tests/RunCMake/Swift/NotSupported-stderr.txt5
-rw-r--r--Tests/RunCMake/Swift/NotSupported.cmake1
-rw-r--r--Tests/RunCMake/Swift/RunCMakeTest.cmake11
-rw-r--r--Tests/RunCMake/Swift/XcodeTooOld-result.txt1
-rw-r--r--Tests/RunCMake/Swift/XcodeTooOld-stderr.txt5
-rw-r--r--Tests/RunCMake/Swift/XcodeTooOld.cmake1
-rw-r--r--Tests/SwiftMix/CMain.c4
-rw-r--r--Tests/SwiftMix/CMakeLists.txt5
-rw-r--r--Tests/SwiftMix/ObjC-Swift.h0
-rw-r--r--Tests/SwiftMix/ObjCMain.m4
-rw-r--r--Tests/SwiftMix/SwiftMain.swift10
-rw-r--r--Tests/SwiftOnly/CMakeLists.txt4
-rw-r--r--Tests/SwiftOnly/main.swift1
19 files changed, 69 insertions, 0 deletions
diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt
index 8865063..8de1c79 100644
--- a/Tests/CMakeLists.txt
+++ b/Tests/CMakeLists.txt
@@ -260,6 +260,12 @@ if(BUILD_TESTING)
ADD_TEST_MACRO(MissingSourceFile MissingSourceFile)
set_tests_properties(MissingSourceFile PROPERTIES
PASS_REGULAR_EXPRESSION "CMake Error at CMakeLists.txt:3 \\(add_executable\\):[ \r\n]*Cannot find source file:[ \r\n]*DoesNotExist/MissingSourceFile.c")
+ if(CMake_TEST_XCODE_VERSION AND NOT CMake_TEST_XCODE_VERSION VERSION_LESS 6.1)
+ if(CMAKE_GENERATOR STREQUAL "Xcode")
+ ADD_TEST_MACRO(SwiftMix SwiftMix)
+ ADD_TEST_MACRO(SwiftOnly SwiftOnly)
+ endif()
+ endif()
if(CMAKE_Fortran_COMPILER)
ADD_TEST_MACRO(FortranOnly FortranOnly)
endif()
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index bc706d3..adbe7cc 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -59,6 +59,10 @@ function(add_RunCMake_test_group test types)
endforeach()
endfunction()
+if(XCODE_VERSION AND "${XCODE_VERSION}" VERSION_LESS 6.1)
+ set(Swift_ARGS -DXCODE_BELOW_6_1=1)
+endif()
+
if(XCODE_VERSION AND "${XCODE_VERSION}" VERSION_LESS 3)
set(GeneratorToolset_ARGS -DXCODE_BELOW_3=1)
endif()
@@ -132,6 +136,7 @@ add_RunCMake_test(GNUInstallDirs)
add_RunCMake_test(TargetPropertyGeneratorExpressions)
add_RunCMake_test(Languages)
add_RunCMake_test(ObjectLibrary)
+add_RunCMake_test(Swift)
add_RunCMake_test(TargetObjects)
add_RunCMake_test(TargetSources)
add_RunCMake_test(find_dependency)
diff --git a/Tests/RunCMake/Swift/CMakeLists.txt b/Tests/RunCMake/Swift/CMakeLists.txt
new file mode 100644
index 0000000..74b3ff8
--- /dev/null
+++ b/Tests/RunCMake/Swift/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.3)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/Swift/Enable-stdout.txt b/Tests/RunCMake/Swift/Enable-stdout.txt
new file mode 100644
index 0000000..39e133f
--- /dev/null
+++ b/Tests/RunCMake/Swift/Enable-stdout.txt
@@ -0,0 +1 @@
+-- The Swift compiler identification is Apple
diff --git a/Tests/RunCMake/Swift/Enable.cmake b/Tests/RunCMake/Swift/Enable.cmake
new file mode 100644
index 0000000..19f297a
--- /dev/null
+++ b/Tests/RunCMake/Swift/Enable.cmake
@@ -0,0 +1 @@
+enable_language(Swift)
diff --git a/Tests/RunCMake/Swift/NotSupported-result.txt b/Tests/RunCMake/Swift/NotSupported-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/Swift/NotSupported-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Swift/NotSupported-stderr.txt b/Tests/RunCMake/Swift/NotSupported-stderr.txt
new file mode 100644
index 0000000..9a9c23f
--- /dev/null
+++ b/Tests/RunCMake/Swift/NotSupported-stderr.txt
@@ -0,0 +1,5 @@
+^CMake Error at .*/Modules/CMakeDetermineSwiftCompiler.cmake:[0-9]+ \(message\):
+ Swift language not supported by "[^"]*" generator
+Call Stack \(most recent call first\):
+ NotSupported.cmake:[0-9]+ \(enable_language\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/Swift/NotSupported.cmake b/Tests/RunCMake/Swift/NotSupported.cmake
new file mode 100644
index 0000000..19f297a
--- /dev/null
+++ b/Tests/RunCMake/Swift/NotSupported.cmake
@@ -0,0 +1 @@
+enable_language(Swift)
diff --git a/Tests/RunCMake/Swift/RunCMakeTest.cmake b/Tests/RunCMake/Swift/RunCMakeTest.cmake
new file mode 100644
index 0000000..0a57121
--- /dev/null
+++ b/Tests/RunCMake/Swift/RunCMakeTest.cmake
@@ -0,0 +1,11 @@
+include(RunCMake)
+
+if(RunCMake_GENERATOR STREQUAL Xcode)
+ if(XCODE_BELOW_6_1)
+ run_cmake(XcodeTooOld)
+ else()
+ run_cmake(Enable)
+ endif()
+else()
+ run_cmake(NotSupported)
+endif()
diff --git a/Tests/RunCMake/Swift/XcodeTooOld-result.txt b/Tests/RunCMake/Swift/XcodeTooOld-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/Swift/XcodeTooOld-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/Swift/XcodeTooOld-stderr.txt b/Tests/RunCMake/Swift/XcodeTooOld-stderr.txt
new file mode 100644
index 0000000..8d18f29
--- /dev/null
+++ b/Tests/RunCMake/Swift/XcodeTooOld-stderr.txt
@@ -0,0 +1,5 @@
+^CMake Error at .*/Modules/CMakeDetermineSwiftCompiler.cmake:[0-9]+ \(message\):
+ Swift language not supported by Xcode [0-9.]+
+Call Stack \(most recent call first\):
+ XcodeTooOld.cmake:[0-9]+ \(enable_language\)
+ CMakeLists.txt:[0-9]+ \(include\)
diff --git a/Tests/RunCMake/Swift/XcodeTooOld.cmake b/Tests/RunCMake/Swift/XcodeTooOld.cmake
new file mode 100644
index 0000000..19f297a
--- /dev/null
+++ b/Tests/RunCMake/Swift/XcodeTooOld.cmake
@@ -0,0 +1 @@
+enable_language(Swift)
diff --git a/Tests/SwiftMix/CMain.c b/Tests/SwiftMix/CMain.c
new file mode 100644
index 0000000..13e2f8c
--- /dev/null
+++ b/Tests/SwiftMix/CMain.c
@@ -0,0 +1,4 @@
+extern int ObjCMain(int argc, char const* const argv[]);
+int main(int argc, char* argv[]) {
+ return ObjCMain(argc, argv);
+}
diff --git a/Tests/SwiftMix/CMakeLists.txt b/Tests/SwiftMix/CMakeLists.txt
new file mode 100644
index 0000000..5e50470
--- /dev/null
+++ b/Tests/SwiftMix/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 3.3)
+project(SwiftMix C Swift)
+
+add_executable(SwiftMix CMain.c ObjCMain.m SwiftMain.swift ObjC-Swift.h)
+set_property(TARGET SwiftMix PROPERTY XCODE_ATTRIBUTE_SWIFT_OBJC_BRIDGING_HEADER "ObjC-Swift.h")
diff --git a/Tests/SwiftMix/ObjC-Swift.h b/Tests/SwiftMix/ObjC-Swift.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/SwiftMix/ObjC-Swift.h
diff --git a/Tests/SwiftMix/ObjCMain.m b/Tests/SwiftMix/ObjCMain.m
new file mode 100644
index 0000000..7fa90ae
--- /dev/null
+++ b/Tests/SwiftMix/ObjCMain.m
@@ -0,0 +1,4 @@
+#import "SwiftMix-Swift.h"
+int ObjCMain(int argc, char const* const argv[]) {
+ return [SwiftMainClass SwiftMain:argc argv:argv];
+}
diff --git a/Tests/SwiftMix/SwiftMain.swift b/Tests/SwiftMix/SwiftMain.swift
new file mode 100644
index 0000000..9af9883
--- /dev/null
+++ b/Tests/SwiftMix/SwiftMain.swift
@@ -0,0 +1,10 @@
+@objc class SwiftMainClass {
+ class func SwiftMain(argc:Int, argv:UnsafePointer<UnsafePointer<CChar>>) -> Int32 {
+ println("argc: \(argc)")
+ for (var i = 0; i < argc; ++i) {
+ var argi = String.fromCString(argv[i])
+ println("arg[\(i)]: \(argi)");
+ }
+ return 0;
+ }
+}
diff --git a/Tests/SwiftOnly/CMakeLists.txt b/Tests/SwiftOnly/CMakeLists.txt
new file mode 100644
index 0000000..5cb9739
--- /dev/null
+++ b/Tests/SwiftOnly/CMakeLists.txt
@@ -0,0 +1,4 @@
+cmake_minimum_required(VERSION 3.3)
+project(SwiftOnly Swift)
+
+add_executable(SwiftOnly main.swift)
diff --git a/Tests/SwiftOnly/main.swift b/Tests/SwiftOnly/main.swift
new file mode 100644
index 0000000..67be986
--- /dev/null
+++ b/Tests/SwiftOnly/main.swift
@@ -0,0 +1 @@
+println("SwiftOnly")