xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
9.87k stars 776 forks source link

Relocation of dylibs in macOS .app Builds with Xcode Rules #5515

Closed charles-liang closed 1 month ago

charles-liang commented 1 month ago

Xmake Version

2.9.4

Operating System Version and Architecture

macOS 15.1 Beta

Describe Bug

In a multi-project setup with a main program and multiple shared libraries, using add_rules("xcode.application") to generate a .app file for macOS. The rpath is set to look in .app/Contents/Frameworks/, but the dylibs are being copied to the .app/Contents/Macos directory. Although it's possible to manually move them each time or write an after_build script to handle the move, it's still a hassle.

Expected Behavior

put libhello.dylib in Frameworks, not in Macos

❯ tree /Users/yao/hanabit/experimental/cpp/xmake/build/macosx/arm64/debug/main.app/Contents/
/Users/yao/hanabit/experimental/cpp/xmake/build/macosx/arm64/debug/main.app/Contents/
├── Frameworks
│   └── libhello.dylib
├── Info.plist
├── MacOS
│   └── main
├── Resources
│   ├── Base.lproj
│   │   └── Main.storyboardc
│   │       ├── Info.plist
│   │       ├── MainMenu.nib
│   │       ├── NSWindowController-B8D-0N-5wS.nib
│   │       └── XfG-lQ-9wD-view-m2S-Jp-Qdl.nib
│   └── PkgInfo
└── _CodeSignature
    └── CodeResources

7 directories, 9 files

Project Configuration

-- - xmake.lua
includes("hello", "main")

-- -- hello/xmake.lua
local target_name = "hello"

set_project(target_name)

target(target_name)
    add_rules("mode.debug", "mode.release")
    add_includedirs("include")
    set_kind("shared")
    add_files("src/*.cpp")
    set_targetdir("$(buildir)/lib/$(plat)/$(arch)/$(mode)")

-- -- main/xmake.lua

local target_name = "main"

set_project(target_name)

target(target_name)
    add_rules("mode.debug", "mode.release")
    add_includedirs("../hello/include")
    set_kind("binary")
    add_files("src/*.cpp")
    add_deps("hello")

platform_dir = "platform/macosx"

if is_plat("macosx") then
    add_rules("xcode.application")
    add_files(platform_dir .. "**.mm")
    add_files(platform_dir .. "**.m")
    add_files(platform_dir .. "**.metal")
    add_files(platform_dir .. "**.storyboard", platform_dir .. "**.xcassets")
    add_files(platform_dir .. "**.plist")
end

Additional Information and Error Logs

❯ tree /Users/yao/hanabit/experimental/cpp/xmake/build/macosx/arm64/debug/main.app/Contents/ /Users/yao/hanabit/experimental/cpp/xmake/build/macosx/arm64/debug/main.app/Contents/ ├── Info.plist ├── MacOS │   ├── libhello.dylib │   └── main ├── Resources │   ├── Base.lproj │   │   └── Main.storyboardc │   │   ├── Info.plist │   │   ├── MainMenu.nib │   │   ├── NSWindowController-B8D-0N-5wS.nib │   │   └── XfG-lQ-9wD-view-m2S-Jp-Qdl.nib │   └── PkgInfo └── _CodeSignature └── CodeResources

6 directories, 9 files

waruqi commented 1 month ago

https://github.com/xmake-io/xmake/pull/5519

try xmake update -s github:xmake-io/xmake#app

charles-liang commented 1 month ago

fixed! Thanks a lot!