Forráskód Böngészése

Xcode: Don't add framework as -framework argument in linker info list

Gusts Kaksis 5 éve
szülő
commit
ce2dee9e5b

+ 11 - 5
Source/cmComputeLinkInformation.cxx

@@ -1293,11 +1293,17 @@ void cmComputeLinkInformation::AddFrameworkItem(std::string const& item)
   // add runtime information
   this->AddLibraryRuntimeInfo(full_fw);
 
-  // Add the item using the -framework option.
-  this->Items.emplace_back(std::string("-framework"), false);
-  cmOutputConverter converter(this->Makefile->GetStateSnapshot());
-  fw = converter.EscapeForShell(fw);
-  this->Items.emplace_back(fw, false);
+  if (this->GlobalGenerator->IsXcode()) {
+    // Add framework path - it will be handled by Xcode after it's added to
+    // "Link Binary With Libraries" build phase
+    this->Items.emplace_back(item, true);
+  } else {
+    // Add the item using the -framework option.
+    this->Items.emplace_back(std::string("-framework"), false);
+    cmOutputConverter converter(this->Makefile->GetStateSnapshot());
+    fw = converter.EscapeForShell(fw);
+    this->Items.emplace_back(fw, false);
+  }
 }
 
 void cmComputeLinkInformation::AddDirectoryItem(std::string const& item)

+ 9 - 1
Source/cmGlobalXCodeGenerator.cxx

@@ -3579,8 +3579,16 @@ void cmGlobalXCodeGenerator::AddDependAndLinkInformation(cmXCodeObject* target)
       for (auto const& libItem : configItemMap[configName]) {
         auto const& libName = *libItem;
         if (libName.IsPath) {
-          libPaths.Add(this->XCodeEscapePath(libName.Value.Value));
           const auto libPath = GetLibraryOrFrameworkPath(libName.Value.Value);
+          if (cmSystemTools::StringEndsWith(libPath.c_str(), ".framework")) {
+            const auto fwName =
+              cmSystemTools::GetFilenameWithoutExtension(libPath);
+            const auto fwDir = cmSystemTools::GetParentDirectory(libPath);
+            libPaths.Add("-F " + this->XCodeEscapePath(fwDir));
+            libPaths.Add("-framework " + fwName);
+          } else {
+            libPaths.Add(this->XCodeEscapePath(libName.Value.Value));
+          }
           if ((!libName.Target || libName.Target->IsImported()) &&
               IsLinkPhaseLibraryExtension(libPath)) {
             // Create file reference for embedding

+ 50 - 5
Tests/RunCMake/XcodeProject/LinkBinariesBuildPhase.cmake

@@ -9,16 +9,28 @@ int func2();
 int func3();
 int func4();
 int func5();
+int func6();
+int func7();
+]])
+set(prototypes_objc [[
+#import <CoreFoundation/CoreFoundation.h>
 ]])
 set(impl [[
 {
   printf("%p %p\n", compress, res_close);
-  return func1() + func2() + func3() + func4() + func5();
+  return func1() + func2() + func3() + func4() + func5() + func6() + func7();
+}
+]])
+set(impl_objc [[
+{
+  CFStringRef cfStr = CFSTR("This is a string");
+  printf("%p %p %ld\n", compress, res_close, (long)CFStringGetLength(cfStr));
+  return func1() + func2() + func3() + func4() + func5() + func6() + func7();
 }
 ]])
 
-file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/mainOuter.c
-  "${prototypes}\nint main(int argc, char** argv) ${impl}"
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/mainOuter.m
+  "${prototypes}\n${prototypes_objc}\nint main(int argc, char** argv) ${impl_objc}"
 )
 
 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/funcOuter.c
@@ -31,7 +43,28 @@ foreach(i RANGE 1 5)
   )
 endforeach()
 
