diff options
author | Alex Neundorf <neundorf@kde.org> | 2011-07-02 21:14:28 (GMT) |
---|---|---|
committer | Alex Neundorf <neundorf@kde.org> | 2011-07-02 21:14:28 (GMT) |
commit | e4f603b698a13857e79a5f6df18a7461b20d4bd4 (patch) | |
tree | 83a4c2dfe14bced8a23129ed0aa3238e3baa384c /Source/cmake.cxx | |
parent | a91d662f46fd2781fc5a3b73c2d244ac6dc2a343 (diff) | |
download | CMake-e4f603b698a13857e79a5f6df18a7461b20d4bd4.zip CMake-e4f603b698a13857e79a5f6df18a7461b20d4bd4.tar.gz CMake-e4f603b698a13857e79a5f6df18a7461b20d4bd4.tar.bz2 |
Implement find-package mode of cmake
In find-package mode, cmake executes Modules/CMakeFindPackage.cmake,
which calls find_package(), and this is then evaluated in cmake.cxx,
which prints an appropriate message to stdout, so it can be used
e.g. in a normal Makefile:
$ /opt/cmake-HEAD/bin/cmake --find-package -DNAME=JPEG
-DCOMPILER_ID=GNU -DLANGUAGE=C -DMODE=EXIST
JPEG found.
$ /opt/cmake-HEAD/bin/cmake --find-package -DNAME=JPEG
-DCOMPILER_ID=GNU -DLANGUAGE=C -DMODE=COMPILE
$ /opt/cmake-HEAD/bin/cmake --find-package -DNAME=JPEG
-DCOMPILER_ID=GNU -DLANGUAGE=C -DMODE=LINK
-rdynamic -ljpeg
Alex
Diffstat (limited to 'Source/cmake.cxx')
-rw-r--r-- | Source/cmake.cxx | 100 |
1 files changed, 98 insertions, 2 deletions
diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 3d42c7f..5b6286e 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -547,8 +547,104 @@ void cmake::ReadListFile(const std::vector<std::string>& args, bool cmake::FindPackage(const std::vector<std::string>& args) { - // create empty function for now, will be filled later - return true; + // if a generator was not yet created, temporarily create one + cmGlobalGenerator *gg = new cmGlobalGenerator; + gg->SetCMakeInstance(this); + this->SetGlobalGenerator(gg); + + // read in the list file to fill the cache + std::auto_ptr<cmLocalGenerator> lg(gg->CreateLocalGenerator()); + cmMakefile* mf = lg->GetMakefile(); + mf->SetHomeOutputDirectory + (cmSystemTools::GetCurrentWorkingDirectory().c_str()); + mf->SetStartOutputDirectory + (cmSystemTools::GetCurrentWorkingDirectory().c_str()); + mf->SetHomeDirectory + (cmSystemTools::GetCurrentWorkingDirectory().c_str()); + mf->SetStartDirectory + (cmSystemTools::GetCurrentWorkingDirectory().c_str()); + + mf->SetArgcArgv(args); + + std::string systemFile = mf->GetModulesFile("CMakeFindPackageMode.cmake"); + mf->ReadListFile(0, systemFile.c_str()); + + std::string language = mf->GetSafeDefinition("LANGUAGE"); + std::string mode = mf->GetSafeDefinition("MODE"); + std::string packageName = mf->GetSafeDefinition("NAME"); + bool packageFound = mf->IsOn("PACKAGE_FOUND"); + bool quiet = mf->IsOn("PACKAGE_QUIET"); + + if (!packageFound) + { + if (!quiet) + { + printf("%s not found.\n", packageName.c_str()); + } + } + else if (mode == "EXIST") + { + if (!quiet) + { + printf("%s found.\n", packageName.c_str()); + } + } + else if (mode == "COMPILE") + { + std::string includes = mf->GetSafeDefinition("PACKAGE_INCLUDE_DIRS"); + std::vector<std::string> includeDirs; + cmSystemTools::ExpandListArgument(includes, includeDirs); + for(std::vector<std::string>::const_iterator dirIt=includeDirs.begin(); + dirIt != includeDirs.end(); + ++dirIt) + { + mf->AddIncludeDirectory(dirIt->c_str(), false); + } + + std::string includeFlags = lg->GetIncludeFlags(language.c_str(), false); + std::string definitions = mf->GetSafeDefinition("PACKAGE_DEFINITIONS"); + printf("%s %s\n", includeFlags.c_str(), definitions.c_str()); + } + else if (mode == "LINK") + { + const char* targetName = "dummy"; + std::vector<std::string> srcs; + cmTarget* tgt = mf->AddExecutable(targetName, srcs, true); + tgt->SetProperty("LINKER_LANGUAGE", language.c_str()); + + std::string libs = mf->GetSafeDefinition("PACKAGE_LIBRARIES"); + std::vector<std::string> libList; + cmSystemTools::ExpandListArgument(libs, libList); + for(std::vector<std::string>::const_iterator libIt=libList.begin(); + libIt != libList.end(); + ++libIt) + { + mf->AddLinkLibraryForTarget(targetName, libIt->c_str(), cmTarget::GENERAL); + } + + + std::string linkLibs; + std::string flags; + std::string linkFlags; + lg->GetTargetFlags(linkLibs, flags, linkFlags, *tgt); + + printf("%s\n", linkLibs.c_str() ); + +/* if ( use_win32 ) + { + tgt->SetProperty("WIN32_EXECUTABLE", "ON"); + } + if ( use_macbundle) + { + tgt->SetProperty("MACOSX_BUNDLE", "ON"); + }*/ + } + + // free generic one if generated +// this->SetGlobalGenerator(0); // setting 0-pointer is not possible +// delete gg; // this crashes inside the cmake instance + + return packageFound; } |