From 1794836ee3e8727c9eed233f1ebaa0a1dbf76e57 Mon Sep 17 00:00:00 2001 From: Bill Hoffman Date: Thu, 4 May 2006 13:35:56 -0400 Subject: ENH: fix build c stuff with c and c++ with c++ --- Source/cmLocalVisualStudio7Generator.cxx | 29 ++++++++++++++++++++++++++--- Tests/COnly/conly.c | 3 ++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index 4143481..fdc4288 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -262,6 +262,8 @@ cmVS7FlagTable cmLocalVisualStudio7GeneratorFlagTable[] = {"EnableEnhancedInstructionSet", "arch:SSE", "Use sse instructions", "1"}, {"FavorSizeOrSpeed", "Ot", "Favor fast code", "1"}, {"FavorSizeOrSpeed", "Os", "Favor small code", "2"}, + {"CompileAs", "TC", "Compile as c code", "1"}, + {"CompileAs", "TP", "Compile as c++ code", "2"}, {"Optimization", "Od", "Non Debug", "0"}, {"Optimization", "O1", "Min Size", "1"}, {"Optimization", "O2", "Max Speed", "2"}, @@ -395,6 +397,16 @@ void cmLocalVisualStudio7Generator::WriteConfiguration(std::ostream& fout, flags += " "; flags += this->Makefile->GetRequiredDefinition(flagVar.c_str()); } + // set the correct language + if(strcmp(linkLanguage, "C") == 0) + { + flags += " /TC "; + } + if(strcmp(linkLanguage, "CXX") == 0) + { + flags += " /TP "; + } + std::cerr << flags << "\n"; } // Add the target-specific flags. @@ -1035,10 +1047,21 @@ void cmLocalVisualStudio7Generator::WriteGroup(const cmSourceGroup *sg, cmTarget } const char* lang = this->GlobalGenerator->GetLanguageFromExtension((*sf)->GetSourceExtension().c_str()); - if(lang && strcmp(lang, "CXX") == 0) + const char* linkLanguage = target.GetLinkerLanguage(this->GetGlobalGenerator()); + // if the source file does not match the linker language + // then force c or c++ + if(linkLanguage && lang && strcmp(lang, linkLanguage) != 0) { - // force a C++ file type - compileFlags += " /TP "; + if(strcmp(lang, "CXX") == 0) + { + // force a C++ file type + compileFlags += " /TP "; + } + else if(strcmp(lang, "C") == 0) + { + // force to c + compileFlags += " /TC "; + } } // Check for extra object-file dependencies. const char* deps = (*sf)->GetProperty("OBJECT_DEPENDS"); diff --git a/Tests/COnly/conly.c b/Tests/COnly/conly.c index e8280ec..7214fe1 100644 --- a/Tests/COnly/conly.c +++ b/Tests/COnly/conly.c @@ -7,6 +7,7 @@ int main () { + int class = 0; if ( LibC1Func() != 2.0 ) { printf("Problem with libc1\n"); @@ -17,6 +18,6 @@ int main () printf("Problem with libc2\n"); return 1; } - printf("Foo: %s\n", foo); + printf("Foo: %s %d\n", foo, class); return 0; } -- cgit v0.12