Merge topic 'swift-mix-cxx'

f6ff19cc9d Tests: Add mixed Swift+CXX source test case
399343486f Tests: Add swift compiler version to test check
a9509cec7e Ninja: Fix mixed Swift/CXX library target generation

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !7679
This commit is contained in:
Brad King
2022-09-21 12:18:43 +00:00
committed by Kitware Robot
8 changed files with 39 additions and 7 deletions

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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)

View 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
View File

@@ -0,0 +1,4 @@
int add_int(int a, int b)
{
return a + b;
}

View File

@@ -0,0 +1,4 @@
int add(int a, int b)
{
return a + b;
}

View File

@@ -0,0 +1,3 @@
public func add(a: Int, b: Int) -> Int {
a + b
}

View File

@@ -0,0 +1,3 @@
import SwiftMixedLib
print(add(a: 1, b: 2))