mirror of
https://github.com/Kitware/CMake.git
synced 2026-08-05 07:10:26 +00:00
Merge topic 'swift-mix-cxx'
f6ff19cc9dTests: Add mixed Swift+CXX source test case399343486fTests: Add swift compiler version to test checka9509cec7eNinja: Fix mixed Swift/CXX library target generation Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !7679
This commit is contained in:
@@ -1085,10 +1085,12 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement(
|
||||
this->GetGeneratorTarget()->GetObjectSources(sources, config);
|
||||
cmLocalGenerator const* LocalGen = this->GetLocalGenerator();
|
||||
for (const auto& source : sources) {
|
||||
const std::string sourcePath = source->GetLanguage() == "Swift"
|
||||
? this->GetCompiledSourceNinjaPath(source)
|
||||
: this->GetObjectFilePath(source, config);
|
||||
oss << " "
|
||||
<< LocalGen->ConvertToOutputFormat(
|
||||
this->GetCompiledSourceNinjaPath(source),
|
||||
cmOutputConverter::SHELL);
|
||||
<< LocalGen->ConvertToOutputFormat(sourcePath,
|
||||
cmOutputConverter::SHELL);
|
||||
}
|
||||
return oss.str();
|
||||
}();
|
||||
@@ -1106,10 +1108,15 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement(
|
||||
std::vector<cmSourceFile const*> sources;
|
||||
gt->GetObjectSources(sources, config);
|
||||
for (const auto& source : sources) {
|
||||
linkBuild.Outputs.push_back(
|
||||
this->ConvertToNinjaPath(this->GetObjectFilePath(source, config)));
|
||||
linkBuild.ExplicitDeps.emplace_back(
|
||||
this->GetCompiledSourceNinjaPath(source));
|
||||
if (source->GetLanguage() == "Swift") {
|
||||
linkBuild.Outputs.push_back(
|
||||
this->ConvertToNinjaPath(this->GetObjectFilePath(source, config)));
|
||||
linkBuild.ExplicitDeps.emplace_back(
|
||||
this->GetCompiledSourceNinjaPath(source));
|
||||
} else {
|
||||
linkBuild.ExplicitDeps.emplace_back(
|
||||
this->GetObjectFilePath(source, config));
|
||||
}
|
||||
}
|
||||
linkBuild.Outputs.push_back(vars["SWIFT_MODULE"]);
|
||||
} else {
|
||||
|
||||
@@ -394,6 +394,9 @@ if(BUILD_TESTING)
|
||||
if(CMake_TEST_XCODE_SWIFT)
|
||||
ADD_TEST_MACRO(SwiftMix SwiftMix)
|
||||
endif()
|
||||
if(CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 5.1)
|
||||
ADD_TEST_MACRO(SwiftMixLib Swifty)
|
||||
endif()
|
||||
endif()
|
||||
if(CMAKE_Fortran_COMPILER)
|
||||
ADD_TEST_MACRO(FortranOnly FortranOnly)
|
||||
|
||||
@@ -14,6 +14,7 @@ if(NOT DEFINED CMAKE_Swift_COMPILER)
|
||||
project(CheckSwift Swift)
|
||||
file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\"
|
||||
\"set(CMAKE_Swift_COMPILER \\\"\${CMAKE_Swift_COMPILER}\\\")\\n\"
|
||||
\"set(CMAKE_Swift_COMPILER_VERSION \\\"\${CMAKE_Swift_COMPILER_VERSION}\\\")\\n\"
|
||||
\"set(CMAKE_Swift_FLAGS \\\"\${CMAKE_Swift_FLAGS}\\\")\\n\")
|
||||
")
|
||||
|
||||
@@ -54,6 +55,7 @@ file(WRITE \"\${CMAKE_CURRENT_BINARY_DIR}/result.cmake\"
|
||||
message(STATUS "${_desc} - ${CMAKE_Swift_COMPILER}")
|
||||
|
||||
set(CMAKE_Swift_COMPILER "${CMAKE_Swift_COMPILER}" CACHE FILEPATH "Swift compiler")
|
||||
set(CMAKE_Swift_COMPILER_VERSION "${CMAKE_Swift_COMPILER_VERSION}" CACHE FILEPATH "Swift compiler version")
|
||||
set(CMAKE_Swift_FLAGS "${CMAKE_Swift_FLAGS}" CACHE STRING "Swift flags")
|
||||
|
||||
mark_as_advanced(CMAKE_Swift_COMPILER)
|
||||
|
||||
6
Tests/SwiftMixLib/CMakeLists.txt
Normal file
6
Tests/SwiftMixLib/CMakeLists.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
project(SwiftMixLib C CXX Swift)
|
||||
|
||||
add_library(SwiftMixedLib lib.c lib.cpp lib.swift)
|
||||
add_executable(Swifty main.swift)
|
||||
target_link_libraries(Swifty PUBLIC SwiftMixedLib)
|
||||
4
Tests/SwiftMixLib/lib.c
Normal file
4
Tests/SwiftMixLib/lib.c
Normal file
@@ -0,0 +1,4 @@
|
||||
int add_int(int a, int b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
4
Tests/SwiftMixLib/lib.cpp
Normal file
4
Tests/SwiftMixLib/lib.cpp
Normal file
@@ -0,0 +1,4 @@
|
||||
int add(int a, int b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
3
Tests/SwiftMixLib/lib.swift
Normal file
3
Tests/SwiftMixLib/lib.swift
Normal file
@@ -0,0 +1,3 @@
|
||||
public func add(a: Int, b: Int) -> Int {
|
||||
a + b
|
||||
}
|
||||
3
Tests/SwiftMixLib/main.swift
Normal file
3
Tests/SwiftMixLib/main.swift
Normal file
@@ -0,0 +1,3 @@
|
||||
import SwiftMixedLib
|
||||
|
||||
print(add(a: 1, b: 2))
|
||||
Reference in New Issue
Block a user