diff options
author | Brad King <brad.king@kitware.com> | 2022-10-31 13:54:03 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-10-31 13:54:12 (GMT) |
commit | 35a231bf0fbf7930cce6893c2fa7e1242df5afdc (patch) | |
tree | 25afd3cbc6c9dc6c696adf5fa5e3d85d60a50338 | |
parent | 353f850f298693e4445207cc99d1bb8b7661f5cc (diff) | |
parent | e88509d0e87eaa6f41603bfd7b07b653527e88c0 (diff) | |
download | CMake-35a231bf0fbf7930cce6893c2fa7e1242df5afdc.zip CMake-35a231bf0fbf7930cce6893c2fa7e1242df5afdc.tar.gz CMake-35a231bf0fbf7930cce6893c2fa7e1242df5afdc.tar.bz2 |
Merge topic 'ewilde/swift-output-file-map-logic'
e88509d0e8 Swift: Omit output-file-map when used as a linker
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !7835
-rw-r--r-- | Modules/CMakeSwiftInformation.cmake | 6 | ||||
-rw-r--r-- | Source/cmNinjaNormalTargetGenerator.cxx | 8 | ||||
-rw-r--r-- | Source/cmNinjaTargetGenerator.cxx | 54 | ||||
-rw-r--r-- | Source/cmNinjaTargetGenerator.h | 3 | ||||
-rw-r--r-- | Source/cmRulePlaceholderExpander.cxx | 5 | ||||
-rw-r--r-- | Source/cmRulePlaceholderExpander.h | 2 | ||||
-rw-r--r-- | Tests/SwiftMixLib/CMakeLists.txt | 3 | ||||
-rw-r--r-- | Tests/SwiftMixLib/main.c | 3 |
8 files changed, 47 insertions, 37 deletions
diff --git a/Modules/CMakeSwiftInformation.cmake b/Modules/CMakeSwiftInformation.cmake index a0cd9da..62f7ef2 100644 --- a/Modules/CMakeSwiftInformation.cmake +++ b/Modules/CMakeSwiftInformation.cmake @@ -103,7 +103,7 @@ if(NOT CMAKE_Swift_NUM_THREADS MATCHES "^[0-9]+$") endif() if(NOT CMAKE_Swift_CREATE_SHARED_LIBRARY) - set(CMAKE_Swift_CREATE_SHARED_LIBRARY "<CMAKE_Swift_COMPILER> -output-file-map <SWIFT_OUTPUT_FILE_MAP> -j ${CMAKE_Swift_NUM_THREADS} -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <SONAME_FLAG> <TARGET_INSTALLNAME_DIR><TARGET_SONAME> ${CMAKE_Swift_IMPLIB_LINKER_FLAGS} <LINK_LIBRARIES>") + set(CMAKE_Swift_CREATE_SHARED_LIBRARY "<CMAKE_Swift_COMPILER> -j ${CMAKE_Swift_NUM_THREADS} -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <SONAME_FLAG> <TARGET_INSTALLNAME_DIR><TARGET_SONAME> ${CMAKE_Swift_IMPLIB_LINKER_FLAGS} <LINK_LIBRARIES>") endif() if(NOT CMAKE_Swift_CREATE_SHARED_MODULE) @@ -111,11 +111,11 @@ if(NOT CMAKE_Swift_CREATE_SHARED_MODULE) endif() if(NOT CMAKE_Swift_LINK_EXECUTABLE) - set(CMAKE_Swift_LINK_EXECUTABLE "<CMAKE_Swift_COMPILER> -output-file-map <SWIFT_OUTPUT_FILE_MAP> -j ${CMAKE_Swift_NUM_THREADS} -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-executable -o <TARGET> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>") + set(CMAKE_Swift_LINK_EXECUTABLE "<CMAKE_Swift_COMPILER> -j ${CMAKE_Swift_NUM_THREADS} -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-executable -o <TARGET> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>") endif() if(NOT CMAKE_Swift_CREATE_STATIC_LIBRARY) - set(CMAKE_Swift_CREATE_STATIC_LIBRARY "<CMAKE_Swift_COMPILER> -output-file-map <SWIFT_OUTPUT_FILE_MAP> -j ${CMAKE_Swift_NUM_THREADS} -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -static -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>") + set(CMAKE_Swift_CREATE_STATIC_LIBRARY "<CMAKE_Swift_COMPILER> -j ${CMAKE_Swift_NUM_THREADS} -num-threads ${CMAKE_Swift_NUM_THREADS} -emit-library -static -o <TARGET> -module-name <SWIFT_MODULE_NAME> -module-link-name <SWIFT_LIBRARY_NAME> -emit-module -emit-module-path <SWIFT_MODULE> -emit-dependencies <DEFINES> <FLAGS> <INCLUDES> <SWIFT_SOURCES> <LINK_FLAGS> <LINK_LIBRARIES>") set(CMAKE_Swift_ARCHIVE_CREATE "<CMAKE_AR> crs <TARGET> <OBJECTS>") set(CMAKE_Swift_ARCHIVE_FINISH "") diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx index bda8a5f..895a4c3 100644 --- a/Source/cmNinjaNormalTargetGenerator.cxx +++ b/Source/cmNinjaNormalTargetGenerator.cxx @@ -372,7 +372,6 @@ void cmNinjaNormalTargetGenerator::WriteLinkRule(bool useResponseFile, vars.SwiftLibraryName = "$SWIFT_LIBRARY_NAME"; vars.SwiftModule = "$SWIFT_MODULE"; vars.SwiftModuleName = "$SWIFT_MODULE_NAME"; - vars.SwiftOutputFileMap = "$SWIFT_OUTPUT_FILE_MAP"; vars.SwiftSources = "$SWIFT_SOURCES"; vars.Defines = "$DEFINES"; @@ -1072,12 +1071,6 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( cmOutputConverter::SHELL); }(vars["SWIFT_MODULE_NAME"]); - const std::string map = cmStrCat(gt->GetSupportDirectory(), '/', config, - '/', "output-file-map.json"); - vars["SWIFT_OUTPUT_FILE_MAP"] = - this->GetLocalGenerator()->ConvertToOutputFormat( - this->ConvertToNinjaPath(map), cmOutputConverter::SHELL); - vars["SWIFT_SOURCES"] = [this, config]() -> std::string { std::vector<cmSourceFile const*> sources; std::stringstream oss; @@ -1101,6 +1094,7 @@ void cmNinjaNormalTargetGenerator::WriteLinkStatement( vars["DEFINES"] = this->GetDefines("Swift", config); vars["FLAGS"] = this->GetFlags("Swift", config); vars["INCLUDES"] = this->GetIncludes("Swift", config); + this->GenerateSwiftOutputFileMap(config, vars["FLAGS"]); } // Compute specific libraries to link with. diff --git a/Source/cmNinjaTargetGenerator.cxx b/Source/cmNinjaTargetGenerator.cxx index e4427f5..ae6a510 100644 --- a/Source/cmNinjaTargetGenerator.cxx +++ b/Source/cmNinjaTargetGenerator.cxx @@ -1177,30 +1177,42 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements( } this->GetImplFileStream(fileConfig) << "\n"; +} - if (!this->Configs[config].SwiftOutputMap.empty()) { - std::string const mapFilePath = - cmStrCat(this->GeneratorTarget->GetSupportDirectory(), '/', config, '/', - "output-file-map.json"); - std::string const targetSwiftDepsPath = [this, config]() -> std::string { - cmGeneratorTarget const* target = this->GeneratorTarget; - if (cmValue name = target->GetProperty("Swift_DEPENDENCIES_FILE")) { - return *name; - } - return this->ConvertToNinjaPath( - cmStrCat(target->GetSupportDirectory(), '/', config, '/', - target->GetName(), ".swiftdeps")); - }(); +void cmNinjaTargetGenerator::GenerateSwiftOutputFileMap( + const std::string& config, std::string& flags) +{ + if (this->Configs[config].SwiftOutputMap.empty()) { + return; + } - // build the global target dependencies - // https://github.com/apple/swift/blob/master/docs/Driver.md#output-file-maps - Json::Value deps(Json::objectValue); - deps["swift-dependencies"] = targetSwiftDepsPath; - this->Configs[config].SwiftOutputMap[""] = deps; + std::string const targetSwiftDepsPath = [this, config]() -> std::string { + cmGeneratorTarget const* target = this->GeneratorTarget; + if (cmValue name = target->GetProperty("Swift_DEPENDENCIES_FILE")) { + return *name; + } + return this->ConvertToNinjaPath(cmStrCat(target->GetSupportDirectory(), + '/', config, '/', + target->GetName(), ".swiftdeps")); + }(); - cmGeneratedFileStream output(mapFilePath); - output << this->Configs[config].SwiftOutputMap; - } + std::string mapFilePath = + cmStrCat(this->GeneratorTarget->GetSupportDirectory(), '/', config, '/', + "output-file-map.json"); + + // build the global target dependencies + // https://github.com/apple/swift/blob/master/docs/Driver.md#output-file-maps + Json::Value deps(Json::objectValue); + deps["swift-dependencies"] = targetSwiftDepsPath; + this->Configs[config].SwiftOutputMap[""] = deps; + + cmGeneratedFileStream output(mapFilePath); + output << this->Configs[config].SwiftOutputMap; + + // Add flag + this->LocalGenerator->AppendFlags(flags, "-output-file-map"); + this->LocalGenerator->AppendFlagEscape(flags, + ConvertToNinjaPath(mapFilePath)); } namespace { diff --git a/Source/cmNinjaTargetGenerator.h b/Source/cmNinjaTargetGenerator.h index 4b4cf8d..c43b650 100644 --- a/Source/cmNinjaTargetGenerator.h +++ b/Source/cmNinjaTargetGenerator.h @@ -163,6 +163,9 @@ protected: void EmitSwiftDependencyInfo(cmSourceFile const* source, const std::string& config); + void GenerateSwiftOutputFileMap(const std::string& config, + std::string& flags); + void ExportObjectCompileCommand( std::string const& language, std::string const& sourceFileName, std::string const& objectDir, std::string const& objectFileName, diff --git a/Source/cmRulePlaceholderExpander.cxx b/Source/cmRulePlaceholderExpander.cxx index b63d11c..638bb42 100644 --- a/Source/cmRulePlaceholderExpander.cxx +++ b/Source/cmRulePlaceholderExpander.cxx @@ -119,11 +119,6 @@ std::string cmRulePlaceholderExpander::ExpandVariable( return this->ReplaceValues->SwiftModuleName; } } - if (this->ReplaceValues->SwiftOutputFileMap) { - if (variable == "SWIFT_OUTPUT_FILE_MAP") { - return this->ReplaceValues->SwiftOutputFileMap; - } - } if (this->ReplaceValues->SwiftSources) { if (variable == "SWIFT_SOURCES") { return this->ReplaceValues->SwiftSources; diff --git a/Source/cmRulePlaceholderExpander.h b/Source/cmRulePlaceholderExpander.h index 23ec405..5d1f199 100644 --- a/Source/cmRulePlaceholderExpander.h +++ b/Source/cmRulePlaceholderExpander.h @@ -64,7 +64,7 @@ public: const char* SwiftLibraryName = nullptr; const char* SwiftModule = nullptr; const char* SwiftModuleName = nullptr; - const char* SwiftOutputFileMap = nullptr; + const char* SwiftOutputFileMapOption = nullptr; const char* SwiftSources = nullptr; const char* ISPCHeader = nullptr; const char* CudaCompileMode = nullptr; diff --git a/Tests/SwiftMixLib/CMakeLists.txt b/Tests/SwiftMixLib/CMakeLists.txt index 40d3498..a52fc94 100644 --- a/Tests/SwiftMixLib/CMakeLists.txt +++ b/Tests/SwiftMixLib/CMakeLists.txt @@ -4,3 +4,6 @@ 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) + +add_executable(c_main main.c) +target_link_libraries(c_main PUBLIC SwiftMixedLib) diff --git a/Tests/SwiftMixLib/main.c b/Tests/SwiftMixLib/main.c new file mode 100644 index 0000000..6ecf984 --- /dev/null +++ b/Tests/SwiftMixLib/main.c @@ -0,0 +1,3 @@ +int main(int argc, char* argv[]) +{ +} |