cmake/Source/cmExportBuildAndroidMKGenerator.cxx

194 lines
6.5 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmExportBuildAndroidMKGenerator.h"
2017-04-14 19:02:05 +02:00
#include <sstream>
#include <utility>
2020-08-30 11:54:41 +02:00
#include <cmext/algorithm>
2016-10-30 18:24:19 +01:00
#include "cmGeneratorTarget.h"
2017-04-14 19:02:05 +02:00
#include "cmLinkItem.h"
2016-10-30 18:24:19 +01:00
#include "cmMakefile.h"
2019-11-11 23:01:05 +01:00
#include "cmMessageType.h"
2017-04-14 19:02:05 +02:00
#include "cmPolicies.h"
#include "cmStateTypes.h"
2020-02-01 23:06:01 +01:00
#include "cmStringAlgorithms.h"
2017-04-14 19:02:05 +02:00
#include "cmSystemTools.h"
#include "cmTarget.h"
2016-10-30 18:24:19 +01:00
cmExportBuildAndroidMKGenerator::cmExportBuildAndroidMKGenerator()
{
2018-01-26 17:06:56 +01:00
this->LG = nullptr;
this->ExportSet = nullptr;
2016-10-30 18:24:19 +01: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-08-09 18:06:22 +02:00
std::ostream& os, cmGeneratorTarget const* target,
cmStateEnums::TargetType /*targetType*/)
2016-10-30 18:24:19 +01:00
{
2020-02-01 23:06:01 +01:00
std::string targetName = cmStrCat(this->Namespace, target->GetExportName());
2016-10-30 18:24:19 +01:00
os << "include $(CLEAR_VARS)\n";
os << "LOCAL_MODULE := ";
os << targetName << "\n";
os << "LOCAL_SRC_FILES := ";
2020-08-30 11:54:41 +02:00
std::string const noConfig; // FIXME: What config to use here?
std::string path =
cmSystemTools::ConvertToOutputPath(target->GetFullPath(noConfig));
2016-10-30 18:24:19 +01: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)
{
2017-04-14 19:02:05 +02:00
std::string config;
2016-10-30 18:24:19 +01:00
if (!this->Configurations.empty()) {
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.";
2019-11-11 23:01:05 +01:00
target->Makefile->IssueMessage(MessageType::AUTHOR_WARNING, w.str());
2016-10-30 18:24:19 +01:00
}
if (!properties.empty()) {
os << "LOCAL_CPP_FEATURES := rtti exceptions\n";
2018-01-26 17:06:56 +01:00
for (auto const& property : properties) {
if (property.first == "INTERFACE_COMPILE_OPTIONS") {
2016-10-30 18:24:19 +01:00
os << "LOCAL_CPP_FEATURES += ";
2018-01-26 17:06:56 +01:00
os << (property.second) << "\n";
} else if (property.first == "INTERFACE_LINK_LIBRARIES") {
2016-10-30 18:24:19 +01:00
std::string staticLibs;
std::string sharedLibs;
std::string ldlibs;
2018-10-28 12:09:07 +01: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-10-30 18:24:19 +01:00
if (gt) {
2017-04-14 19:02:05 +02:00
if (gt->GetType() == cmStateEnums::SHARED_LIBRARY ||
gt->GetType() == cmStateEnums::MODULE_LIBRARY) {
2018-01-26 17:06:56 +01:00
sharedLibs += " " + lib;
2016-10-30 18:24:19 +01:00
} else {
2018-01-26 17:06:56 +01:00
staticLibs += " " + lib;
2016-10-30 18:24:19 +01:00
}
} else {
bool relpath = false;
if (type == cmExportBuildAndroidMKGenerator::INSTALL) {
2020-08-30 11:54:41 +02:00
relpath = cmHasLiteralPrefix(lib, "../");
2016-10-30 18:24:19 +01: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-04-23 21:13:27 +02:00
if (cmSystemTools::FileIsFullPath(lib) ||
2020-08-30 11:54:41 +02:00
cmHasLiteralPrefix(lib, "-l") || relpath) {
2018-04-23 21:13:27 +02:00
ldlibs += " " + lib;
2016-10-30 18:24:19 +01:00
// if it is not a path and does not have a -l then add -l
2018-04-23 21:13:27 +02:00
} else if (!lib.empty()) {
ldlibs += " -l" + lib;
2016-10-30 18:24:19 +01: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";
}
2018-01-26 17:06:56 +01:00
} else if (property.first == "INTERFACE_INCLUDE_DIRECTORIES") {
std::string includes = property.second;
2020-02-01 23:06:01 +01:00
std::vector<std::string> includeList = cmExpandedList(includes);
2016-10-30 18:24:19 +01:00
os << "LOCAL_EXPORT_C_INCLUDES := ";
std::string end;
2018-01-26 17:06:56 +01:00
for (std::string const& i : includeList) {
os << end << i;
2016-10-30 18:24:19 +01:00
end = "\\\n";
}
os << "\n";
2018-10-28 12:09:07 +01:00
} else if (property.first == "INTERFACE_LINK_OPTIONS") {
os << "LOCAL_EXPORT_LDFLAGS := ";
2020-02-01 23:06:01 +01:00
std::vector<std::string> linkFlagsList =
cmExpandedList(property.second);
2018-10-28 12:09:07 +01:00
os << cmJoin(linkFlagsList, " ") << "\n";
2016-10-30 18:24:19 +01:00
} else {
2018-01-26 17:06:56 +01:00
os << "# " << property.first << " " << (property.second) << "\n";
2016-10-30 18:24:19 +01:00
}
}
}
// Tell the NDK build system if prebuilt static libraries use C++.
2017-04-14 19:02:05 +02:00
if (target->GetType() == cmStateEnums::STATIC_LIBRARY) {
2016-10-30 18:24:19 +01:00
cmLinkImplementation const* li = target->GetLinkImplementation(config);
2020-08-30 11:54:41 +02:00
if (cm::contains(li->Languages, "CXX")) {
2016-10-30 18:24:19 +01:00
os << "LOCAL_HAS_CPP := true\n";
}
}
switch (target->GetType()) {
2017-04-14 19:02:05 +02:00
case cmStateEnums::SHARED_LIBRARY:
case cmStateEnums::MODULE_LIBRARY:
2016-10-30 18:24:19 +01:00
os << "include $(PREBUILT_SHARED_LIBRARY)\n";
break;
2017-04-14 19:02:05 +02:00
case cmStateEnums::STATIC_LIBRARY:
2016-10-30 18:24:19 +01:00
os << "include $(PREBUILT_STATIC_LIBRARY)\n";
break;
2017-04-14 19:02:05 +02:00
case cmStateEnums::EXECUTABLE:
case cmStateEnums::UTILITY:
case cmStateEnums::OBJECT_LIBRARY:
case cmStateEnums::GLOBAL_TARGET:
case cmStateEnums::INTERFACE_LIBRARY:
case cmStateEnums::UNKNOWN_LIBRARY:
2016-10-30 18:24:19 +01:00
break;
}
os << "\n";
}