diff options
author | Brad King <brad.king@kitware.com> | 2020-06-12 14:06:31 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2020-06-12 14:06:37 (GMT) |
commit | 81ea5eb63753cbba8018d62fbb1d6218868ee8fa (patch) | |
tree | adaa46a964c7f819d1e593a03486754eb2efc7e5 | |
parent | d42011e3cf274b5a204d64360fba72552fcc6fde (diff) | |
parent | 5c04e77e0792c0a704ec4d7c2bb228750d37d060 (diff) | |
download | CMake-81ea5eb63753cbba8018d62fbb1d6218868ee8fa.zip CMake-81ea5eb63753cbba8018d62fbb1d6218868ee8fa.tar.gz CMake-81ea5eb63753cbba8018d62fbb1d6218868ee8fa.tar.bz2 |
Merge topic 'vs-lang-C' into release-3.18
5c04e77e07 VS: Restore compilation of '.C' sources as C++
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4880
-rw-r--r-- | Source/cmVisualStudio10TargetGenerator.cxx | 9 | ||||
-rw-r--r-- | Tests/CxxOnly/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/CxxOnly/cxxonly.cxx | 2 | ||||
-rw-r--r-- | Tests/CxxOnly/test.C | 1 |
4 files changed, 10 insertions, 4 deletions
diff --git a/Source/cmVisualStudio10TargetGenerator.cxx b/Source/cmVisualStudio10TargetGenerator.cxx index 97c4c85..a3ccd2b 100644 --- a/Source/cmVisualStudio10TargetGenerator.cxx +++ b/Source/cmVisualStudio10TargetGenerator.cxx @@ -2321,11 +2321,14 @@ void cmVisualStudio10TargetGenerator::OutputSourceSpecificFlags( } // 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); const char* compileAs = 0; - if (lang != - this->GlobalGenerator->GetLanguageFromExtension( - sf.GetExtension().c_str())) { + if (lang != extLang) { if (lang == "CXX") { // force a C++ file type compileAs = "CompileAsCpp"; diff --git a/Tests/CxxOnly/CMakeLists.txt b/Tests/CxxOnly/CMakeLists.txt index e62f3c7..8207dd1 100644 --- a/Tests/CxxOnly/CMakeLists.txt +++ b/Tests/CxxOnly/CMakeLists.txt @@ -5,7 +5,7 @@ set(CMAKE_DEBUG_POSTFIX "_test_debug_postfix") if(WIN32) set(EXTRA_SRCS test.CPP) 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_executable (CxxOnly cxxonly.cxx) target_link_libraries(CxxOnly testcxx1.my testcxx2) diff --git a/Tests/CxxOnly/cxxonly.cxx b/Tests/CxxOnly/cxxonly.cxx index 0911a07..8bd1637 100644 --- a/Tests/CxxOnly/cxxonly.cxx +++ b/Tests/CxxOnly/cxxonly.cxx @@ -1,5 +1,6 @@ #include "libcxx1.h" #include "libcxx2.h" +extern int testC; #ifdef _MSC_VER extern int testCPP; #endif @@ -8,6 +9,7 @@ extern int testCPP; int main() { + testC = 1; #ifdef _MSC_VER testCPP = 1; #endif diff --git a/Tests/CxxOnly/test.C b/Tests/CxxOnly/test.C new file mode 100644 index 0000000..e87e6c0 --- /dev/null +++ b/Tests/CxxOnly/test.C @@ -0,0 +1 @@ +int testC; |