CMake 编译 swift 项目

Zoh*_*r81 5 macos compilation objective-c cmake swift

I've tried playing with the idea to compile my mixed swift/objective-c/c++ based project using CMake. So as a starter, I went to SwiftMix example and run the following CMakeList.txt file :

cmake_minimum_required(VERSION 3.3)
project(SwiftMix C Swift)

add_executable(SwiftMix CMain.c ObjCMain.m SwiftMain.swift ObjC-Swift.h)
set_property(TARGET SwiftMix PROPERTY XCODE_ATTRIBUTE_SWIFT_OBJC_BRIDGING_HEADER "ObjC-Swift.h")
Run Code Online (Sandbox Code Playgroud)

After running cmake on the file above, I got the following error :

CMake Error: CMAKE_Swift_COMPILER not set, after EnableLanguage

However, it looks like inside CMake installation (version 3.9.1), there's a file/files which handle the swift support and define the missing variable from the error message :

/usr/local/Cellar/cmake/3.9.1//share/cmake/Modules/CMakeSwiftCompiler.cmake.in

Any idea how can I change the "CMakeLists.txt" to support swift ?

冯剑龙*_*冯剑龙 -2

首先,“Unix Makefiles”生成器不支持 Swift 语言。所以,你必须使用 cmake -G Xcode 。然后,生成Xcode项目,如果不起作用,您可以尝试 sudo xcode-select --reset 或升级您的cmake版本。最后,尝试 cmake -G Xcode 。再次。