diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2007-02-20 14:35:21 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2007-02-20 14:35:21 (GMT) |
commit | 1d8e7e9411f62a60340b1edba6c55a8e7548a93b (patch) | |
tree | 932198ce265b630740c8340c0e2d0a8a723919bc | |
parent | 5c0a340a9e0146841b14065497373cb9a79d5768 (diff) | |
download | CMake-1d8e7e9411f62a60340b1edba6c55a8e7548a93b.zip CMake-1d8e7e9411f62a60340b1edba6c55a8e7548a93b.tar.gz CMake-1d8e7e9411f62a60340b1edba6c55a8e7548a93b.tar.bz2 |
BUG: fix for bug 4423 set language fixes
-rw-r--r-- | Source/CMakeLists.txt | 11 | ||||
-rw-r--r-- | Source/cmLocalVisualStudio6Generator.cxx | 8 | ||||
-rw-r--r-- | Source/cmLocalVisualStudio7Generator.cxx | 11 | ||||
-rw-r--r-- | Tests/SetLang/CMakeLists.txt | 7 | ||||
-rw-r--r-- | Tests/SetLang/bar.c | 21 | ||||
-rw-r--r-- | Tests/SetLang/foo.c | 7 |
6 files changed, 61 insertions, 4 deletions
diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 65a20f7..3684f51 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -697,6 +697,16 @@ IF(BUILD_TESTING) -DCMAKE_TEST_SYSTEM_LIBRARIES:BOOL=${CMAKE_TEST_SYSTEM_LIBRARIES} --test-command complex) + ADD_TEST(SetLang ${CMAKE_CTEST_COMMAND} + --build-and-test + "${CMake_SOURCE_DIR}/Tests/SetLang" + "${CMake_BINARY_DIR}/Tests/SetLang" + --build-two-config + --build-generator ${CMAKE_TEST_GENERATOR} + --build-makeprogram ${CMAKE_TEST_MAKEPROGRAM} + --build-project SetLang + --test-command bar) + # ADD_TEST(ConvLibrary ${CMAKE_CTEST_COMMAND} # --build-and-test # "${CMake_SOURCE_DIR}/Tests/ConvLibrary" @@ -707,6 +717,7 @@ IF(BUILD_TESTING) # --build-project ConvLibrary # --test-command bartest) + # ADD_TEST(complexRelativePaths ${CMAKE_CTEST_COMMAND} # --build-and-test # "${CMake_SOURCE_DIR}/Tests/ComplexRelativePaths" diff --git a/Source/cmLocalVisualStudio6Generator.cxx b/Source/cmLocalVisualStudio6Generator.cxx index edb0610..284a2a6 100644 --- a/Source/cmLocalVisualStudio6Generator.cxx +++ b/Source/cmLocalVisualStudio6Generator.cxx @@ -421,12 +421,16 @@ void cmLocalVisualStudio6Generator compileFlags += cflags; } - const char* lang = this->GlobalGenerator-> - GetLanguageFromExtension((*sf)->GetSourceExtension().c_str()); + const char* lang = this->GetSourceFileLanguage(*(*sf)); if(lang && strcmp(lang, "CXX") == 0) { // force a C++ file type compileFlags += " /TP "; + } + else if(strcmp(lang, "C") == 0) + { + // force to c file type + compileFlags += " /TC "; } // Check for extra object-file dependencies. diff --git a/Source/cmLocalVisualStudio7Generator.cxx b/Source/cmLocalVisualStudio7Generator.cxx index b69d9bb..642b78f 100644 --- a/Source/cmLocalVisualStudio7Generator.cxx +++ b/Source/cmLocalVisualStudio7Generator.cxx @@ -1148,9 +1148,16 @@ void cmLocalVisualStudio7Generator } const char* lang = this->GlobalGenerator->GetLanguageFromExtension ((*sf)->GetSourceExtension().c_str()); + const char* sourceLang = this->GetSourceFileLanguage(*(*sf)); const char* linkLanguage = target.GetLinkerLanguage (this->GetGlobalGenerator()); - + bool needForceLang = false; + // source file does not match its extension language + if(lang && sourceLang && strcmp(lang, sourceLang) != 0) + { + needForceLang = true; + lang = sourceLang; + } // If lang is set, the compiler will generate code automatically. // If HEADER_FILE_ONLY is set, we must suppress this generation in // the project file @@ -1159,7 +1166,7 @@ void cmLocalVisualStudio7Generator // if the source file does not match the linker language // then force c or c++ - if(linkLanguage && lang && strcmp(lang, linkLanguage) != 0) + if(needForceLang || (linkLanguage && lang && strcmp(lang, linkLanguage) != 0)) { if(strcmp(lang, "CXX") == 0) { diff --git a/Tests/SetLang/CMakeLists.txt b/Tests/SetLang/CMakeLists.txt new file mode 100644 index 0000000..d53b308 --- /dev/null +++ b/Tests/SetLang/CMakeLists.txt @@ -0,0 +1,7 @@ +# test forcing a source file language to c++ from c +project(SetLang) +add_library(foo foo.c) +add_executable(bar bar.c) +set_source_files_properties(foo.c bar.c PROPERTIES LANGUAGE CXX) +target_link_libraries(bar foo) +set_target_properties(bar PROPERTIES LINKER_LANGUAGE CXX) diff --git a/Tests/SetLang/bar.c b/Tests/SetLang/bar.c new file mode 100644 index 0000000..f59c318 --- /dev/null +++ b/Tests/SetLang/bar.c @@ -0,0 +1,21 @@ +#include <stdio.h> + +int foo(); +class A +{ +public: + A() {this->i = foo();} + int i; +}; + +int main() +{ + A a; + if(a.i == 21) + { + printf("passed foo is 21\n"); + return 0; + } + printf("Failed foo is not 21\n"); + return -1; +} diff --git a/Tests/SetLang/foo.c b/Tests/SetLang/foo.c new file mode 100644 index 0000000..e7918af --- /dev/null +++ b/Tests/SetLang/foo.c @@ -0,0 +1,7 @@ +int foo() +{ + int r = 10; + r++; + int ret = r+10; + return ret; +} |