| 843 | } |
| 844 | |
| 845 | bool cmake::FindPackage(std::vector<std::string> const& args) |
| 846 | { |
| 847 | this->SetHomeDirectory(cmSystemTools::GetLogicalWorkingDirectory()); |
| 848 | this->SetHomeOutputDirectory(cmSystemTools::GetLogicalWorkingDirectory()); |
| 849 | |
| 850 | this->SetGlobalGenerator(cm::make_unique<cmGlobalGenerator>(this)); |
| 851 | |
| 852 | cmStateSnapshot snapshot = this->GetCurrentSnapshot(); |
| 853 | snapshot.GetDirectory().SetCurrentBinary( |
| 854 | cmSystemTools::GetLogicalWorkingDirectory()); |
| 855 | snapshot.GetDirectory().SetCurrentSource( |
| 856 | cmSystemTools::GetLogicalWorkingDirectory()); |
| 857 | // read in the list file to fill the cache |
| 858 | snapshot.SetDefaultDefinitions(); |
| 859 | auto mfu = cm::make_unique<cmMakefile>(this->GetGlobalGenerator(), snapshot); |
| 860 | cmMakefile* mf = mfu.get(); |
| 861 | this->GlobalGenerator->AddMakefile(std::move(mfu)); |
| 862 | |
| 863 | mf->SetArgcArgv(args); |
| 864 | |
| 865 | std::string systemFile = mf->GetModulesFile("CMakeFindPackageMode.cmake"); |
| 866 | mf->ReadListFile(systemFile); |
| 867 | |
| 868 | std::string language = mf->GetSafeDefinition("LANGUAGE"); |
| 869 | std::string mode = mf->GetSafeDefinition("MODE"); |
| 870 | std::string packageName = mf->GetSafeDefinition("NAME"); |
| 871 | bool packageFound = mf->IsOn("PACKAGE_FOUND"); |
| 872 | bool quiet = mf->IsOn("PACKAGE_QUIET"); |
| 873 | |
| 874 | if (!packageFound) { |
| 875 | if (!quiet) { |
| 876 | printf("%s not found.\n", packageName.c_str()); |
| 877 | } |
| 878 | } else if (mode == "EXIST"_s) { |
| 879 | if (!quiet) { |
| 880 | printf("%s found.\n", packageName.c_str()); |
| 881 | } |
| 882 | } else if (mode == "COMPILE"_s) { |
| 883 | std::string includes = mf->GetSafeDefinition("PACKAGE_INCLUDE_DIRS"); |
| 884 | cmList includeDirs{ includes }; |
| 885 | |
| 886 | this->GlobalGenerator->CreateGenerationObjects(); |
| 887 | auto const& lg = this->GlobalGenerator->LocalGenerators[0]; |
| 888 | std::string includeFlags = |
| 889 | lg->GetIncludeFlags(includeDirs, nullptr, language, std::string()); |
| 890 | |
| 891 | std::string definitions = mf->GetSafeDefinition("PACKAGE_DEFINITIONS"); |
| 892 | printf("%s %s\n", includeFlags.c_str(), definitions.c_str()); |
| 893 | } else if (mode == "LINK"_s) { |
| 894 | char const* targetName = "dummy"; |
| 895 | std::vector<std::string> srcs; |
| 896 | cmTarget* tgt = mf->AddExecutable(targetName, srcs, true); |
| 897 | tgt->SetProperty("LINKER_LANGUAGE", language); |
| 898 | |
| 899 | std::string libs = mf->GetSafeDefinition("PACKAGE_LIBRARIES"); |
| 900 | cmList libList{ libs }; |
| 901 | for (std::string const& lib : libList) { |
| 902 | tgt->AddLinkLibrary(*mf, lib, GENERAL_LibraryType); |
no test coverage detected