summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-12-18 18:44:44 (GMT)
committerBrad King <brad.king@kitware.com>2020-12-21 16:50:54 (GMT)
commit9ab77201f772af9f8f0954722ed3a2414eb1d29c (patch)
tree6b3142e4c59ba1254c8ab28d2c633e52650bd649
parent05a59f37abd982b249f8cad648640c3394acc98a (diff)
downloadCMake-9ab77201f772af9f8f0954722ed3a2414eb1d29c.zip
CMake-9ab77201f772af9f8f0954722ed3a2414eb1d29c.tar.gz
CMake-9ab77201f772af9f8f0954722ed3a2414eb1d29c.tar.bz2
Apple: Fix linking to frameworks that do not exist until build time
Fixes: #21621
-rw-r--r--Source/cmComputeLinkInformation.cxx18
-rw-r--r--Source/cmComputeLinkInformation.h1
-rw-r--r--Tests/Framework/CMakeLists.txt16
-rw-r--r--Tests/Framework/External/CMakeLists.txt5
-rw-r--r--Tests/Framework/External/external.c4
-rw-r--r--Tests/Framework/useExternal.c6
6 files changed, 37 insertions, 13 deletions
diff --git a/Source/cmComputeLinkInformation.cxx b/Source/cmComputeLinkInformation.cxx
index 201a9d9..6e1fac0 100644
--- a/Source/cmComputeLinkInformation.cxx
+++ b/Source/cmComputeLinkInformation.cxx
@@ -699,9 +699,13 @@ void cmComputeLinkInformation::AddItem(BT<std::string> const& item,
} else {
// This is not a CMake target. Use the name given.
if (cmSystemTools::FileIsFullPath(item.Value)) {
- if (cmSystemTools::FileIsDirectory(item.Value)) {
+ if (cmSystemTools::IsPathToFramework(item.Value) &&
+ this->Makefile->IsOn("APPLE")) {
+ // This is a framework.
+ this->AddFrameworkItem(item.Value);
+ } else if (cmSystemTools::FileIsDirectory(item.Value)) {
// This is a directory.
- this->AddDirectoryItem(item.Value);
+ this->DropDirectoryItem(item.Value);
} else {
// Use the full path given to the library file.
this->Depends.push_back(item.Value);
@@ -1306,16 +1310,6 @@ void cmComputeLinkInformation::AddFrameworkItem(std::string const& item)
}
}
-void cmComputeLinkInformation::AddDirectoryItem(std::string const& item)
-{
- if (this->Makefile->IsOn("APPLE") &&
- cmSystemTools::IsPathToFramework(item)) {
- this->AddFrameworkItem(item);
- } else {
- this->DropDirectoryItem(item);
- }
-}
-
void cmComputeLinkInformation::DropDirectoryItem(std::string const& item)
{
// A full path to a directory was found as a link item. Warn the
diff --git a/Source/cmComputeLinkInformation.h b/Source/cmComputeLinkInformation.h
index 543b6d7..ec8d73c 100644
--- a/Source/cmComputeLinkInformation.h
+++ b/Source/cmComputeLinkInformation.h
@@ -155,7 +155,6 @@ private:
void AddFullItem(BT<std::string> const& item);
bool CheckImplicitDirItem(std::string const& item);
void AddUserItem(BT<std::string> const& item, bool pathNotKnown);
- void AddDirectoryItem(std::string const& item);
void AddFrameworkItem(std::string const& item);
void DropDirectoryItem(std::string const& item);
bool CheckSharedLibNoSOName(std::string const& item);
diff --git a/Tests/Framework/CMakeLists.txt b/Tests/Framework/CMakeLists.txt
index a313c2c..f741ec2 100644
--- a/Tests/Framework/CMakeLists.txt
+++ b/Tests/Framework/CMakeLists.txt
@@ -84,3 +84,19 @@ if(NOT XCODE OR NOT XCODE_VERSION VERSION_LESS 5)
endif()
include(CPack)
+
+if(APPLE)
+ set(ExternalFramework_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/External")
+ file(REMOVE_RECURSE "${ExternalFramework_INSTALL_DIR}")
+
+ include(ExternalProject)
+ ExternalProject_Add(ExternalFramework
+ SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/External"
+ INSTALL_DIR "${ExternalFramework_INSTALL_DIR}"
+ CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
+ )
+
+ add_executable(useExternal useExternal.c)
+ target_link_libraries(useExternal PRIVATE "${ExternalFramework_INSTALL_DIR}/lib/External.framework")
+ add_dependencies(useExternal ExternalFramework)
+endif()
diff --git a/Tests/Framework/External/CMakeLists.txt b/Tests/Framework/External/CMakeLists.txt
new file mode 100644
index 0000000..b9128fd
--- /dev/null
+++ b/Tests/Framework/External/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 3.19)
+project(ExternalFramework C)
+add_library(External SHARED external.c)
+set_property(TARGET External PROPERTY FRAMEWORK 1)
+install(TARGETS External DESTINATION lib)
diff --git a/Tests/Framework/External/external.c b/Tests/Framework/External/external.c
new file mode 100644
index 0000000..8441e71
--- /dev/null
+++ b/Tests/Framework/External/external.c
@@ -0,0 +1,4 @@
+int external(void)
+{
+ return 0;
+}
diff --git a/Tests/Framework/useExternal.c b/Tests/Framework/useExternal.c
new file mode 100644
index 0000000..8494b15
--- /dev/null
+++ b/Tests/Framework/useExternal.c
@@ -0,0 +1,6 @@
+extern int external(void);
+
+int main(void)
+{
+ return external();
+}