From a40744c81a8d6dad994def5a63103fc229a75afc Mon Sep 17 00:00:00 2001 From: Tushar Maheshwari Date: Tue, 27 Aug 2019 12:19:43 +0530 Subject: cmSourceFile: Move LANGUAGE to GetPropertyForUser - Remove the special case from cmGetSourceFilePropertyCommand Tests: check LANGUAGE for source file - use target_sources to add file - use get_property to read property value --- Source/cmGetSourceFilePropertyCommand.cxx | 4 ---- Source/cmSourceFile.cxx | 7 +++++++ Tests/SourceFileProperty/CMakeLists.txt | 17 ++++++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Source/cmGetSourceFilePropertyCommand.cxx b/Source/cmGetSourceFilePropertyCommand.cxx index 5a477b9..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->GetOrDetermineLanguage()); - return true; - } const char* prop = nullptr; if (!args[2].empty()) { prop = sf->GetPropertyForUser(args[2]); diff --git a/Source/cmSourceFile.cxx b/Source/cmSourceFile.cxx index 738a1c0..5d738d5 100644 --- a/Source/cmSourceFile.cxx +++ b/Source/cmSourceFile.cxx @@ -272,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/Tests/SourceFileProperty/CMakeLists.txt b/Tests/SourceFileProperty/CMakeLists.txt index 1b6506d..5dbc34f 100644 --- a/Tests/SourceFileProperty/CMakeLists.txt +++ b/Tests/SourceFileProperty/CMakeLists.txt @@ -1,19 +1,22 @@ -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_property(LANG SOURCE ICaseTest.c PROPERTY LANGUAGE) +if (NOT "${LANG}" STREQUAL "C") + message(FATAL_ERROR "Bad language for file ICaseTest.c") +endif () -- cgit v0.12