-add_executable(app1 mainOuter.c)
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/ExternalFrameworks/CMakeLists.txt
+[[
+cmake_minimum_required(VERSION 3.18)
+project(ExternalFrameworks)
+add_library(staticFrameworkExt STATIC func6.c)
+add_library(sharedFrameworkExt SHARED func7.c)
+set_target_properties(staticFrameworkExt PROPERTIES FRAMEWORK TRUE)
+set_target_properties(sharedFrameworkExt PROPERTIES FRAMEWORK TRUE)
+]]
+)
+
+foreach(i RANGE 6 7)
+  file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/ExternalFrameworks/func${i}.c
+    "int func${i}() { return 32 + ${i}; }\n"
+  )
+endforeach()
+
+add_custom_target(prebuildDependencies ALL
+    COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_BINARY_DIR}/ExternalFrameworks -B ${CMAKE_CURRENT_BINARY_DIR}/ExternalFrameworks/build -G Xcode
+    COMMAND ${CMAKE_COMMAND} --build ${CMAKE_CURRENT_BINARY_DIR}/ExternalFrameworks/build --target staticFrameworkExt sharedFrameworkExt --config Debug
+)
+add_executable(app1 mainOuter.m)
 add_library(static1 STATIC funcOuter.c)
 add_library(shared1 SHARED funcOuter.c)
 add_library(module1 MODULE funcOuter.c)
@@ -40,6 +73,13 @@ add_library(staticFramework1 STATIC funcOuter.c)
 add_library(sharedFramework1 SHARED funcOuter.c)
 set_target_properties(staticFramework1 PROPERTIES FRAMEWORK TRUE)
 set_target_properties(sharedFramework1 PROPERTIES FRAMEWORK TRUE)
+add_dependencies(app1 prebuildDependencies)
+add_dependencies(static1 prebuildDependencies)
+add_dependencies(shared1 prebuildDependencies)
+add_dependencies(module1 prebuildDependencies)
+add_dependencies(obj1 prebuildDependencies)
+add_dependencies(staticFramework1 prebuildDependencies)
+add_dependencies(sharedFramework1 prebuildDependencies)
 
 add_library(static2 STATIC func1.c)
 add_library(shared2 SHARED func2.c)
@@ -49,9 +89,10 @@ add_library(sharedFramework2 SHARED func5.c)
 set_target_properties(staticFramework2 PROPERTIES FRAMEWORK TRUE)
 set_target_properties(sharedFramework2 PROPERTIES FRAMEWORK TRUE)
 
-# Pick a couple of libraries that are always present in the Xcode SDK
+# Pick some external libraries that are always present in the Xcode SDK
 find_library(libz z REQUIRED)
 find_library(libresolv resolv REQUIRED)
+find_library(CoreFoundation CoreFoundation REQUIRED)
 add_library(imported2 UNKNOWN IMPORTED)
 set_target_properties(imported2 PROPERTIES IMPORTED_LOCATION ${libz})
 
