Skip to content

[CMake] Updates to allow inclusion using FetchContent #2173

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 8 commits into from
Sep 28, 2023

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Sep 8, 2023

bnbarham and others added 5 commits September 18, 2023 14:44
Various updates that allow swift-syntax to be included using
FetchContent.

Mostly this is just not replacing `target_link_libraries` since that is
a global replacement, but we also now use a couple of variables from the
swift if they're set (eg. `SWIFT_HOST_LIBRARIES_DEST_DIR` and
`SWIFT_HOST_MODULE_TRIPLE`).
This was needed for rewriting RUNPATH. swift now build syntax libraries
via 'FecthcContent', so RUNPATH are not rewritten.
And remove SwiftSyntaxTargets.cmake because it was just a duplication.
@rintaro rintaro marked this pull request as ready for review September 20, 2023 17:43
@rintaro rintaro requested a review from bnbarham as a code owner September 20, 2023 17:43
CMakeLists.txt Outdated
Comment on lines 35 to 37
if(SWIFT_HOST_RUNTIME_DEST_DIR)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${SWIFT_HOST_RUNTIME_DEST_DIR}")
else()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on doing something like this?

if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()

This would allow us to control the behaviour from the FetchContent with the standard CMake options.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooo that's a very good point! That would be much nicer, assuming it works.

elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
set(SWIFT_MODULE_TRIPLE "aarch64-unknown-windows-msvc")
if("${SWIFT_HOST_MODULE_TRIPLE}" STREQUAL "")
# FIXME: This is a hack. It's all a hack. Windows isn't setting
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow this. This is meant to be a user controlled option, what were you expecting? Or is this is a bug CMake that we should also try to get fixed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is just what was already there, I don't think this is a CMake bug. For non-Windows it's all being set via build-script.

Copy link
Contributor

@bnbarham bnbarham Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to expand on this... The reason we need the module triple at all is to output the module in the subfolder format rather than the flat format. Ideally we'll get that fixed at some point in CMake itself 😅. CMAKE_Swift_COMPILER_TARGET is being set in build-script, but I assume that if this was added, it wasn't set for Windows somewhere (in PR testing?). SWIFT_HOST_MODULE_TRIPLE is being passed from the Swift build, so this path would only be taken in the standalone. Not ideal, but also not really anything to do with the fetchcontent change itself.

function(target_link_swift_syntax_libraries TARGET)
cmake_parse_arguments(ARGS "" "" "PUBLIC" ${ARGN})

target_link_libraries(${TARGET} PUBLIC ${ARGS_PUBLIC})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should PUBLIC not be conditional on ${ARGS_PUBLIC}?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a hack. It used to parse dependencies as PUBLIC multi-value arguments.
I updated it because it's was certainly confusing.

@ahoppen ahoppen removed their request for review September 21, 2023 00:30
The argument list handling was a hack and confusing.
@bnbarham
Copy link
Contributor

Thanks! This should make our lives much simpler :)

@rintaro
Copy link
Member Author

rintaro commented Sep 21, 2023

@rintaro rintaro merged commit e0e5ad8 into swiftlang:main Sep 28, 2023
rintaro added a commit to rintaro/swift-syntax that referenced this pull request Sep 29, 2023
[CMake] Updates to allow inclusion using FetchContent

(cherry picked from commit e0e5ad8)

 Conflicts:
	Sources/SwiftDiagnostics/CMakeLists.txt
	Sources/SwiftIDEUtils/CMakeLists.txt
	cmake/modules/AddSwiftHostLibrary.cmake
rintaro added a commit to rintaro/swift-syntax that referenced this pull request Sep 29, 2023
[CMake] Updates to allow inclusion using FetchContent

(cherry picked from commit e0e5ad8)

 Conflicts:
	Sources/SwiftDiagnostics/CMakeLists.txt
	Sources/SwiftIDEUtils/CMakeLists.txt
	cmake/modules/AddSwiftHostLibrary.cmake
rintaro added a commit to rintaro/swift-syntax that referenced this pull request Sep 29, 2023
[CMake] Updates to allow inclusion using FetchContent

(cherry picked from commit e0e5ad8)
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.

3 participants