Skip to content

Commit c26edd4

Browse files
committed
Fix macOS bundled Python lookup for the shapeworks CLI
The CLI binary installed at install/bin/shapeworks lives outside the .app, so find_bundled_python_home()'s ../Resources/Python lookup didn't resolve and the CLI silently fell back to the conda prefix baked into the binary. Relocate the CLI into ShapeWorksStudio.app/Contents/MacOS/ during the post-macdeployqt install step, with RPATH set for that location, and leave a thin wrapper at install/bin/shapeworks so package.sh, docs, and existing invocations of `shapeworks` keep working unchanged.
1 parent 329e2cf commit c26edd4

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

Applications/shapeworks/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ set_target_properties(shapeworks_exe PROPERTIES
3535
#ENABLE_EXPORTS TRUE # needed to enable dependency of shapeworksTests (fixme: doesn't work with gcc, but works with Xcode)
3636
# https://gitlab.kitware.com/cmake/cmake/-/issues/19527
3737
)
38+
39+
if(APPLE AND USE_BUNDLED_PYTHON)
40+
# The CLI is relocated into ShapeWorksStudio.app/Contents/MacOS/ at install time
41+
# (see cmake/InstallBundledPython.cmake) so its bundled-Python lookup at
42+
# ../Resources/Python resolves. Link it with RPATH for that final location.
43+
set_property(
44+
TARGET shapeworks_exe
45+
PROPERTY INSTALL_RPATH
46+
"@executable_path/../Frameworks"
47+
"@executable_path/../Resources/Python/lib"
48+
)
49+
endif()
50+
3851
install(TARGETS shapeworks_exe
3952
ARCHIVE DESTINATION bin
4053
RUNTIME DESTINATION bin

cmake/InstallBundledPython.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,38 @@ else()
381381
" COMPONENT Runtime)
382382
endif()
383383

384+
# ---------------------------------------------------------------------------
385+
# 7. macOS: relocate the shapeworks CLI into the .app so its bundled-Python
386+
# lookup (../Resources/Python relative to the executable) resolves.
387+
# Leaves a thin wrapper at install/bin/shapeworks for backward compatibility.
388+
# ---------------------------------------------------------------------------
389+
if(APPLE)
390+
# Generate wrapper script at configure time using bracket syntax
391+
# (avoids escape gymnastics inside install(CODE))
392+
set(_cli_wrapper_dir "${CMAKE_BINARY_DIR}/_bundled_python/cli_wrapper")
393+
file(MAKE_DIRECTORY "${_cli_wrapper_dir}")
394+
file(WRITE "${_cli_wrapper_dir}/shapeworks"
395+
[=[#!/bin/bash
396+
LOC="`dirname "$0"`"
397+
"${LOC}/ShapeWorksStudio.app/Contents/MacOS/shapeworks" "$@"
398+
]=])
399+
400+
# Move the CLI binary into the .app after macdeployqt runs
401+
install(CODE "
402+
set(_install_root \"\$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}\")
403+
set(_cli_src \"\${_install_root}/bin/shapeworks\")
404+
set(_cli_dest_dir \"\${_install_root}/bin/ShapeWorksStudio.app/Contents/MacOS\")
405+
set(_cli_dest \"\${_cli_dest_dir}/shapeworks\")
406+
if(EXISTS \"\${_cli_src}\" AND NOT IS_SYMLINK \"\${_cli_src}\")
407+
file(MAKE_DIRECTORY \"\${_cli_dest_dir}\")
408+
file(RENAME \"\${_cli_src}\" \"\${_cli_dest}\")
409+
message(STATUS \"Relocated shapeworks CLI into .app/Contents/MacOS/\")
410+
endif()
411+
" COMPONENT Runtime)
412+
413+
# Install the wrapper at install/bin/shapeworks (registered after the move so
414+
# it lands in the now-empty slot rather than overwriting the binary)
415+
install(PROGRAMS "${_cli_wrapper_dir}/shapeworks" DESTINATION bin)
416+
endif()
417+
384418
message(STATUS "InstallBundledPython: will install bundled Python to ${_app_python_dest}")

0 commit comments

Comments
 (0)