[cmake-developers] Adding Swift support to CMake for Linux/Makefiles

Brad King brad.king at kitware.com
Tue Jan 19 11:28:59 EST 2016


On 01/18/2016 01:51 PM, Eric Wing wrote:
> So the good news is I have a basic add_executable working with Swift
> on Linux via the Makefile generator.
> 
> It works with all Swift files, or intermixed C+Swift files. Bridging
> header is also supported.

Great!

> - I’m still copying over some CFLAGS to Swift_FLAGS. For example, I
> couldn’t figure out what was providing the ‘-I’ flag for include
> paths. Rules like this still need to be rewritten for Swift.

Try adding to CMakeSwiftInformation:

 set(CMAKE_INCLUDE_FLAG_Swift -I)

> - TODO: I need to look at Swift's DEFINE system.

Yes.  After we get things building correctly the first time then we'll
also need to see about adding needed dependencies to the build system.

> - Note: The new file is Linux-unknown-Swift.cmake. When I compile
> Swift myself, there is no company or organization identifier (swift
> --version) unlike the one Apple ships with Xcode, and CMake refers to
> the identifier as ‘unknown’. I made the file reflect this, but maybe
> we should rename this later (maybe Swift_org).

In an earlier Swift thread there was discussion about the name of the
compiler id and ``Apple`` was chosen because that is the vendor of
their version.  We definitely need to choose an id besides "unknown"
for this.  Perhaps ``SwiftOrg``?  Also, we need a good way to check
the id.  We could use `--version` if necessary but do we know whether
the language provides any kind of identifier for code to use for
conditional compilation?

> - To answer your question about whether ‘swift’ instead of ’swiftc’
> can be used for linking, I think the answer is yes, but I have been
> unable to figure out the correct incantation.

Okay.  Let's go with the ``<CMAKE_Swift_COMPILER>c`` hack until we
know more.  I'd prefer not to have to expose a separate setting for
the link driver only to remove it later.

> - Swift Standard (or Core) Libraries: Swift comes with multiple
> standard libraries.
[snip]
> I think CMake should provide some variables to the full paths to
> these libraries since users like me will want to refer to them.

Perhaps, but we currently don't do that for any other languages.
We do provide CMAKE_{C,CXX,Fortran}_IMPLICIT_LINK_DIRECTORIES
listing directories that may contain the standard libraries.
This is the same as the information needed to use the C linker
to mix languages that we previously discussed trying to extract
for Swift.

-Brad



More information about the cmake-developers mailing list