@@ -59,6 +100,7 @@ set_target_properties(imported2 PROPERTIES IMPORTED_LOCATION ${libz})
 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/foundLibs.cmake "
 set(libz \"${libz}\")
 set(libresolv \"${libresolv}\")
+set(CoreFoundation \"${CoreFoundation}\")
 ")
 
 set(mainTargets
@@ -78,6 +120,9 @@ set(linkToThings
     sharedFramework2
     imported2
     ${libresolv}
+    ${CoreFoundation}
+    "${CMAKE_CURRENT_BINARY_DIR}/ExternalFrameworks/build/Debug/sharedFrameworkExt.framework"
+    "${CMAKE_CURRENT_BINARY_DIR}/ExternalFrameworks/build/Debug/staticFrameworkExt.framework"
 )
 
 foreach(mainTarget IN LISTS mainTargets)

+ 2 - 2
Tests/RunCMake/XcodeProject/LinkBinariesBuildPhase_BUILT_ONLY-check.cmake

@@ -6,7 +6,7 @@ include(${RunCMake_TEST_BINARY_DIR}/foundLibs.cmake)
 
 foreach(mainTarget IN ITEMS app1 shared1 module1 sharedFramework1)
   checkFlags(OTHER_LDFLAGS ${mainTarget}
-    "obj2;${libz};${libresolv}"
+    "obj2;${libz};${libresolv};CoreFoundation;sharedFrameworkExt;staticFrameworkExt"
     "static2;shared2;staticFramework2;sharedFramework2"
   )
 endforeach()
@@ -14,6 +14,6 @@ endforeach()
 foreach(mainTarget IN ITEMS static1 staticFramework1)
   checkFlags(OTHER_LIBTOOLFLAGS ${mainTarget}
     "obj2"
-    "static2;shared2;staticFramework2;sharedFramework2;${libz};${libresolv}"
+    "static2;shared2;staticFramework2;sharedFramework2;${libz};${libresolv};CoreFoundation;sharedFrameworkExt;staticFrameworkExt"
   )
 endforeach()

+ 2 - 0
Tests/RunCMake/XcodeProject/LinkBinariesBuildPhase_Funcs.cmake

@@ -1,3 +1,5 @@
+cmake_minimum_required(VERSION 3.18...3.19)
+
 macro(returnOnError errorMsg)
   if(NOT "${errorMsg}" STREQUAL "")
     set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}\n${errorMsg}" PARENT_SCOPE)

+ 2 - 2
Tests/RunCMake/XcodeProject/LinkBinariesBuildPhase_KNOWN_LOCATION-check.cmake

@@ -7,13 +7,13 @@ include(${RunCMake_TEST_BINARY_DIR}/foundLibs.cmake)
 foreach(mainTarget IN ITEMS app1 shared1 module1 sharedFramework1)
   checkFlags(OTHER_LDFLAGS ${mainTarget}
     "obj2"
-    "static2;shared2;staticFramework2;sharedFramework2;${libz};${libresolv}"
+    "static2;shared2;staticFramework2;sharedFramework2;${libz};${libresolv};CoreFoundation;sharedFrameworkExt;staticFrameworkExt"
   )
 endforeach()
 
 foreach(mainTarget IN ITEMS static1 staticFramework1)
   checkFlags(OTHER_LIBTOOLFLAGS ${mainTarget}
     "obj2"
-    "static2;shared2;staticFramework2;sharedFramework2;${libz};${libresolv}"
+    "static2;shared2;staticFramework2;sharedFramework2;${libz};${libresolv};CoreFoundation;sharedFrameworkExt;staticFrameworkExt"
   )
 endforeach()

+ 2 - 2
Tests/RunCMake/XcodeProject/LinkBinariesBuildPhase_NONE-check.cmake

@@ -6,7 +6,7 @@ include(${RunCMake_TEST_BINARY_DIR}/foundLibs.cmake)
 
 foreach(mainTarget IN ITEMS app1 shared1 module1 sharedFramework1)
   checkFlags(OTHER_LDFLAGS ${mainTarget}
-    "static2;shared2;staticFramework2;sharedFramework2;obj2;${libz};${libresolv}"
+    "static2;shared2;staticFramework2;sharedFramework2;obj2;${libz};${libresolv};CoreFoundation;sharedFrameworkExt;staticFrameworkExt"
     ""
   )
 endforeach()
@@ -14,6 +14,6 @@ endforeach()
 foreach(mainTarget IN ITEMS static1 staticFramework1)
   checkFlags(OTHER_LIBTOOLFLAGS ${mainTarget}
     "obj2"
-    "static2;shared2;staticFramework2;sharedFramework2;${libz};${libresolv}"
+    "static2;shared2;staticFramework2;sharedFramework2;${libz};${libresolv};CoreFoundation;sharedFrameworkExt;staticFrameworkExt"
   )
 endforeach()