diff options
author | Brad King <brad.king@kitware.com> | 2019-08-28 15:51:53 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2019-08-28 15:52:04 (GMT) |
commit | ffa1fa20e6ef3e78aad2dca75658232593509519 (patch) | |
tree | cdb7904d053fae028fc1da9c6c14d6d7370c4fa6 | |
parent | 606df71e48bf3594a7f79d68d990f401af9e45ea (diff) | |
parent | 41ba3e28e6840fd560a537d400146d2cde67a239 (diff) | |
download | CMake-ffa1fa20e6ef3e78aad2dca75658232593509519.zip CMake-ffa1fa20e6ef3e78aad2dca75658232593509519.tar.gz CMake-ffa1fa20e6ef3e78aad2dca75658232593509519.tar.bz2 |
Merge topic 'sf-LANGUAGE-prop'
41ba3e28e6 Tests: Collect SourceFileProperty tests
a40744c81a cmSourceFile: Move LANGUAGE to GetPropertyForUser
8cb3cffa42 cmSourceFile: Rename non-const GetLanguage
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !3744
-rw-r--r-- | Source/cmExtraCodeBlocksGenerator.cxx | 2 | ||||
-rw-r--r-- | Source/cmExtraSublimeTextGenerator.cxx | 6 | ||||
-rw-r--r-- | Source/cmFileAPICodemodel.cxx | 2 | ||||
-rw-r--r-- | Source/cmGeneratorTarget.cxx | 4 | ||||
-rw-r--r-- | Source/cmGetSourceFilePropertyCommand.cxx | 4 | ||||
-rw-r--r-- | Source/cmJsonObjects.cxx | 2 | ||||
-rw-r--r-- | Source/cmSourceFile.cxx | 26 | ||||
-rw-r--r-- | Source/cmSourceFile.h | 2 | ||||
-rw-r--r-- | Tests/COnly/CMakeLists.txt | 6 | ||||
-rw-r--r-- | Tests/SourceFileProperty/CMakeLists.txt | 22 |
10 files changed, 39 insertions, 37 deletions
diff --git a/Source/cmExtraCodeBlocksGenerator.cxx b/Source/cmExtraCodeBlocksGenerator.cxx index d8a1a49..487d0de 100644 --- a/Source/cmExtraCodeBlocksGenerator.cxx +++ b/Source/cmExtraCodeBlocksGenerator.cxx @@ -365,7 +365,7 @@ void cmExtraCodeBlocksGenerator::CreateNewProjectFile( // check whether it is a C/C++/CUDA implementation file bool isCFile = false; - std::string lang = s->GetLanguage(); + std::string lang = s->GetOrDetermineLanguage(); if (lang == "C" || lang == "CXX" || lang == "CUDA") { std::string const& srcext = s->GetExtension(); isCFile = cm->IsSourceExtension(srcext); diff --git a/Source/cmExtraSublimeTextGenerator.cxx b/Source/cmExtraSublimeTextGenerator.cxx index 33f5157..6f4472b 100644 --- a/Source/cmExtraSublimeTextGenerator.cxx +++ b/Source/cmExtraSublimeTextGenerator.cxx @@ -342,7 +342,7 @@ std::string cmExtraSublimeTextGenerator::ComputeFlagsForObject( cmSourceFile* source, cmLocalGenerator* lg, cmGeneratorTarget* gtgt) { std::string flags; - std::string language = source->GetLanguage(); + std::string language = source->GetOrDetermineLanguage(); if (language.empty()) { language = "C"; } @@ -377,7 +377,7 @@ std::string cmExtraSublimeTextGenerator::ComputeDefines( { std::set<std::string> defines; cmMakefile* makefile = lg->GetMakefile(); - const std::string& language = source->GetLanguage(); + const std::string& language = source->GetOrDetermineLanguage(); const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target, language); @@ -410,7 +410,7 @@ std::string cmExtraSublimeTextGenerator::ComputeIncludes( { std::vector<std::string> includes; cmMakefile* makefile = lg->GetMakefile(); - const std::string& language = source->GetLanguage(); + const std::string& language = source->GetOrDetermineLanguage(); const std::string& config = makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); cmGeneratorExpressionInterpreter genexInterpreter(lg, config, target, language); diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx index e4b7670..08db7c7 100644 --- a/Source/cmFileAPICodemodel.cxx +++ b/Source/cmFileAPICodemodel.cxx @@ -837,7 +837,7 @@ CompileData Target::BuildCompileData(cmSourceFile* sf) { CompileData fd; - fd.Language = sf->GetLanguage(); + fd.Language = sf->GetOrDetermineLanguage(); if (fd.Language.empty()) { return fd; } diff --git a/Source/cmGeneratorTarget.cxx b/Source/cmGeneratorTarget.cxx index 3048c5f..1d64f1c 100644 --- a/Source/cmGeneratorTarget.cxx +++ b/Source/cmGeneratorTarget.cxx @@ -1593,7 +1593,7 @@ void cmGeneratorTarget::ComputeKindedSources(KindedSources& files, kind = SourceKindHeader; } else if (sf->GetPropertyAsBool("EXTERNAL_OBJECT")) { kind = SourceKindExternalObject; - } else if (!sf->GetLanguage().empty()) { + } else if (!sf->GetOrDetermineLanguage().empty()) { kind = SourceKindObjectSource; } else if (ext == "def") { kind = SourceKindModuleDefinition; @@ -6055,7 +6055,7 @@ void cmGeneratorTarget::GetLanguages(std::set<std::string>& languages, std::vector<cmSourceFile*> sourceFiles; this->GetSourceFiles(sourceFiles, config); for (cmSourceFile* src : sourceFiles) { - const std::string& lang = src->GetLanguage(); + const std::string& lang = src->GetOrDetermineLanguage(); if (!lang.empty()) { languages.insert(lang); } diff --git a/Source/cmGetSourceFilePropertyCommand.cxx b/Source/cmGetSourceFilePropertyCommand.cxx index a16076d..5c1c8a5 100644 --- a/Source/cmGetSourceFilePropertyCommand.cxx +++ b/Source/cmGetSourceFilePropertyCommand.cxx @@ -24,10 +24,6 @@ bool cmGetSourceFilePropertyCommand::InitialPass( sf = this->Makefile->CreateSource(file); } if (sf) { - if (args[2] == "LANGUAGE") { - this->Makefile->AddDefinition(var, sf->GetLanguage()); - return true; - } const char* prop = nullptr; if (!args[2].empty()) { prop = sf->GetPropertyForUser(args[2]); diff --git a/Source/cmJsonObjects.cxx b/Source/cmJsonObjects.cxx index b8eed13..4948b01 100644 --- a/Source/cmJsonObjects.cxx +++ b/Source/cmJsonObjects.cxx @@ -264,7 +264,7 @@ static Json::Value DumpSourceFilesList( std::unordered_map<LanguageData, std::vector<std::string>> fileGroups; for (cmSourceFile* file : files) { LanguageData fileData; - fileData.Language = file->GetLanguage(); + fileData.Language = file->GetOrDetermineLanguage(); if (!fileData.Language.empty()) { const LanguageData& ld = languageDataMap.at(fileData.Language); cmLocalGenerator* lg = target->GetLocalGenerator(); diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index a6d2807..5d738d5 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -45,11 +45,13 @@ std::string cmSourceFile::GetObjectLibrary() const return this->ObjectLibrary; } -std::string cmSourceFile::GetLanguage() +std::string const& cmSourceFile::GetOrDetermineLanguage() { // If the language was set explicitly by the user then use it. if (const char* lang = this->GetProperty(propLANGUAGE)) { - return lang; + // Assign to member in order to return a reference. + this->Language = lang; + return this->Language; } // Perform computation needed to get the language if necessary. @@ -72,8 +74,8 @@ std::string cmSourceFile::GetLanguage() } } - // Now try to determine the language. - return static_cast<cmSourceFile const*>(this)->GetLanguage(); + // Use the language determined from the file extension. + return this->Language; } std::string cmSourceFile::GetLanguage() const @@ -83,13 +85,8 @@ std::string cmSourceFile::GetLanguage() const return lang; } - // If the language was determined from the source file extension use it. - if (!this->Language.empty()) { - return this->Language; - } - - // The language is not known. - return ""; + // Use the language determined from the file extension. + return this->Language; } cmSourceFileLocation const& cmSourceFile::GetLocation() const @@ -275,6 +272,13 @@ const char* cmSourceFile::GetPropertyForUser(const std::string& prop) this->GetFullPath(); } + // Similarly, LANGUAGE can be determined by the file extension + // if it is requested by the user. + if (prop == propLANGUAGE) { + // The c_str pointer is valid until `this->Language` is modified. + return this->GetOrDetermineLanguage().c_str(); + } + // Perform the normal property lookup. return this->GetProperty(prop); } diff --git a/Source/cmSourceFile.h b/Source/cmSourceFile.h index edad4c7..ccd5b62 100644 --- a/Source/cmSourceFile.h +++ b/Source/cmSourceFile.h @@ -88,7 +88,7 @@ public: /** * Get the language of the compiler to use for this source file. */ - std::string GetLanguage(); + std::string const& GetOrDetermineLanguage(); std::string GetLanguage() const; /** diff --git a/Tests/COnly/CMakeLists.txt b/Tests/COnly/CMakeLists.txt index 3037f13..20615fe 100644 --- a/Tests/COnly/CMakeLists.txt +++ b/Tests/COnly/CMakeLists.txt @@ -13,11 +13,5 @@ if(MSVC_VERSION AND NOT CMAKE_C_COMPILER_ID STREQUAL Clang OR "x${CMAKE_C_COMPIL endif() string(ASCII 35 32 67 77 97 107 101 ASCII_STRING) message(STATUS "String: ${ASCII_STRING}") -get_source_file_property(LANG conly.c LANGUAGE) -if("${LANG}" STREQUAL "C") - message("Language is C") -else() - message(FATAL_ERROR "Bad language for file conly.c") -endif() add_library(testCModule MODULE testCModule.c) diff --git a/Tests/SourceFileProperty/CMakeLists.txt b/Tests/SourceFileProperty/CMakeLists.txt index 1b6506d..5e55f7b 100644 --- a/Tests/SourceFileProperty/CMakeLists.txt +++ b/Tests/SourceFileProperty/CMakeLists.txt @@ -1,19 +1,27 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.1) project(SourceFileProperty C) -set(sources) - if (EXISTS icasetest.c) # If a file exists by this name, use it. set_source_files_properties(icasetest.c PROPERTIES - COMPILE_FLAGS -DNEEDED_TO_WORK) + COMPILE_DEFINITIONS NEEDED_TO_WORK) else () # Work on case-sensitive file systems as well. set_source_files_properties(main.c PROPERTIES - COMPILE_FLAGS -DNO_NEED_TO_CALL) + COMPILE_DEFINITIONS NO_NEED_TO_CALL) endif () -list(APPEND sources ICaseTest.c) -add_executable(SourceFileProperty main.c ${sources}) +add_executable(SourceFileProperty main.c) +target_sources(SourceFileProperty PRIVATE ICaseTest.c) + +get_source_file_property(LANG_MAIN main.c LANGUAGE) +if(NOT "${LANG_MAIN}" STREQUAL "C") + message(FATAL_ERROR "Bad language for file main.c") +endif() + +get_property(LANG_TEST SOURCE ICaseTest.c PROPERTY LANGUAGE) +if (NOT "${LANG_TEST}" STREQUAL "C") + message(FATAL_ERROR "Bad language for file ICaseTest.c") +endif () |