From 8bd98b8117c31ee797b33fbf04ebfc03942ea15e Mon Sep 17 00:00:00 2001 From: Ben Leadbetter Date: Thu, 30 Jun 2022 11:00:59 +0100 Subject: Genex: Fix TARGET_BUNDLE_DIR_NAME incorrect extension Fix the genex from commit 997af2e1a6 (Genex: Add TARGET_BUNDLE_DIR_NAME, 2022-04-14, v3.24.0-rc1~233^2) to use the correct bundle directory extension for each bundle type. Fixes: #23683 --- Source/cmGeneratorExpressionNode.cxx | 14 +++++++-- .../RunCMake/GenEx-TARGET_FILE/RunCMakeTest.cmake | 3 ++ .../TARGET_BUNDLE_DIR_NAME-check.cmake | 1 + .../GenEx-TARGET_FILE/TARGET_BUNDLE_DIR_NAME.cmake | 33 ++++++++++++++++++++++ 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 Tests/RunCMake/GenEx-TARGET_FILE/TARGET_BUNDLE_DIR_NAME-check.cmake create mode 100644 Tests/RunCMake/GenEx-TARGET_FILE/TARGET_BUNDLE_DIR_NAME.cmake diff --git a/Source/cmGeneratorExpressionNode.cxx b/Source/cmGeneratorExpressionNode.cxx index b08cddb..d773fdf 100644 --- a/Source/cmGeneratorExpressionNode.cxx +++ b/Source/cmGeneratorExpressionNode.cxx @@ -2763,8 +2763,18 @@ struct TargetFilesystemArtifactResultCreator return std::string(); } - return target->GetAppBundleDirectory(context->Config, - cmGeneratorTarget::BundleDirLevel); + auto level = cmGeneratorTarget::BundleDirLevel; + auto config = context->Config; + if (target->IsAppBundleOnApple()) { + return target->GetAppBundleDirectory(config, level); + } + if (target->IsFrameworkOnApple()) { + return target->GetFrameworkDirectory(config, level); + } + if (target->IsCFBundleOnApple()) { + return target->GetCFBundleDirectory(config, level); + } + return std::string(); } }; diff --git a/Tests/RunCMake/GenEx-TARGET_FILE/RunCMakeTest.cmake b/Tests/RunCMake/GenEx-TARGET_FILE/RunCMakeTest.cmake index 148baac..a79fcaf 100644 --- a/Tests/RunCMake/GenEx-TARGET_FILE/RunCMakeTest.cmake +++ b/Tests/RunCMake/GenEx-TARGET_FILE/RunCMakeTest.cmake @@ -2,6 +2,9 @@ include(RunCMake) run_cmake(TARGET_FILE-recursion) run_cmake(OUTPUT_NAME-recursion) +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + run_cmake(TARGET_BUNDLE_DIR_NAME) +endif() run_cmake(TARGET_FILE_DIR-dependency) run_cmake(TARGET_FILE_DIR-no-dependency) run_cmake(TARGET_FILE_PREFIX-imported-target) diff --git a/Tests/RunCMake/GenEx-TARGET_FILE/TARGET_BUNDLE_DIR_NAME-check.cmake b/Tests/RunCMake/GenEx-TARGET_FILE/TARGET_BUNDLE_DIR_NAME-check.cmake new file mode 100644 index 0000000..6e62ce3 --- /dev/null +++ b/Tests/RunCMake/GenEx-TARGET_FILE/TARGET_BUNDLE_DIR_NAME-check.cmake @@ -0,0 +1 @@ +include ("${RunCMake_TEST_BINARY_DIR}/TARGET_BUNDLE_DIR_NAME-generated.cmake") diff --git a/Tests/RunCMake/GenEx-TARGET_FILE/TARGET_BUNDLE_DIR_NAME.cmake b/Tests/RunCMake/GenEx-TARGET_FILE/TARGET_BUNDLE_DIR_NAME.cmake new file mode 100644 index 0000000..23db8fd --- /dev/null +++ b/Tests/RunCMake/GenEx-TARGET_FILE/TARGET_BUNDLE_DIR_NAME.cmake @@ -0,0 +1,33 @@ +enable_language(C) + +set(GENERATE_CONTENT [[ +macro (check_value test_msg value expected) + if (NOT "${value}" STREQUAL "${expected}") + string (APPEND RunCMake_TEST_FAILED "${test_msg}: actual result:\n [${value}]\nbut expected:\n [${expected}]\n") + endif() +endmacro() +]]) + +add_library(test-lib MODULE empty.c) +set_target_properties(test-lib PROPERTIES BUNDLE TRUE) + +add_library(test-fw empty.c) +set_target_properties(test-fw PROPERTIES FRAMEWORK TRUE) + +add_executable(test-app MACOSX_BUNDLE empty.c) + +add_executable(test-app-custom MACOSX_BUNDLE empty.c) +set_target_properties(test-app-custom PROPERTIES BUNDLE_EXTENSION custom) + +string(APPEND GENERATE_CONTENT [[ +check_value("TARGET_BUNDLE_DIR_NAME library" "$" "test-lib.bundle") +check_value("TARGET_BUNDLE_DIR_NAME framework" "$" "test-fw.framework") +check_value("TARGET_BUNDLE_DIR_NAME app" "$" "test-app.app") +check_value("TARGET_BUNDLE_DIR_NAME custom" "$" "test-app-custom.custom") +]]) + +file( + GENERATE + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/TARGET_BUNDLE_DIR_NAME-generated.cmake" + CONTENT "${GENERATE_CONTENT}" +) -- cgit v0.12