Swift executables with MACOSX_BUNDLE fail to find libswiftCore.dylib

Swift executables with MACOSX_BUNDLE fail to find libswiftCore.dylib

When making a pure Swift bundle Xcode automatically copies `libswiftCore.dylib` as follows.

```

./Tests/SwiftOnly/Debug/SwiftOnly.app

└── Contents

├── Frameworks

│ └── libswiftCore.dylib

├── Info.plist

├── MacOS

│ └── SwiftOnly

├── PkgInfo

└── Resources

└── libswiftRemoteMirror.dylib

```

When I try to run the output I get a dynamic linking error. I can reproduce this by adding MACOSX_BUNDLE to `./Tests/SwiftOnly/CMakeLists.txt` (in the CMake source tree) in `add_executable` and trying to run
the result.

It seems that the rpath should be set to `@loader_path/../Frameworks`. I am not a Swift maestro so not exactly sure on the details of how this works. After running `install_name_tool -add_rpath "@loader_path/../Frameworks"
./Tests/SwiftOnly/Debug/SwiftOnly.app/Contents/MacOS/SwiftOnly` it runs fine.

Does anyone have any idea what to do? Is it a missing CMake Swift feature? We are currently working around it by manually adding the rpath with a cmake step.

When making a pure Swift bundle Xcode automatically copies `libswiftCore.dylib` as follows.

```

./Tests/SwiftOnly/Debug/SwiftOnly.app

└── Contents

├── Frameworks

│ └── libswiftCore.dylib

├── Info.plist

├── MacOS

│ └── SwiftOnly

├── PkgInfo

└── Resources

└── libswiftRemoteMirror.dylib

```

When I try to run the output I get a dynamic linking error. I can reproduce this by adding MACOSX_BUNDLE to `./Tests/SwiftOnly/CMakeLists.txt` (in the CMake source tree) in `add_executable` and trying to run
the result.

It seems that the rpath should be set to `@loader_path/../Frameworks`. I am not a Swift maestro so not exactly sure on the details of how this works. After running `install_name_tool -add_rpath "@loader_path/../Frameworks"
./Tests/SwiftOnly/Debug/SwiftOnly.app/Contents/MacOS/SwiftOnly` it runs fine.

Does anyone have any idea what to do? Is it a missing CMake Swift feature? We are currently working around it by manually adding the rpath with a cmake step.

When making a pure Swift bundle Xcode automatically copies `libswiftCore.dylib` as follows.

```

./Tests/SwiftOnly/Debug/SwiftOnly.app

└── Contents

├── Frameworks

│ └── libswiftCore.dylib

├── Info.plist

├── MacOS

│ └── SwiftOnly

├── PkgInfo

└── Resources

└── libswiftRemoteMirror.dylib

```

When I try to run the output I get a dynamic linking error. I can reproduce this by adding MACOSX_BUNDLE to `./Tests/SwiftOnly/CMakeLists.txt`
(in the CMake source tree) in `add_executable` and trying to run the result.

It seems that the rpath should be set to `@loader_path/../Frameworks`. I am not a Swift maestro so not exactly sure on the details of
how this works. After running `install_name_tool -add_rpath "@loader_path/../Frameworks" ./Tests/SwiftOnly/Debug/SwiftOnly.app/Contents/MacOS/SwiftOnly` it runs fine.

Does anyone have any idea what to do? Is it a missing CMake Swift feature? We are currently working around it by manually adding the
rpath with a cmake step.

If full support for Swift was added to CMake yes why not. But I’m not a CMake developer and considering current Swift support it’s a bit early I think. I mean Swift support should come as a global feature, not just this specific point.

When making a pure Swift bundle Xcode automatically copies `libswiftCore.dylib` as follows.

```

./Tests/SwiftOnly/Debug/SwiftOnly.app

└── Contents

├── Frameworks

│ └── libswiftCore.dylib

├── Info.plist

├── MacOS

│ └── SwiftOnly

├── PkgInfo

└── Resources

└── libswiftRemoteMirror.dylib

```

When I try to run the output I get a dynamic linking error. I can reproduce this by adding MACOSX_BUNDLE to `./Tests/SwiftOnly/CMakeLists.txt`
(in the CMake source tree) in `add_executable` and trying to run the result.

It seems that the rpath should be set to `@loader_path/../Frameworks`. I am not a Swift maestro so not exactly sure on the details of
how this works. After running `install_name_tool -add_rpath "@loader_path/../Frameworks" ./Tests/SwiftOnly/Debug/SwiftOnly.app/Contents/MacOS/SwiftOnly` it runs fine.

Does anyone have any idea what to do? Is it a missing CMake Swift feature? We are currently working around it by manually adding the
rpath with a cmake step.