mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-17 15:32:10 +08:00
find_program: Properly decode URL for bundle exe name with spaces
Fixes: #20817
This commit is contained in:
@@ -266,14 +266,13 @@ std::string cmFindProgramCommand::GetBundleExecutable(
|
|||||||
|
|
||||||
if (executableURL != nullptr) {
|
if (executableURL != nullptr) {
|
||||||
const int MAX_OSX_PATH_SIZE = 1024;
|
const int MAX_OSX_PATH_SIZE = 1024;
|
||||||
char buffer[MAX_OSX_PATH_SIZE];
|
UInt8 buffer[MAX_OSX_PATH_SIZE];
|
||||||
|
|
||||||
// Convert the CFString to a C string
|
if (CFURLGetFileSystemRepresentation(executableURL, false, buffer,
|
||||||
CFStringGetCString(CFURLGetString(executableURL), buffer,
|
MAX_OSX_PATH_SIZE)) {
|
||||||
MAX_OSX_PATH_SIZE, kCFStringEncodingUTF8);
|
executable = bundlePath + "/Contents/MacOS/" +
|
||||||
|
std::string(reinterpret_cast<char*>(buffer));
|
||||||
// And finally to a c++ string
|
}
|
||||||
executable = bundlePath + "/Contents/MacOS/" + std::string(buffer);
|
|
||||||
// Only release CFURLRef if it's not null
|
// Only release CFURLRef if it's not null
|
||||||
CFRelease(executableURL);
|
CFRelease(executableURL);
|
||||||
}
|
}
|
||||||
|
1
Tests/RunCMake/find_program/BundleSpaceInName-stdout.txt
Normal file
1
Tests/RunCMake/find_program/BundleSpaceInName-stdout.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
-- FakeApp_EXECUTABLE='.*/Tests/RunCMake/find_program/BundleSpaceInName-build/Fake app.app/Contents/MacOS/Fake app'
|
8
Tests/RunCMake/find_program/BundleSpaceInName.cmake
Normal file
8
Tests/RunCMake/find_program/BundleSpaceInName.cmake
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
set(fakeApp "${CMAKE_CURRENT_BINARY_DIR}/Fake app.app/Contents/MacOS/Fake app")
|
||||||
|
file(WRITE "${fakeApp}" "#!/bin/sh\n")
|
||||||
|
execute_process(COMMAND chmod a+rx "${fakeApp}")
|
||||||
|
|
||||||
|
find_program(FakeApp_EXECUTABLE NAMES "Fake app" NO_DEFAULT_PATH
|
||||||
|
PATHS "${CMAKE_CURRENT_BINARY_DIR}"
|
||||||
|
)
|
||||||
|
message(STATUS "FakeApp_EXECUTABLE='${FakeApp_EXECUTABLE}'")
|
@@ -14,3 +14,7 @@ endif()
|
|||||||
if(UNIX)
|
if(UNIX)
|
||||||
run_cmake(ExeNoRead)
|
run_cmake(ExeNoRead)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(APPLE)
|
||||||
|
run_cmake(BundleSpaceInName)
|
||||||
|
endif()
|
||||||
|
Reference in New Issue
Block a user