diff options
-rw-r--r-- | Source/cmFindPackageCommand.cxx | 9 | ||||
-rw-r--r-- | Source/cmFindPackageCommand.h | 2 | ||||
-rw-r--r-- | Source/cmInstallTargetGenerator.cxx | 31 | ||||
-rw-r--r-- | Source/cmQtAutoGenInitializer.cxx | 43 | ||||
-rw-r--r-- | Source/cmake.cxx | 16 | ||||
-rw-r--r-- | Source/cmake.h | 17 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/QtInFunction.cmake | 13 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/QtInFunctionNested-stderr.txt | 8 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/QtInFunctionNested.cmake | 17 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/QtInFunctionProperty.cmake | 21 | ||||
-rw-r--r-- | Tests/RunCMake/Autogen/RunCMakeTest.cmake | 5 | ||||
-rw-r--r-- | Tests/RunCMake/CMakeLists.txt | 9 | ||||
-rw-r--r-- | Tests/RunCMake/Framework/InstallBeforeFramework-stderr.txt | 7 | ||||
-rw-r--r-- | Tests/RunCMake/Framework/InstallBeforeFramework.cmake | 5 | ||||
-rw-r--r-- | Tests/RunCMake/Framework/RunCMakeTest.cmake | 2 |
15 files changed, 156 insertions, 49 deletions
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx index f9ac310..c2e0712 100644 --- a/Source/cmFindPackageCommand.cxx +++ b/Source/cmFindPackageCommand.cxx @@ -693,7 +693,7 @@ bool cmFindPackageCommand::FindModule(bool& found) std::string var = this->Name; var += "_FIND_MODULE"; this->Makefile->AddDefinition(var, "1"); - bool result = this->ReadListFile(mfile.c_str(), DoPolicyScope); + bool result = this->ReadListFile(mfile, DoPolicyScope); this->Makefile->RemoveDefinition(var); return result; } @@ -776,7 +776,7 @@ bool cmFindPackageCommand::HandlePackageMode() this->StoreVersionFound(); // Parse the configuration file. - if (this->ReadListFile(this->FileFound.c_str(), DoPolicyScope)) { + if (this->ReadListFile(this->FileFound, DoPolicyScope)) { // The package has been found. found = true; @@ -1036,7 +1036,8 @@ bool cmFindPackageCommand::FindAppBundleConfig() return false; } -bool cmFindPackageCommand::ReadListFile(const char* f, PolicyScopeRule psr) +bool cmFindPackageCommand::ReadListFile(const std::string& f, + PolicyScopeRule psr) { const bool noPolicyScope = !this->PolicyScope || psr == NoPolicyScope; if (this->Makefile->ReadDependentFile(f, noPolicyScope)) { @@ -1590,7 +1591,7 @@ bool cmFindPackageCommand::CheckVersionFile(std::string const& version_file, // Load the version check file. Pass NoPolicyScope because we do // our own policy push/pop independent of CMP0011. bool suitable = false; - if (this->ReadListFile(version_file.c_str(), NoPolicyScope)) { + if (this->ReadListFile(version_file, NoPolicyScope)) { // Check the output variables. bool okay = this->Makefile->IsOn("PACKAGE_VERSION_EXACT"); bool unsuitable = this->Makefile->IsOn("PACKAGE_VERSION_UNSUITABLE"); diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h index 83d8431..a11d253 100644 --- a/Source/cmFindPackageCommand.h +++ b/Source/cmFindPackageCommand.h @@ -110,7 +110,7 @@ private: NoPolicyScope, DoPolicyScope }; - bool ReadListFile(const char* f, PolicyScopeRule psr); + bool ReadListFile(const std::string& f, PolicyScopeRule psr); void StoreVersionFound(); void ComputePrefixes(); diff --git a/Source/cmInstallTargetGenerator.cxx b/Source/cmInstallTargetGenerator.cxx index 10df70b..26cebf0 100644 --- a/Source/cmInstallTargetGenerator.cxx +++ b/Source/cmInstallTargetGenerator.cxx @@ -19,6 +19,7 @@ #include "cmStateTypes.h" #include "cmSystemTools.h" #include "cmTarget.h" +#include "cmake.h" cmInstallTargetGenerator::cmInstallTargetGenerator( std::string targetName, const char* dest, bool implib, @@ -209,8 +210,34 @@ void cmInstallTargetGenerator::GenerateScriptForConfig( // An import library looks like a static library. type = cmInstallType_STATIC_LIBRARY; } else if (this->Target->IsFrameworkOnApple()) { - // There is a bug in cmInstallCommand if this fails. - assert(this->NamelinkMode == NamelinkModeNone); + // FIXME: In principle we should be able to + // assert(this->NamelinkMode == NamelinkModeNone); + // but since the current install() command implementation checks + // the FRAMEWORK property immediately instead of delaying until + // generate time, it is possible for project code to set the + // property after calling install(). In such a case, the install() + // command will use the LIBRARY code path and create two install + // generators, one for the namelink component (NamelinkModeOnly) + // and one for the primary artifact component (NamelinkModeSkip). + // Historically this was not diagnosed and resulted in silent + // installation of a framework to the LIBRARY destination. + // Retain that behavior and warn about the case. + switch (this->NamelinkMode) { + case NamelinkModeNone: + // Normal case. + break; + case NamelinkModeOnly: + // Assume the NamelinkModeSkip instance will warn and install. + return; + case NamelinkModeSkip: { + std::string e = "Target '" + this->Target->GetName() + + "' was changed to a FRAMEWORK sometime after install(). " + "This may result in the wrong install DESTINATION. " + "Set the FRAMEWORK property earlier."; + this->Target->GetGlobalGenerator()->GetCMakeInstance()->IssueMessage( + MessageType::AUTHOR_WARNING, e, this->GetBacktrace()); + } break; + } // Install the whole framework directory. type = cmInstallType_DIRECTORY; diff --git a/Source/cmQtAutoGenInitializer.cxx b/Source/cmQtAutoGenInitializer.cxx index 1d7f6d1..caeed15 100644 --- a/Source/cmQtAutoGenInitializer.cxx +++ b/Source/cmQtAutoGenInitializer.cxx @@ -1370,7 +1370,7 @@ void cmQtAutoGenInitializer::AddGeneratedSource(std::string const& filename, this->Target->AddSource(filename, prepend); } -static unsigned int CharPtrToInt(const char* const input) +static unsigned int CharPtrToUInt(const char* const input) { unsigned long tmp = 0; if (input != nullptr && cmSystemTools::StringToULong(input, &tmp)) { @@ -1379,36 +1379,43 @@ static unsigned int CharPtrToInt(const char* const input) return 0; } -static unsigned int StringToInt(const std::string& input) -{ - return input.empty() ? 0 : CharPtrToInt(input.c_str()); -} - -static std::vector<cmQtAutoGenInitializer::IntegerVersion> GetKnownQtVersions( +static std::vector<cmQtAutoGen::IntegerVersion> GetKnownQtVersions( cmGeneratorTarget const* target) { cmMakefile* makefile = target->Target->GetMakefile(); - - std::vector<cmQtAutoGenInitializer::IntegerVersion> result; - for (const std::string& prefix : - std::vector<std::string>({ "Qt6Core", "Qt5Core", "QT" })) { - auto tmp = cmQtAutoGenInitializer::IntegerVersion( - StringToInt(makefile->GetSafeDefinition(prefix + "_VERSION_MAJOR")), - StringToInt(makefile->GetSafeDefinition(prefix + "_VERSION_MINOR"))); - if (tmp.Major != 0) { - result.push_back(tmp); + std::vector<cmQtAutoGen::IntegerVersion> result; + // Adds a version to the result (nullptr safe) + auto addVersion = [&result](const char* major, const char* minor) { + cmQtAutoGen::IntegerVersion ver(CharPtrToUInt(major), + CharPtrToUInt(minor)); + if (ver.Major != 0) { + result.emplace_back(ver); } + }; + // Qt version variable prefixes + std::array<std::string, 3> const prefixes{ { "Qt6Core", "Qt5Core", "QT" } }; + + // Read versions from variables + for (const std::string& prefix : prefixes) { + addVersion(makefile->GetDefinition(prefix + "_VERSION_MAJOR"), + makefile->GetDefinition(prefix + "_VERSION_MINOR")); + } + + // Read versions from directory properties + for (const std::string& prefix : prefixes) { + addVersion(makefile->GetProperty(prefix + "_VERSION_MAJOR"), + makefile->GetProperty(prefix + "_VERSION_MINOR")); } return result; } -std::pair<cmQtAutoGenInitializer::IntegerVersion, unsigned int> +std::pair<cmQtAutoGen::IntegerVersion, unsigned int> cmQtAutoGenInitializer::GetQtVersion(cmGeneratorTarget const* target) { std::pair<IntegerVersion, unsigned int> res( IntegerVersion(), - CharPtrToInt(target->GetLinkInterfaceDependentStringProperty( + CharPtrToUInt(target->GetLinkInterfaceDependentStringProperty( "QT_MAJOR_VERSION", ""))); auto knownQtVersions = GetKnownQtVersions(target); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 2b627ff..8023298 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -437,7 +437,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args) } } std::cout << "loading initial cache file " << path << "\n"; - this->ReadListFile(args, path.c_str()); + this->ReadListFile(args, path); } else if (arg.find("-P", 0) == 0) { i++; if (i >= args.size()) { @@ -451,7 +451,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args) } // Register fake project commands that hint misuse in script mode. GetProjectCommandsInScriptMode(this->State); - this->ReadListFile(args, path.c_str()); + this->ReadListFile(args, path); } else if (arg.find("--find-package", 0) == 0) { findPackageMode = true; } @@ -465,7 +465,7 @@ bool cmake::SetCacheArgs(const std::vector<std::string>& args) } void cmake::ReadListFile(const std::vector<std::string>& args, - const char* path) + const std::string& path) { // if a generator was not yet created, temporarily create one cmGlobalGenerator* gg = this->GetGlobalGenerator(); @@ -478,7 +478,7 @@ void cmake::ReadListFile(const std::vector<std::string>& args, } // read in the list file to fill the cache - if (path) { + if (!path.empty()) { this->CurrentSnapshot = this->State->Reset(); std::string homeDir = this->GetHomeDirectory(); std::string homeOutputDir = this->GetHomeOutputDirectory(); @@ -499,7 +499,7 @@ void cmake::ReadListFile(const std::vector<std::string>& args, mf.SetArgcArgv(args); } if (!mf.ReadListFile(path)) { - cmSystemTools::Error("Error processing file: ", path); + cmSystemTools::Error("Error processing file: " + path); } this->SetHomeDirectory(homeDir); this->SetHomeOutputDirectory(homeOutputDir); @@ -1606,14 +1606,14 @@ void cmake::PreLoadCMakeFiles() if (!pre_load.empty()) { pre_load += "/PreLoad.cmake"; if (cmSystemTools::FileExists(pre_load)) { - this->ReadListFile(args, pre_load.c_str()); + this->ReadListFile(args, pre_load); } } pre_load = this->GetHomeOutputDirectory(); if (!pre_load.empty()) { pre_load += "/PreLoad.cmake"; if (cmSystemTools::FileExists(pre_load)) { - this->ReadListFile(args, pre_load.c_str()); + this->ReadListFile(args, pre_load); } } } @@ -2613,7 +2613,7 @@ int cmake::Build(int jobs, const std::string& dir, const std::string& target, cachePath + "/" + "CMakeFiles/" + "VerifyGlobs.cmake"; if (cmSystemTools::FileExists(globVerifyScript)) { std::vector<std::string> args; - this->ReadListFile(args, globVerifyScript.c_str()); + this->ReadListFile(args, globVerifyScript); } } diff --git a/Source/cmake.h b/Source/cmake.h index 314101e..53d44f1 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -444,7 +444,6 @@ public: protected: void RunCheckForUnusedVariables(); - void InitializeProperties(); int HandleDeleteCacheVariables(const std::string& var); typedef std::vector<cmGlobalGeneratorFactory*> RegisteredGeneratorsVector; @@ -464,7 +463,8 @@ protected: std::string GeneratorToolset; ///! read in a cmake list file to initialize the cache - void ReadListFile(const std::vector<std::string>& args, const char* path); + void ReadListFile(const std::vector<std::string>& args, + const std::string& path); bool FindPackage(const std::vector<std::string>& args); ///! Check if CMAKE_CACHEFILE_DIR is set. If it is not, delete the log file. @@ -487,7 +487,6 @@ protected: private: ProgressCallbackType ProgressCallback; - bool InTryCompile; WorkingMode CurrentWorkingMode; bool DebugOutput; bool Trace; @@ -535,18 +534,6 @@ private: void AppendGlobalGeneratorsDocumentation(std::vector<cmDocumentationEntry>&); void AppendExtraGeneratorsDocumentation(std::vector<cmDocumentationEntry>&); - - /** - * Convert a message type between a warning and an error, based on the state - * of the error output CMake variables, in the cache. - */ - MessageType ConvertMessageType(MessageType t) const; - - /* - * Check if messages of this type should be output, based on the state of the - * warning and error output CMake variables, in the cache. - */ - bool IsMessageTypeVisible(MessageType t) const; }; #define CMAKE_STANDARD_OPTIONS_TABLE \ diff --git a/Tests/RunCMake/Autogen/QtInFunction.cmake b/Tests/RunCMake/Autogen/QtInFunction.cmake new file mode 100644 index 0000000..a44bc5a --- /dev/null +++ b/Tests/RunCMake/Autogen/QtInFunction.cmake @@ -0,0 +1,13 @@ +enable_language(CXX) + +function (use_autogen target) + find_package(Qt5 REQUIRED COMPONENTS Core Widgets) + set(Qt5Core_VERSION_MAJOR "${Qt5Core_VERSION_MAJOR}" PARENT_SCOPE) + set(Qt5Core_VERSION_MINOR "${Qt5Core_VERSION_MINOR}" PARENT_SCOPE) + set_property(TARGET "${target}" PROPERTY AUTOMOC 1) + set_property(TARGET "${target}" PROPERTY AUTORCC 1) + set_property(TARGET "${target}" PROPERTY AUTOUIC 1) +endfunction () + +add_executable(main empty.cpp) +use_autogen(main) diff --git a/Tests/RunCMake/Autogen/QtInFunctionNested-stderr.txt b/Tests/RunCMake/Autogen/QtInFunctionNested-stderr.txt new file mode 100644 index 0000000..1c6660a --- /dev/null +++ b/Tests/RunCMake/Autogen/QtInFunctionNested-stderr.txt @@ -0,0 +1,8 @@ +^CMake Warning \(dev\) in CMakeLists.txt: + AUTOGEN: No valid Qt version found for target main. AUTOMOC, AUTOUIC and + AUTORCC disabled. Consider adding: + + find_package\(Qt<QTVERSION> COMPONENTS Widgets\) + + to your CMakeLists.txt file. +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/Autogen/QtInFunctionNested.cmake b/Tests/RunCMake/Autogen/QtInFunctionNested.cmake new file mode 100644 index 0000000..5421ba0 --- /dev/null +++ b/Tests/RunCMake/Autogen/QtInFunctionNested.cmake @@ -0,0 +1,17 @@ +enable_language(CXX) + +function (use_autogen target) + find_package(Qt5 REQUIRED COMPONENTS Core Widgets) + set(Qt5Core_VERSION_MAJOR "${Qt5Core_VERSION_MAJOR}" PARENT_SCOPE) + set(Qt5Core_VERSION_MINOR "${Qt5Core_VERSION_MINOR}" PARENT_SCOPE) + set_property(TARGET "${target}" PROPERTY AUTOMOC 1) + set_property(TARGET "${target}" PROPERTY AUTORCC 1) + set_property(TARGET "${target}" PROPERTY AUTOUIC 1) +endfunction () + +function (wrap_autogen target) + use_autogen("${target}") +endfunction () + +add_executable(main empty.cpp) +wrap_autogen(main) diff --git a/Tests/RunCMake/Autogen/QtInFunctionProperty.cmake b/Tests/RunCMake/Autogen/QtInFunctionProperty.cmake new file mode 100644 index 0000000..35f1cd1 --- /dev/null +++ b/Tests/RunCMake/Autogen/QtInFunctionProperty.cmake @@ -0,0 +1,21 @@ +enable_language(CXX) + +function (use_autogen target) + find_package(Qt5 REQUIRED COMPONENTS Core Widgets) + set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + PROPERTY + Qt5Core_VERSION_MAJOR "${Qt5Core_VERSION_MAJOR}") + set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + PROPERTY + Qt5Core_VERSION_MINOR "${Qt5Core_VERSION_MINOR}") + set_property(TARGET "${target}" PROPERTY AUTOMOC 1) + set_property(TARGET "${target}" PROPERTY AUTORCC 1) + set_property(TARGET "${target}" PROPERTY AUTOUIC 1) +endfunction () + +function (wrap_autogen target) + use_autogen("${target}") +endfunction () + +add_executable(main empty.cpp) +wrap_autogen(main) diff --git a/Tests/RunCMake/Autogen/RunCMakeTest.cmake b/Tests/RunCMake/Autogen/RunCMakeTest.cmake index e52f28d..a31b67c 100644 --- a/Tests/RunCMake/Autogen/RunCMakeTest.cmake +++ b/Tests/RunCMake/Autogen/RunCMakeTest.cmake @@ -1,3 +1,8 @@ include(RunCMake) run_cmake(NoQt) +if (with_qt5) + run_cmake(QtInFunction) + run_cmake(QtInFunctionNested) + run_cmake(QtInFunctionProperty) +endif () diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 2de90e7..1f3e5c3 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -150,7 +150,14 @@ if(NOT CMake_TEST_EXTERNAL_CMAKE) endif() add_RunCMake_test(AndroidTestUtilities) -add_RunCMake_test(Autogen) +set(autogen_with_qt5 FALSE) +if(CMake_TEST_Qt5) + find_package(Qt5Widgets QUIET NO_MODULE) +endif() +if(CMake_TEST_Qt5 AND Qt5Widgets_FOUND) + set(autogen_with_qt5 TRUE) +endif () +add_RunCMake_test(Autogen -Dwith_qt5=${autogen_with_qt5}) add_RunCMake_test(BuildDepends) if(UNIX AND "${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja") add_RunCMake_test(Byproducts) diff --git a/Tests/RunCMake/Framework/InstallBeforeFramework-stderr.txt b/Tests/RunCMake/Framework/InstallBeforeFramework-stderr.txt new file mode 100644 index 0000000..a3a7c6c --- /dev/null +++ b/Tests/RunCMake/Framework/InstallBeforeFramework-stderr.txt @@ -0,0 +1,7 @@ +^CMake Warning \(dev\) at InstallBeforeFramework.cmake:4 \(install\): + Target 'foo' was changed to a FRAMEWORK sometime after install\(\). This may + result in the wrong install DESTINATION. Set the FRAMEWORK property + earlier. +Call Stack \(most recent call first\): + CMakeLists.txt:[0-9]+ \(include\) +This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/Framework/InstallBeforeFramework.cmake b/Tests/RunCMake/Framework/InstallBeforeFramework.cmake new file mode 100644 index 0000000..3791dac --- /dev/null +++ b/Tests/RunCMake/Framework/InstallBeforeFramework.cmake @@ -0,0 +1,5 @@ +enable_language(C) + +add_library(foo SHARED foo.c) +install(TARGETS foo LIBRARY DESTINATION lib) +set_property(TARGET foo PROPERTY FRAMEWORK TRUE) diff --git a/Tests/RunCMake/Framework/RunCMakeTest.cmake b/Tests/RunCMake/Framework/RunCMakeTest.cmake index 4fc83f8..e705a31 100644 --- a/Tests/RunCMake/Framework/RunCMakeTest.cmake +++ b/Tests/RunCMake/Framework/RunCMakeTest.cmake @@ -1,5 +1,7 @@ include(RunCMake) +run_cmake(InstallBeforeFramework) + function(framework_layout_test Name Toolchain Type) set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${Toolchain}${Type}FrameworkLayout-build) set(RunCMake_TEST_NO_CLEAN 1) |