diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2016-07-12 17:26:55 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2016-09-13 16:47:43 (GMT) |
commit | 42ce9f1e7178b3535726c0c885cc7c9f760cc8b6 (patch) | |
tree | 6ebd228d18eb0b08ff2d950900574dd29caad95d /Source/cmInstallCommand.cxx | |
parent | d5257063b04a95aca3d144f860698a3c7181e554 (diff) | |
download | CMake-42ce9f1e7178b3535726c0c885cc7c9f760cc8b6.zip CMake-42ce9f1e7178b3535726c0c885cc7c9f760cc8b6.tar.gz CMake-42ce9f1e7178b3535726c0c885cc7c9f760cc8b6.tar.bz2 |
Add support for creating prebuilt Android.mk files
Add options to the `install()` and `export()` commands to export the
targets we build into Android.mk files that reference them as prebuilt
libraries with associated usage requirements (compile definitions,
include directories, link libraries). This will allow CMake-built
projects to be imported into projects using the Android NDK build
system.
Closes: #15562
Diffstat (limited to 'Source/cmInstallCommand.cxx')
-rw-r--r-- | Source/cmInstallCommand.cxx | 98 |
1 files changed, 97 insertions, 1 deletions
diff --git a/Source/cmInstallCommand.cxx b/Source/cmInstallCommand.cxx index 4912eac..e464bce 100644 --- a/Source/cmInstallCommand.cxx +++ b/Source/cmInstallCommand.cxx @@ -83,6 +83,8 @@ bool cmInstallCommand::InitialPass(std::vector<std::string> const& args, return this->HandleDirectoryMode(args); } else if (args[0] == "EXPORT") { return this->HandleExportMode(args); + } else if (args[0] == "EXPORT_ANDROID_MK") { + return this->HandleExportAndroidMKMode(args); } // Unknown mode. @@ -1097,6 +1099,100 @@ bool cmInstallCommand::HandleDirectoryMode( return true; } +bool cmInstallCommand::HandleExportAndroidMKMode( + std::vector<std::string> const& args) +{ +#ifdef CMAKE_BUILD_WITH_CMAKE + // This is the EXPORT mode. + cmInstallCommandArguments ica(this->DefaultComponentName); + cmCAString exp(&ica.Parser, "EXPORT_ANDROID_MK"); + cmCAString name_space(&ica.Parser, "NAMESPACE", &ica.ArgumentGroup); + cmCAEnabler exportOld(&ica.Parser, "EXPORT_LINK_INTERFACE_LIBRARIES", + &ica.ArgumentGroup); + cmCAString filename(&ica.Parser, "FILE", &ica.ArgumentGroup); + exp.Follows(0); + + ica.ArgumentGroup.Follows(&exp); + std::vector<std::string> unknownArgs; + ica.Parse(&args, &unknownArgs); + + if (!unknownArgs.empty()) { + // Unknown argument. + std::ostringstream e; + e << args[0] << " given unknown argument \"" << unknownArgs[0] << "\"."; + this->SetError(e.str()); + return false; + } + + if (!ica.Finalize()) { + return false; + } + + // Make sure there is a destination. + if (ica.GetDestination().empty()) { + // A destination is required. + std::ostringstream e; + e << args[0] << " given no DESTINATION!"; + this->SetError(e.str()); + return false; + } + + // Check the file name. + std::string fname = filename.GetString(); + if (fname.find_first_of(":/\\") != fname.npos) { + std::ostringstream e; + e << args[0] << " given invalid export file name \"" << fname << "\". " + << "The FILE argument may not contain a path. " + << "Specify the path in the DESTINATION argument."; + this->SetError(e.str()); + return false; + } + + // Check the file extension. + if (!fname.empty() && + cmSystemTools::GetFilenameLastExtension(fname) != ".mk") { + std::ostringstream e; + e << args[0] << " given invalid export file name \"" << fname << "\". " + << "The FILE argument must specify a name ending in \".mk\"."; + this->SetError(e.str()); + return false; + } + if (fname.find_first_of(":/\\") != fname.npos) { + std::ostringstream e; + e << args[0] << " given export name \"" << exp.GetString() << "\". " + << "This name cannot be safely converted to a file name. " + << "Specify a different export name or use the FILE option to set " + << "a file name explicitly."; + this->SetError(e.str()); + return false; + } + // Use the default name + if (fname.empty()) { + fname = "Android.mk"; + } + + cmExportSet* exportSet = + this->Makefile->GetGlobalGenerator()->GetExportSets()[exp.GetString()]; + + cmInstallGenerator::MessageLevel message = + cmInstallGenerator::SelectMessageLevel(this->Makefile); + + // Create the export install generator. + cmInstallExportGenerator* exportGenerator = new cmInstallExportGenerator( + exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(), + ica.GetConfigurations(), ica.GetComponent().c_str(), message, + ica.GetExcludeFromAll(), fname.c_str(), name_space.GetCString(), + exportOld.IsEnabled(), true); + this->Makefile->AddInstallGenerator(exportGenerator); + + return true; +#else + static_cast<void>(args); + this->SetError("EXPORT_ANDROID_MK not supported in bootstrap cmake"); + return false; +#endif +} + bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args) { // This is the EXPORT mode. @@ -1203,7 +1299,7 @@ bool cmInstallCommand::HandleExportMode(std::vector<std::string> const& args) exportSet, ica.GetDestination().c_str(), ica.GetPermissions().c_str(), ica.GetConfigurations(), ica.GetComponent().c_str(), message, ica.GetExcludeFromAll(), fname.c_str(), name_space.GetCString(), - exportOld.IsEnabled()); + exportOld.IsEnabled(), false); this->Makefile->AddInstallGenerator(exportGenerator); return true; |