summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2019-01-29 11:54:46 -0500
committerBrad King <brad.king@kitware.com>2019-01-29 12:49:53 -0500
commitd9dd68cb60ed09e32cbda8bbd3e31c86a8778e66 (patch)
tree8115a6a2ff6650a4011ff6a10d1bb3ee8d7546a9
parent8887ebc69b86606b388272d5c89ce11753bb4804 (diff)
downloadcmake-d9dd68cb60ed09e32cbda8bbd3e31c86a8778e66.tar.gz
macOS: Restore compatibility for setting FRAMEWORK after install()
The `FRAMEWORK` target property affects the way the `install()` command treats the target and so should be set first. Our implementation assumed that this was always the case and led to an assertion failure. Prior to CMake 3.12 this was visible only when using an explicit `LIBRARY ... NAMELINK_ONLY` option, but commit 0212d7c762 (install: add NAMELINK_COMPONENT argument, 2018-04-18, v3.12.0-rc1~139^2~3) made it possible with a simple `LIBRARY DESTINATION`. Fully supporting out-of-order specification will require non-trivial refactoring to defer install generator creation to generate time. For now simply restore the old behavior of installing the framework to the library destination. Fixes: #18848
-rw-r--r--Source/cmInstallTargetGenerator.cxx25
-rw-r--r--Tests/RunCMake/Framework/InstallBeforeFramework.cmake5
-rw-r--r--Tests/RunCMake/Framework/RunCMakeTest.cmake2
3 files changed, 30 insertions, 2 deletions
diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx
index 8b8f79b98a..bf0217a6e8 100644
--- a/Source/cmInstallTargetGenerator.cxx
+++ b/Source/cmInstallTargetGenerator.cxx
@@ -210,8 +210,29 @@ void cmInstallTargetGenerator::GenerateScriptForConfig(
// An import library looks like a static library.
type = cmInstallType_STATIC_LIBRARY;
} else if (this->Target->IsFrameworkOnApple()) {
- // There is a bug in cmInstallCommand if this fails.
- assert(this->NamelinkMode == NamelinkModeNone);
+ // FIXME: In principle we should be able to
+ // assert(this->NamelinkMode == NamelinkModeNone);
+ // but since the current install() command implementation checks
+ // the FRAMEWORK property immediately instead of delaying until
+ // generate time, it is possible for project code to set the
+ // property after calling install(). In such a case, the install()
+ // command will use the LIBRARY code path and create two install
+ // generators, one for the namelink component (NamelinkModeOnly)
+ // and one for the primary artifact component (NamelinkModeSkip).
+ // Historically this was not diagnosed and resulted in silent
+ // installation of a framework to the LIBRARY destination.
+ // Retain that behavior.
+ switch (this->NamelinkMode) {
+ case NamelinkModeNone:
+ // Normal case.
+ break;
+ case NamelinkModeOnly:
+ // Assume the NamelinkModeSkip instance will install.
+ return;
+ case NamelinkModeSkip: {
+ // Proceed to install in the LIBRARY destination for compatibility.
+ } break;
+ }
// Install the whole framework directory.
type = cmInstallType_DIRECTORY;
diff --git a/Tests/RunCMake/Framework/InstallBeforeFramework.cmake b/Tests/RunCMake/Framework/InstallBeforeFramework.cmake
new file mode 100644
index 0000000000..3791dace79
--- /dev/null
+++ b/Tests/RunCMake/Framework/InstallBeforeFramework.cmake
@@ -0,0 +1,5 @@
+enable_language(C)
+
+add_library(foo SHARED foo.c)
+install(TARGETS foo LIBRARY DESTINATION lib)
+set_property(TARGET foo PROPERTY FRAMEWORK TRUE)
diff --git a/Tests/RunCMake/Framework/RunCMakeTest.cmake b/Tests/RunCMake/Framework/RunCMakeTest.cmake
index 4fc83f801d..e705a31fa1 100644
--- a/Tests/RunCMake/Framework/RunCMakeTest.cmake
+++ b/Tests/RunCMake/Framework/RunCMakeTest.cmake
@@ -1,5 +1,7 @@
include(RunCMake)
+run_cmake(InstallBeforeFramework)
+
function(framework_layout_test Name Toolchain Type)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${Toolchain}${Type}FrameworkLayout-build)
set(RunCMake_TEST_NO_CLEAN 1)