Skip to content

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

Closed
@charles-liang

Description

@charles-liang

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions