2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2016-07-12 17:26:55 +00:00
|
|
|
#include "cmExportBuildAndroidMKGenerator.h"
|
|
|
|
|
2016-11-05 20:40:14 +00:00
|
|
|
#include <sstream>
|
|
|
|
#include <utility>
|
|
|
|
|
2019-08-19 12:31:52 +00:00
|
|
|
#include "cmAlgorithms.h"
|
2016-07-12 17:26:55 +00:00
|
|
|
#include "cmGeneratorTarget.h"
|
2016-11-05 20:40:14 +00:00
|
|
|
#include "cmLinkItem.h"
|
2016-07-12 17:26:55 +00:00
|
|
|
#include "cmMakefile.h"
|
2018-11-22 03:36:50 +00:00
|
|
|
#include "cmMessageType.h"
|
2016-11-05 20:40:14 +00:00
|
|
|
#include "cmPolicies.h"
|
|
|
|
#include "cmStateTypes.h"
|
2019-07-29 10:16:40 +00:00
|
|
|
#include "cmStringAlgorithms.h"
|
2016-11-05 20:40:14 +00:00
|
|
|
#include "cmSystemTools.h"
|
|
|
|
#include "cmTarget.h"
|
2016-10-07 18:57:26 +00:00
|
|
|
|
2016-07-12 17:26:55 +00:00
|
|
|
cmExportBuildAndroidMKGenerator::cmExportBuildAndroidMKGenerator()
|
|
|
|
{
|
2017-08-22 21:42:36 +00:00
|
|
|
this->LG = nullptr;
|
|
|
|
this->ExportSet = nullptr;
|
2016-07-12 17:26:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmExportBuildAndroidMKGenerator::GenerateImportHeaderCode(
|
|
|
|
std::ostream& os, const std::string&)
|
|
|
|
{
|
|
|
|
os << "LOCAL_PATH := $(call my-dir)\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmExportBuildAndroidMKGenerator::GenerateImportFooterCode(std::ostream&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmExportBuildAndroidMKGenerator::GenerateExpectedTargetsCode(
|
|
|
|
std::ostream&, const std::string&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmExportBuildAndroidMKGenerator::GenerateImportTargetCode(
|
2018-02-28 15:58:07 +00:00
|
|
|
std::ostream& os, cmGeneratorTarget const* target,
|
|
|
|
cmStateEnums::TargetType /*targetType*/)
|
2016-07-12 17:26:55 +00:00
|
|
|
{
|
2019-08-22 14:34:40 +00:00
|
|
|
std::string targetName = cmStrCat(this->Namespace, target->GetExportName());
|
2016-07-12 17:26:55 +00:00
|
|
|
os << "include $(CLEAR_VARS)\n";
|
|
|
|
os << "LOCAL_MODULE := ";
|
|
|
|
os << targetName << "\n";
|
|
|
|
os << "LOCAL_SRC_FILES := ";
|
2018-01-31 15:20:02 +00:00
|
|
|
std::string path = cmSystemTools::ConvertToOutputPath(target->GetFullPath());
|
2016-07-12 17:26:55 +00:00
|
|
|
os << path << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmExportBuildAndroidMKGenerator::GenerateImportPropertyCode(
|
|
|
|
std::ostream&, const std::string&, cmGeneratorTarget const*,
|
|
|
|
ImportPropertyMap const&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmExportBuildAndroidMKGenerator::GenerateMissingTargetsCheckCode(
|
|
|
|
std::ostream&, const std::vector<std::string>&)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties(
|
|
|
|
const cmGeneratorTarget* target, std::ostream& os,
|
|
|
|
const ImportPropertyMap& properties)
|
|
|
|
{
|
2016-12-10 13:53:06 +00:00
|
|
|
std::string config;
|
2016-09-15 21:59:29 +00:00
|
|
|
if (!this->Configurations.empty()) {
|
2016-07-12 17:26:55 +00:00
|
|
|
config = this->Configurations[0];
|
|
|
|
}
|
|
|
|
cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties(
|
|
|
|
target, os, properties, cmExportBuildAndroidMKGenerator::BUILD, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmExportBuildAndroidMKGenerator::GenerateInterfaceProperties(
|
|
|
|
const cmGeneratorTarget* target, std::ostream& os,
|
|
|
|
const ImportPropertyMap& properties, GenerateType type,
|
|
|
|
std::string const& config)
|
|
|
|
{
|
|
|
|
const bool newCMP0022Behavior =
|
|
|
|
target->GetPolicyStatusCMP0022() != cmPolicies::WARN &&
|
|
|
|
target->GetPolicyStatusCMP0022() != cmPolicies::OLD;
|
|
|
|
if (!newCMP0022Behavior) {
|
|
|
|
std::ostringstream w;
|
|
|
|
if (type == cmExportBuildAndroidMKGenerator::BUILD) {
|
|
|
|
w << "export(TARGETS ... ANDROID_MK) called with policy CMP0022";
|
|
|
|
} else {
|
|
|
|
w << "install( EXPORT_ANDROID_MK ...) called with policy CMP0022";
|
|
|
|
}
|
|
|
|
w << " set to OLD for target " << target->Target->GetName() << ". "
|
|
|
|
<< "The export will only work with CMP0022 set to NEW.";
|
2018-11-22 03:36:50 +00:00
|
|
|
target->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
|
2016-07-12 17:26:55 +00:00
|
|
|
}
|
|
|
|
if (!properties.empty()) {
|
|
|
|
os << "LOCAL_CPP_FEATURES := rtti exceptions\n";
|
2017-09-11 10:40:26 +00:00
|
|
|
for (auto const& property : properties) {
|
|
|
|
if (property.first == "INTERFACE_COMPILE_OPTIONS") {
|
2016-07-12 17:26:55 +00:00
|
|
|
os << "LOCAL_CPP_FEATURES += ";
|
2017-09-11 10:40:26 +00:00
|
|
|
os << (property.second) << "\n";
|
|
|
|
} else if (property.first == "INTERFACE_LINK_LIBRARIES") {
|
2016-07-12 17:26:55 +00:00
|
|
|
std::string staticLibs;
|
|
|
|
std::string sharedLibs;
|
|
|
|
std::string ldlibs;
|
2018-09-10 13:40:01 +00:00
|
|
|
cmLinkInterfaceLibraries const* linkIFace =
|
|
|
|
target->GetLinkInterfaceLibraries(config, target, false);
|
|
|
|
for (cmLinkItem const& item : linkIFace->Libraries) {
|
|
|
|
cmGeneratorTarget const* gt = item.Target;
|
|
|
|
std::string const& lib = item.AsStr();
|
2016-07-12 17:26:55 +00:00
|
|
|
if (gt) {
|
|
|
|
|
2016-10-18 19:28:46 +00:00
|
|
|
if (gt->GetType() == cmStateEnums::SHARED_LIBRARY ||
|
|
|
|
gt->GetType() == cmStateEnums::MODULE_LIBRARY) {
|
2017-09-11 10:40:26 +00:00
|
|
|
sharedLibs += " " + lib;
|
2016-07-12 17:26:55 +00:00
|
|
|
} else {
|
2017-09-11 10:40:26 +00:00
|
|
|
staticLibs += " " + lib;
|
2016-07-12 17:26:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bool relpath = false;
|
|
|
|
if (type == cmExportBuildAndroidMKGenerator::INSTALL) {
|
2017-09-11 10:40:26 +00:00
|
|
|
relpath = lib.substr(0, 3) == "../";
|
2016-07-12 17:26:55 +00:00
|
|
|
}
|
|
|
|
// check for full path or if it already has a -l, or
|
|
|
|
// in the case of an install check for relative paths
|
|
|
|
// if it is full or a link library then use string directly
|
2018-02-14 16:09:55 +00:00
|
|
|
if (cmSystemTools::FileIsFullPath(lib) ||
|
|
|
|
lib.substr(0, 2) == "-l" || relpath) {
|
|
|
|
ldlibs += " " + lib;
|
2016-07-12 17:26:55 +00:00
|
|
|
// if it is not a path and does not have a -l then add -l
|
2018-02-14 16:09:55 +00:00
|
|
|
} else if (!lib.empty()) {
|
|
|
|
ldlibs += " -l" + lib;
|
2016-07-12 17:26:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!sharedLibs.empty()) {
|
|
|
|
os << "LOCAL_SHARED_LIBRARIES :=" << sharedLibs << "\n";
|
|
|
|
}
|
|
|
|
if (!staticLibs.empty()) {
|
|
|
|
os << "LOCAL_STATIC_LIBRARIES :=" << staticLibs << "\n";
|
|
|
|
}
|
|
|
|
if (!ldlibs.empty()) {
|
|
|
|
os << "LOCAL_EXPORT_LDLIBS :=" << ldlibs << "\n";
|
|
|
|
}
|
2017-09-11 10:40:26 +00:00
|
|
|
} else if (property.first == "INTERFACE_INCLUDE_DIRECTORIES") {
|
|
|
|
std::string includes = property.second;
|
2019-08-23 14:17:39 +00:00
|
|
|
std::vector<std::string> includeList = cmExpandedList(includes);
|
2016-07-12 17:26:55 +00:00
|
|
|
os << "LOCAL_EXPORT_C_INCLUDES := ";
|
|
|
|
std::string end;
|
2017-09-11 10:40:26 +00:00
|
|
|
for (std::string const& i : includeList) {
|
|
|
|
os << end << i;
|
2016-07-12 17:26:55 +00:00
|
|
|
end = "\\\n";
|
|
|
|
}
|
|
|
|
os << "\n";
|
2018-04-24 15:01:01 +00:00
|
|
|
} else if (property.first == "INTERFACE_LINK_OPTIONS") {
|
|
|
|
os << "LOCAL_EXPORT_LDFLAGS := ";
|
2019-08-23 14:17:39 +00:00
|
|
|
std::vector<std::string> linkFlagsList =
|
|
|
|
cmExpandedList(property.second);
|
2018-04-24 15:01:01 +00:00
|
|
|
os << cmJoin(linkFlagsList, " ") << "\n";
|
2016-07-12 17:26:55 +00:00
|
|
|
} else {
|
2017-09-11 10:40:26 +00:00
|
|
|
os << "# " << property.first << " " << (property.second) << "\n";
|
2016-07-12 17:26:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-07 18:57:26 +00:00
|
|
|
|
|
|
|
// Tell the NDK build system if prebuilt static libraries use C++.
|
2016-10-18 19:28:46 +00:00
|
|
|
if (target->GetType() == cmStateEnums::STATIC_LIBRARY) {
|
2016-10-07 18:57:26 +00:00
|
|
|
cmLinkImplementation const* li = target->GetLinkImplementation(config);
|
2019-08-19 12:31:52 +00:00
|
|
|
if (cmContains(li->Languages, "CXX")) {
|
2016-10-07 18:57:26 +00:00
|
|
|
os << "LOCAL_HAS_CPP := true\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-12 17:26:55 +00:00
|
|
|
switch (target->GetType()) {
|
2016-10-18 19:28:46 +00:00
|
|
|
case cmStateEnums::SHARED_LIBRARY:
|
|
|
|
case cmStateEnums::MODULE_LIBRARY:
|
2016-07-12 17:26:55 +00:00
|
|
|
os << "include $(PREBUILT_SHARED_LIBRARY)\n";
|
|
|
|
break;
|
2016-10-18 19:28:46 +00:00
|
|
|
case cmStateEnums::STATIC_LIBRARY:
|
2016-07-12 17:26:55 +00:00
|
|
|
os << "include $(PREBUILT_STATIC_LIBRARY)\n";
|
|
|
|
break;
|
2016-10-18 19:28:46 +00:00
|
|
|
case cmStateEnums::EXECUTABLE:
|
|
|
|
case cmStateEnums::UTILITY:
|
|
|
|
case cmStateEnums::OBJECT_LIBRARY:
|
|
|
|
case cmStateEnums::GLOBAL_TARGET:
|
|
|
|
case cmStateEnums::INTERFACE_LIBRARY:
|
|
|
|
case cmStateEnums::UNKNOWN_LIBRARY:
|
2016-07-12 17:26:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
os << "\n";
|
|
|
|
}
|