Skip to content

Add workaround for building executables with older CMake versions. #619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2021

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented Apr 28, 2021

Some time between CMake 3.16 and 3.17 the default behaviour seems to have changed as follows:
For a project which will build an executable, e.g.:

add_executable(exe_target
    main.swift)
target_link_libraries(exe_target PUBLIC
    libA
    libB)

In 3.17, the invocation command to create the exe_target executable includes -Xlinker -rpath -Xlinkier <libA_path/lib> and so forth for the linked libraries and their dependencies.
In 3.16, the linker is not passed the rpath flags, so the executable ends up without the LC_RPATH required for it to run.
This affects executable targets only, libraries do still have rpaths propagated correctly.

The correct solution (which will hopefully happen soon) is to bump the compiler's minimum CMake version to 3.18.
This is under discussion now here: https://forums.swift.org/t/bump-cmake-version-to-3-18

@artemcm
Copy link
Contributor Author

artemcm commented Apr 28, 2021

@swift-ci please test

@artemcm
Copy link
Contributor Author

artemcm commented Apr 29, 2021

It's looking like this PR:
swiftlang/swift#36094
Is moving ahead so it'll be better to have that merged to avoid introducing this kind of workaround.

We should also bump the corresponding required CMake on this repository though, I'll put up a PR.

@artemcm
Copy link
Contributor Author

artemcm commented Apr 30, 2021

Closing in favour of:
#624

@artemcm artemcm closed this Apr 30, 2021
@artemcm
Copy link
Contributor Author

artemcm commented May 6, 2021

I'm going to re-open because the CMake version bump logistics will require more orchestration and I would like to merge the respective swift PR. I will track removing this code once we update the required CMake in a way that makes it redundant.

@artemcm artemcm reopened this May 6, 2021
@artemcm
Copy link
Contributor Author

artemcm commented May 6, 2021

@swift-ci please test

1 similar comment
@artemcm
Copy link
Contributor Author

artemcm commented May 6, 2021

@swift-ci please test

Some time between CMake 3.16 and 3.17 the default behaviour seems to have changed as follows:
For a project which will build an executable, e.g.:
```
add_executable(exe_target
    main.swift)
target_link_libraries(exe_target PUBLIC
    libA
    libB)
```
In 3.17, the invocation command to create the `exe_target` executable includes `-Xlinker -rpath -Xlinkier <libA_path/lib>` and so forth for the linked libraries and their dependencies.
In 3.16, the linker is not passed the rpath flags, so the executable ends up without the `LC_RPATH` required for it to run.
This affects executable targets only, libraries do still have rpaths propagated correctly.
@artemcm artemcm force-pushed the WorkaroundOlderCMake branch from e46ccc7 to 444d48f Compare May 6, 2021 21:49
@artemcm
Copy link
Contributor Author

artemcm commented May 6, 2021

Just re-basing to get cross-repo testing to pick up the right changes.

@swift-ci please test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants