[cmake-developers] [PATCH 1/5] Add handling for XCTest bundles

Gregor Jasny gjasny at googlemail.com
Sat Feb 14 15:32:55 EST 2015


An XCTest bundle is a CFBundle with a special product-type and bundle
extension. It gets loaded directly into the AppBundle
it should test. For more information about XCTest visit the Mac
Developer library at:

  http://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/testing_with_xcode/

To build a XCTest bundle, you need to create a CFBundle and set the
XCTEST property.

add_library(CocoaExampleTest MODULE ...)
set_target_properties(CocoaExampleTest PROPERTIES
  BUNDLE TRUE
  XCTEST TRUE)

Signed-off-by: Gregor Jasny <gjasny at googlemail.com>
---
 Help/manual/cmake-properties.7.rst |  1 +
 Help/prop_tgt/XCTEST.rst           | 10 ++++++++++
 Source/cmGlobalXCodeGenerator.cxx  | 12 ++++++++++--
 Source/cmTarget.cxx                | 16 +++++++++++++++-
 Source/cmTarget.h                  |  3 +++
 5 files changed, 39 insertions(+), 3 deletions(-)
 create mode 100644 Help/prop_tgt/XCTEST.rst

diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst
index 25f989f..d795c6e 100644
--- a/Help/manual/cmake-properties.7.rst
+++ b/Help/manual/cmake-properties.7.rst
@@ -243,6 +243,7 @@ Properties on Targets
    /prop_tgt/VS_WINRT_REFERENCES
    /prop_tgt/WIN32_EXECUTABLE
    /prop_tgt/XCODE_ATTRIBUTE_an-attribute
+   /prop_tgt/XCTEST
 
 Properties on Tests
 ===================
diff --git a/Help/prop_tgt/XCTEST.rst b/Help/prop_tgt/XCTEST.rst
new file mode 100644
index 0000000..3a3adf6
--- /dev/null
+++ b/Help/prop_tgt/XCTEST.rst
@@ -0,0 +1,10 @@
+XCTEST
+------
+
+This target is a XCTest CFBundle on the Mac.
+
+If a module library target has this property set to true it will be
+built as a CFBundle when built on the mac.  It will have the directory
+structure required for a CFBundle.
+
+This property depends on :prop_tgt:`BUNDLE` to be effective.
diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx
index aea134e..784bc24 100644
--- a/Source/cmGlobalXCodeGenerator.cxx
+++ b/Source/cmGlobalXCodeGenerator.cxx
@@ -804,6 +804,10 @@ GetSourcecodeValueFromFileExtension(const std::string& _ext,
     {
     sourcecode = "compiled.mach-o.objfile";
     }
+  else if(ext == "xctest")
+    {
+    sourcecode = "wrapper.cfbundle";
+    }
   else if(ext == "xib")
     {
     keepLastKnownFileType = true;
@@ -2598,7 +2602,9 @@ const char* cmGlobalXCodeGenerator::GetTargetFileType(cmTarget& cmtarget)
     case cmTarget::STATIC_LIBRARY:
       return "archive.ar";
     case cmTarget::MODULE_LIBRARY:
-      if (cmtarget.IsCFBundleOnApple())
+      if (cmtarget.IsXCTestOnApple())
+        return "wrapper.cfbundle";
+      else if (cmtarget.IsCFBundleOnApple())
         return "wrapper.plug-in";
       else
         return ((this->XcodeVersion >= 22)?
@@ -2622,7 +2628,9 @@ const char* cmGlobalXCodeGenerator::GetTargetProductType(cmTarget& cmtarget)
     case cmTarget::STATIC_LIBRARY:
       return "com.apple.product-type.library.static";
     case cmTarget::MODULE_LIBRARY:
-      if (cmtarget.IsCFBundleOnApple())
+      if (cmtarget.IsXCTestOnApple())
+        return "com.apple.product-type.bundle.unit-test";
+      else if (cmtarget.IsCFBundleOnApple())
         return "com.apple.product-type.bundle";
       else
         return ((this->XcodeVersion >= 22)?
diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx
index 526a923..6ce165a 100644
--- a/Source/cmTarget.cxx
+++ b/Source/cmTarget.cxx
@@ -615,6 +615,13 @@ bool cmTarget::IsCFBundleOnApple() const
 }
 
 //----------------------------------------------------------------------------
+bool cmTarget::IsXCTestOnApple() const
+{
+  return (this->IsCFBundleOnApple() &&
+          this->GetPropertyAsBool("XCTEST"));
+}
+
+//----------------------------------------------------------------------------
 bool cmTarget::IsBundleOnApple() const
 {
   return this->IsFrameworkOnApple() || this->IsAppBundleOnApple() ||
@@ -6781,7 +6788,14 @@ std::string cmTarget::GetCFBundleDirectory(const std::string& config,
   const char *ext = this->GetProperty("BUNDLE_EXTENSION");
   if (!ext)
     {
-    ext = "bundle";
+    if (this->IsXCTestOnApple())
+      {
+      ext = "xctest";
+      }
+    else
+      {
+      ext = "bundle";
+      }
     }
   fpath += ext;
   fpath += "/Contents";
diff --git a/Source/cmTarget.h b/Source/cmTarget.h
index ddd9859..b58e0a0 100644
--- a/Source/cmTarget.h
+++ b/Source/cmTarget.h
@@ -526,6 +526,9 @@ public:
   /** Return whether this target is a CFBundle (plugin) on Apple.  */
   bool IsCFBundleOnApple() const;
 
+  /** Return whether this target is a XCTest on Apple.  */
+  bool IsXCTestOnApple() const;
+
   /** Return whether this target is an executable Bundle on Apple.  */
   bool IsAppBundleOnApple() const;
 
-- 
2.3.0



More information about the cmake-developers mailing list