diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2019-05-31 11:30:58 -0700 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-06-03 14:05:10 -0400 |
commit | b06f4c8a745c96f19a9e9a7c7eb0ac22250472a2 (patch) | |
tree | 16391a388c369be9f7379134ff9583421f7a0ac5 | |
parent | 73472408c501e66c9dd8c027293b8c0907001b42 (diff) | |
download | cmake-b06f4c8a745c96f19a9e9a7c7eb0ac22250472a2.tar.gz |
Swift: disallow WIN32_EXECUTABLE properties
Currently, the compiler does not synthesize the correct entry point for
the application and passing the subsystem flag does not work the same
way with the Swift linker language. Add a check to prevent the
application of `WIN32_EXECUTABLE` to Swift executables until they can be
properly supported. This will prevent the need for a future policy
change.
Closes: #19325
-rw-r--r-- | Source/cmGlobalGenerator.cxx | 35 | ||||
-rw-r--r-- | Source/cmGlobalGenerator.h | 1 | ||||
-rw-r--r-- | Tests/RunCMake/Swift/E.swift | 2 | ||||
-rw-r--r-- | Tests/RunCMake/Swift/RunCMakeTest.cmake | 2 | ||||
-rw-r--r-- | Tests/RunCMake/Swift/Win32ExecutableDisallowed-result.txt | 1 | ||||
-rw-r--r-- | Tests/RunCMake/Swift/Win32ExecutableDisallowed-stderr.txt | 4 | ||||
-rw-r--r-- | Tests/RunCMake/Swift/Win32ExecutableDisallowed.cmake | 4 |
7 files changed, 48 insertions, 1 deletions
diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx index 26886f556c..df0f33fdf0 100644 --- a/Source/cmGlobalGenerator.cxx +++ b/Source/cmGlobalGenerator.cxx @@ -331,6 +331,37 @@ bool cmGlobalGenerator::CheckTargetsForMissingSources() const return failed; } +bool cmGlobalGenerator::CheckTargetsForType() const +{ + if (!this->GetLanguageEnabled("Swift")) { + return false; + } + bool failed = false; + for (cmLocalGenerator* generator : this->LocalGenerators) { + for (cmGeneratorTarget* target : generator->GetGeneratorTargets()) { + std::vector<std::string> configs; + target->Makefile->GetConfigurations(configs); + if (configs.empty()) { + configs.emplace_back(); + } + + for (std::string const& config : configs) { + if (target->GetLinkerLanguage(config) == "Swift") { + if (target->GetPropertyAsBool("WIN32_EXECUTABLE")) { + this->GetCMakeInstance()->IssueMessage( + MessageType::FATAL_ERROR, + "WIN32_EXECUTABLE property is not supported on Swift " + "executables", + target->GetBacktrace()); + failed = true; + } + } + } + } + } + return failed; +} + bool cmGlobalGenerator::IsExportedTargetsFile( const std::string& filename) const { @@ -1414,6 +1445,10 @@ bool cmGlobalGenerator::Compute() return false; } + if (this->CheckTargetsForType()) { + return false; + } + for (cmLocalGenerator* localGen : this->LocalGenerators) { localGen->ComputeHomeRelativeOutputPath(); } diff --git a/Source/cmGlobalGenerator.h b/Source/cmGlobalGenerator.h index dcd8c5f711..db964892a4 100644 --- a/Source/cmGlobalGenerator.h +++ b/Source/cmGlobalGenerator.h @@ -609,6 +609,7 @@ private: virtual void ForceLinkerLanguages(); bool CheckTargetsForMissingSources() const; + bool CheckTargetsForType() const; void CreateLocalGenerators(); diff --git a/Tests/RunCMake/Swift/E.swift b/Tests/RunCMake/Swift/E.swift new file mode 100644 index 0000000000..a41546787b --- /dev/null +++ b/Tests/RunCMake/Swift/E.swift @@ -0,0 +1,2 @@ +func f() { +} diff --git a/Tests/RunCMake/Swift/RunCMakeTest.cmake b/Tests/RunCMake/Swift/RunCMakeTest.cmake index de99042269..4817045541 100644 --- a/Tests/RunCMake/Swift/RunCMakeTest.cmake +++ b/Tests/RunCMake/Swift/RunCMakeTest.cmake @@ -6,7 +6,7 @@ if(RunCMake_GENERATOR STREQUAL Xcode) endif() elseif(RunCMake_GENERATOR STREQUAL Ninja) if(CMAKE_Swift_COMPILER) - # Add Ninja-specific Swift tests here. + run_cmake(Win32ExecutableDisallowed) endif() else() run_cmake(NotSupported) diff --git a/Tests/RunCMake/Swift/Win32ExecutableDisallowed-result.txt b/Tests/RunCMake/Swift/Win32ExecutableDisallowed-result.txt new file mode 100644 index 0000000000..d00491fd7e --- /dev/null +++ b/Tests/RunCMake/Swift/Win32ExecutableDisallowed-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Swift/Win32ExecutableDisallowed-stderr.txt b/Tests/RunCMake/Swift/Win32ExecutableDisallowed-stderr.txt new file mode 100644 index 0000000000..d78101a913 --- /dev/null +++ b/Tests/RunCMake/Swift/Win32ExecutableDisallowed-stderr.txt @@ -0,0 +1,4 @@ +^CMake Error at Win32ExecutableDisallowed.cmake:[0-9]+ \(add_executable\): + WIN32_EXECUTABLE property is not supported on Swift executables +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/Swift/Win32ExecutableDisallowed.cmake b/Tests/RunCMake/Swift/Win32ExecutableDisallowed.cmake new file mode 100644 index 0000000000..02d5447497 --- /dev/null +++ b/Tests/RunCMake/Swift/Win32ExecutableDisallowed.cmake @@ -0,0 +1,4 @@ +enable_language(Swift) +add_executable(E E.swift) +set_target_properties(E PROPERTIES + WIN32_EXECUTABLE TRUE) |