mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 21:31:08 -06:00
Merge topic 'static'
9e829779f2 Swift: preserve `-static` for static library swiftmodules
Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !9141
This commit is contained in:
@@ -1987,6 +1987,18 @@ void cmNinjaTargetGenerator::WriteSwiftObjectBuildStatement(
|
||||
return !isMultiThread && compileMode == cmSwiftCompileMode::Wholemodule;
|
||||
}();
|
||||
|
||||
// Without `-emit-library` or `-emit-executable`, targets with a single
|
||||
// source file parse as a Swift script instead of like normal source. For
|
||||
// non-executable targets, append this to ensure that they are parsed like a
|
||||
// normal source.
|
||||
if (target.GetType() != cmStateEnums::EXECUTABLE) {
|
||||
this->LocalGenerator->AppendFlags(vars["FLAGS"], "-parse-as-library");
|
||||
}
|
||||
|
||||
if (target.GetType() == cmStateEnums::STATIC_LIBRARY) {
|
||||
this->LocalGenerator->AppendFlags(vars["FLAGS"], "-static");
|
||||
}
|
||||
|
||||
// Swift modules only make sense to emit from things that can be imported.
|
||||
// Executables that don't export symbols can't be imported, so don't try to
|
||||
// emit a swiftmodule for them. It will break.
|
||||
@@ -2011,14 +2023,6 @@ void cmNinjaTargetGenerator::WriteSwiftObjectBuildStatement(
|
||||
vars["FLAGS"], cmStrCat(libraryLinkNameFlag, ' ', libraryLinkName));
|
||||
}
|
||||
|
||||
// Without `-emit-library` or `-emit-executable`, targets with a single
|
||||
// source file parse as a Swift script instead of like normal source. For
|
||||
// non-executable targets, append this to ensure that they are parsed like a
|
||||
// normal source.
|
||||
if (target.GetType() != cmStateEnums::EXECUTABLE) {
|
||||
this->LocalGenerator->AppendFlags(vars["FLAGS"], "-parse-as-library");
|
||||
}
|
||||
|
||||
this->LocalGenerator->AppendFlags(vars["FLAGS"],
|
||||
this->GetFlags(language, config));
|
||||
vars["DEFINES"] = this->GetDefines(language, config);
|
||||
|
||||
@@ -76,6 +76,12 @@ elseif(RunCMake_GENERATOR STREQUAL Ninja)
|
||||
# -v: verbose to capture executed commands -n: dry-run to avoid actually compiling
|
||||
run_cmake_command(ForceResponseFile-check ${CMAKE_COMMAND} --build ${ForceResponseFile_TEST_BINARY_DIR} -- -vn)
|
||||
endblock()
|
||||
|
||||
block()
|
||||
set(SwiftLibraryModuleCommand_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/SwiftLibraryModuleCommand-build)
|
||||
run_cmake(SwiftLibraryModuleCommand)
|
||||
run_cmake_command(SwiftLibraryModuleCommand-check ${CMAKE_COMMAND} --build ${SwiftLibraryModuleCommand_TEST_BINARY_DIR} -- -n -v)
|
||||
endblock()
|
||||
endif()
|
||||
elseif(RunCMake_GENERATOR STREQUAL "Ninja Multi-Config")
|
||||
if(CMake_TEST_Swift)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
.*swiftc(.exe)? .* -parse-as-library -static -emit-module .* -module-name StaticLibrary [^
|
||||
]*
|
||||
.*swiftc(.exe)? .* -parse-as-library -emit-module .* -module-name DynamicLibrary
|
||||
8
Tests/RunCMake/Swift/SwiftLibraryModuleCommand.cmake
Normal file
8
Tests/RunCMake/Swift/SwiftLibraryModuleCommand.cmake
Normal file
@@ -0,0 +1,8 @@
|
||||
if(POLICY CMP0157)
|
||||
cmake_policy(SET CMP0157 NEW)
|
||||
endif()
|
||||
|
||||
enable_language(Swift)
|
||||
|
||||
add_library(StaticLibrary STATIC L.swift)
|
||||
add_library(DynamicLibrary SHARED L.swift)
|
||||
Reference in New Issue
Block a user