Browse Source

Xcode: Add targets marked as EXCLUDE_FROM_ALL to project (#16101)

Gregor Jasny 9 years ago
parent
commit
df32e564ae

+ 4 - 9
Source/cmGlobalXCodeGenerator.cxx

@@ -2635,13 +2635,10 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
 }
 
 bool cmGlobalXCodeGenerator::CreateGroups(
-  cmLocalGenerator* root, std::vector<cmLocalGenerator*>& generators)
+  std::vector<cmLocalGenerator*>& generators)
 {
   for (std::vector<cmLocalGenerator*>::iterator i = generators.begin();
        i != generators.end(); ++i) {
-    if (this->IsExcluded(root, *i)) {
-      continue;
-    }
     cmMakefile* mf = (*i)->GetMakefile();
     std::vector<cmSourceGroup> sourceGroups = mf->GetSourceGroups();
     std::vector<cmGeneratorTarget*> tgts = (*i)->GetGeneratorTargets();
@@ -2873,7 +2870,7 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
   this->MainGroupChildren->AddObject(resourcesGroup);
 
   // now create the cmake groups
-  if (!this->CreateGroups(root, generators)) {
+  if (!this->CreateGroups(generators)) {
     return false;
   }
 
@@ -3041,10 +3038,8 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
   std::vector<cmXCodeObject*> targets;
   for (std::vector<cmLocalGenerator*>::iterator i = generators.begin();
        i != generators.end(); ++i) {
-    if (!this->IsExcluded(root, *i)) {
-      if (!this->CreateXCodeTargets(*i, targets)) {
-        return false;
-      }
+    if (!this->CreateXCodeTargets(*i, targets)) {
+      return false;
     }
   }
   // loop over all targets and add link and depend info

+ 1 - 2
Source/cmGlobalXCodeGenerator.h

@@ -92,8 +92,7 @@ private:
   cmXCodeObject* CreateOrGetPBXGroup(cmGeneratorTarget* gtgt,
                                      cmSourceGroup* sg);
   cmXCodeObject* CreatePBXGroup(cmXCodeObject* parent, std::string name);
-  bool CreateGroups(cmLocalGenerator* root,
-                    std::vector<cmLocalGenerator*>& generators);
+  bool CreateGroups(std::vector<cmLocalGenerator*>& generators);
   std::string XCodeEscapePath(const std::string& p);
   std::string RelativeToSource(const char* p);
   std::string RelativeToBinary(const char* p);

+ 6 - 0
Tests/RunCMake/add_subdirectory/ExcludeFromAll.cmake

@@ -0,0 +1,6 @@
+enable_language(CXX)
+
+add_subdirectory(ExcludeFromAll EXCLUDE_FROM_ALL)
+
+add_executable(main main.cpp)
+target_link_libraries(main PRIVATE foo)

+ 4 - 0
Tests/RunCMake/add_subdirectory/ExcludeFromAll/CMakeLists.txt

@@ -0,0 +1,4 @@
+add_library(bar STATIC bar.cpp)
+
+add_library(foo STATIC foo.cpp)
+target_include_directories(foo PUBLIC .)

+ 1 - 0
Tests/RunCMake/add_subdirectory/ExcludeFromAll/bar.cpp

@@ -0,0 +1 @@
+#error This should be excluded from all target

+ 6 - 0
Tests/RunCMake/add_subdirectory/ExcludeFromAll/foo.cpp

@@ -0,0 +1,6 @@
+#include "foo.h"
+
+int foo()
+{
+  return 42;
+}

+ 1 - 0
Tests/RunCMake/add_subdirectory/ExcludeFromAll/foo.h

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

+ 12 - 0
Tests/RunCMake/add_subdirectory/RunCMakeTest.cmake

@@ -3,3 +3,15 @@ include(RunCMake)
 run_cmake(DoesNotExist)
 run_cmake(Missing)
 run_cmake(Function)
+
+set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/ExcludeFromAll-build)
+set(RunCMake_TEST_NO_CLEAN 1)
+
+file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+
+run_cmake(ExcludeFromAll)
+run_cmake_command(ExcludeFromAll-build ${CMAKE_COMMAND} --build .)
+
+unset(RunCMake_TEST_BINARY_DIR)
+unset(RunCMake_TEST_NO_CLEAN)

+ 6 - 0
Tests/RunCMake/add_subdirectory/main.cpp

@@ -0,0 +1,6 @@
+#include "foo.h"
+
+int main(int, char**)
+{
+  return foo();
+}