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

Eric Wing ewmailing at gmail.com
Fri Jan 29 15:16:26 EST 2016


On 1/20/16, Brad King <brad.king at kitware.com> wrote:
> On 01/20/2016 08:48 AM, Eric Wing wrote:
>> I thought maybe setting the internal
>> CMAKE_${lang}_COMPILER_ID_FLAGS_LIST or
>> CMAKE_${lang}_COMPILER_ID_FLAGS
>> to "-version" would fix this.
>>
>> But this did nothing.
>
> Those are internal details of the CMAKE_DETERMINE_COMPILER_ID
> function and are not meant to be set anywhere else.  I think you
> may be looking for something like this:
>
> https://cmake.org/gitweb?p=cmake.git;a=blob;f=Modules/CMakeDetermineFortranCompiler.cmake;hb=v3.4.2#l122
>
> It is used by the CMAKE_DETERMINE_COMPILER_ID_VENDOR fallback when
> the compiler id cannot be extracted from the basic compiler output.
> More work may be needed to also extract a version number through
> the CMAKE_DETERMINE_COMPILER_ID_VENDOR infrastructure.

I need more guidance here. I'm not connecting the dots.
My problem seems to be that the execute_process() in
CMakeDetermineCompilerId.cmake is trying to invoke the command:
'swift CompilerId/main.swift'

This will cause swift to run in REPL mode which won't return.
It is not passing any of the flags I taught CMake to use when trying
to compile a Swift program.

Looking at the execute_process() that gets invoked (final one in the
big if/elseif block of CMAKE_DETERMINE_COMPILER_ID_BUILD), the only
way to get the flags I need are via CMAKE_${lang}_COMPILER_ID_FLAGS.
But there is a block at the top of the file which overwrites the
variables. I was suggesting list(APPEND) instead of set() would fix
that problem, and in fact look suspicious to me since there is no way
to access those values passed to execute_process().

  if(CMAKE_${lang}_FLAGS)
    #set(CMAKE_${lang}_COMPILER_ID_FLAGS ${CMAKE_${lang}_FLAGS})
    list(APPEND CMAKE_${lang}_COMPILER_ID_FLAGS ${CMAKE_${lang}_FLAGS})
  else()
#    set(CMAKE_${lang}_COMPILER_ID_FLAGS $ENV{${flagvar}})
    list(APPEND CMAKE_${lang}_COMPILER_ID_FLAGS $ENV{${flagvar}})
  endif()



>
> Yes.  One remaining question is if there is an established convention
> already out there for the name of the SWIFTFLAGS environment variable.
>

I haven't spotted anything so far. Remember that Xcode and anything
GUI based on Mac doesn't use environmental variables. So this isn't a
feature that the existing Apple community would be using.


Thanks,
Eric


More information about the cmake-developers mailing list