mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-01 20:00:51 -05:00
VS: Restore compilation of '.C' sources as C++
Refactoring in commit 3b547e2e4b (VS: Simplify logic adding source file
C/C++ language flag to MSVC, 2020-05-15, v3.18.0-rc1~139^2~1) failed to
account for MSVC's treatment of `.C` extensions as C. Add this special
case to the logic to restore use of `-TP` for `.C` extensions.
Fixes: #20822
This commit is contained in:
@@ -2321,11 +2321,14 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Force language if the file extension does not match.
|
// Force language if the file extension does not match.
|
||||||
|
// Note that MSVC treats the upper-case '.C' extension as C and not C++.
|
||||||
|
std::string const ext = sf.GetExtension();
|
||||||
|
std::string const extLang = ext == "C"
|
||||||
|
? "C"
|
||||||
|
: this->GlobalGenerator->GetLanguageFromExtension(ext.c_str());
|
||||||
std::string lang = this->LocalGenerator->GetSourceFileLanguage(sf);
|
std::string lang = this->LocalGenerator->GetSourceFileLanguage(sf);
|
||||||
const char* compileAs = 0;
|
const char* compileAs = 0;
|
||||||
if (lang !=
|
if (lang != extLang) {
|
||||||
this->GlobalGenerator->GetLanguageFromExtension(
|
|
||||||
sf.GetExtension().c_str())) {
|
|
||||||
if (lang == "CXX") {
|
if (lang == "CXX") {
|
||||||
// force a C++ file type
|
// force a C++ file type
|
||||||
compileAs = "CompileAsCpp";
|
compileAs = "CompileAsCpp";
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ set(CMAKE_DEBUG_POSTFIX "_test_debug_postfix")
|
|||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(EXTRA_SRCS test.CPP)
|
set(EXTRA_SRCS test.CPP)
|
||||||
endif()
|
endif()
|
||||||
add_library(testcxx1.my STATIC libcxx1.cxx ${EXTRA_SRCS})
|
add_library(testcxx1.my STATIC libcxx1.cxx test.C ${EXTRA_SRCS})
|
||||||
add_library(testcxx2 SHARED libcxx2.cxx)
|
add_library(testcxx2 SHARED libcxx2.cxx)
|
||||||
add_executable (CxxOnly cxxonly.cxx)
|
add_executable (CxxOnly cxxonly.cxx)
|
||||||
target_link_libraries(CxxOnly testcxx1.my testcxx2)
|
target_link_libraries(CxxOnly testcxx1.my testcxx2)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "libcxx1.h"
|
#include "libcxx1.h"
|
||||||
#include "libcxx2.h"
|
#include "libcxx2.h"
|
||||||
|
extern int testC;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
extern int testCPP;
|
extern int testCPP;
|
||||||
#endif
|
#endif
|
||||||
@@ -8,6 +9,7 @@ extern int testCPP;
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
testC = 1;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
testCPP = 1;
|
testCPP = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
int testC;
|
||||||
Reference in New Issue
Block a user