Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable CMake Unity build for Android #2932

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,12 @@ list(APPEND SRC_FILES
${PROJECT_SOURCE_DIR}/src/mbgl/util/work_request.cpp
)

set_source_files_properties(
${PROJECT_SOURCE_DIR}/src/mbgl/style/conversion/geojson.cpp
PROPERTIES
SKIP_UNITY_BUILD_INCLUSION 1
)

if(MLN_WITH_OPENGL)
message(STATUS "Configuring GL-Native with OpenGL renderer backend")
target_compile_definitions(
Expand Down Expand Up @@ -1087,6 +1093,7 @@ if(MLN_WITH_OPENGL)
${PROJECT_SOURCE_DIR}/src/mbgl/gl/attribute.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/command_encoder.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/command_encoder.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/enum.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/context.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/context.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/fence.cpp
Expand All @@ -1095,7 +1102,6 @@ if(MLN_WITH_OPENGL)
${PROJECT_SOURCE_DIR}/src/mbgl/gl/debugging_extension.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/defines.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/draw_scope_resource.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/enum.cpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/enum.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/extension.hpp
${PROJECT_SOURCE_DIR}/src/mbgl/gl/framebuffer.hpp
Expand Down
6 changes: 3 additions & 3 deletions benchmark/function/camera_function.benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using namespace mbgl;
using namespace mbgl::style;

static std::string createFunctionJSON(size_t stopCount) {
static std::string createCameraFunctionJSON(size_t stopCount) {
std::string stops = "[";
for (size_t i = 0; i < stopCount; i++) {
std::string value = std::to_string(24.0f / stopCount * i);
Expand All @@ -25,7 +25,7 @@ static void Parse_CameraFunction(benchmark::State& state) {
while (state.KeepRunning()) {
conversion::Error error;
state.PauseTiming();
auto doc = createFunctionJSON(stopCount);
auto doc = createCameraFunctionJSON(stopCount);
state.ResumeTiming();
std::optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(
doc, error, false, false);
Expand All @@ -38,7 +38,7 @@ static void Parse_CameraFunction(benchmark::State& state) {

static void Evaluate_CameraFunction(benchmark::State& state) {
size_t stopCount = state.range(0);
auto doc = createFunctionJSON(stopCount);
auto doc = createCameraFunctionJSON(stopCount);
conversion::Error error;
std::optional<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(
doc, error, false, false);
Expand Down
6 changes: 3 additions & 3 deletions benchmark/function/composite_function.benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using namespace mbgl;
using namespace mbgl::style;

static std::string createFunctionJSON(size_t stopCount) {
static std::string createCompositeFunctionJSON(size_t stopCount) {
std::string stops = "[";
for (size_t outerStop = 0; outerStop < stopCount; outerStop++) {
for (size_t innerStop = 0; innerStop < stopCount; innerStop++) {
Expand All @@ -31,7 +31,7 @@ static void Parse_CompositeFunction(benchmark::State& state) {
while (state.KeepRunning()) {
conversion::Error error;
state.PauseTiming();
auto doc = createFunctionJSON(stopCount);
auto doc = createCompositeFunctionJSON(stopCount);
state.ResumeTiming();
std::optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(
doc, error, true, false);
Expand All @@ -44,7 +44,7 @@ static void Parse_CompositeFunction(benchmark::State& state) {

static void Evaluate_CompositeFunction(benchmark::State& state) {
size_t stopCount = state.range(0);
auto doc = createFunctionJSON(stopCount);
auto doc = createCompositeFunctionJSON(stopCount);
conversion::Error error;
std::optional<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(
doc, error, true, false);
Expand Down
6 changes: 3 additions & 3 deletions benchmark/function/source_function.benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using namespace mbgl;
using namespace mbgl::style;

static std::string createFunctionJSON(size_t stopCount) {
static std::string createSourceFunctionJSON(size_t stopCount) {
std::string stops = "[";
for (size_t i = 0; i < stopCount; i++) {
std::string value = std::to_string(100.0f / stopCount * i);
Expand All @@ -26,7 +26,7 @@ static void Parse_SourceFunction(benchmark::State& state) {
while (state.KeepRunning()) {
conversion::Error error;
state.PauseTiming();
auto doc = createFunctionJSON(stopCount);
auto doc = createSourceFunctionJSON(stopCount);
state.ResumeTiming();
std::optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(
doc, error, true, false);
Expand All @@ -39,7 +39,7 @@ static void Parse_SourceFunction(benchmark::State& state) {

static void Evaluate_SourceFunction(benchmark::State& state) {
size_t stopCount = state.range(0);
auto doc = createFunctionJSON(stopCount);
auto doc = createSourceFunctionJSON(stopCount);
conversion::Error error;
std::optional<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(
doc, error, true, false);
Expand Down
5 changes: 5 additions & 0 deletions include/mbgl/renderer/change_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,9 @@ class RemoveRenderTargetRequest : public ChangeRequest {
RenderTargetPtr renderTarget;
};

#if MLN_DRAWABLE_RENDERER

void activateRenderTarget(const RenderTargetPtr &renderTarget_, bool activate, UniqueChangeRequestVec &changes);
#endif

} // namespace mbgl
8 changes: 4 additions & 4 deletions include/mbgl/style/layer_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class LayerProperties {
};

template <class Derived>
inline const auto& getEvaluated(const Immutable<LayerProperties>& properties) noexcept {
return static_cast<const Derived&>(*properties).evaluated;
inline const auto& getEvaluated(const Immutable<LayerProperties>& layerProperties) noexcept {
return static_cast<const Derived&>(*layerProperties).evaluated;
}

template <class Derived>
inline const auto& getCrossfade(const Immutable<LayerProperties>& properties) noexcept {
return static_cast<const Derived&>(*properties).crossfade;
inline const auto& getCrossfade(const Immutable<LayerProperties>& layerProperties) noexcept {
return static_cast<const Derived&>(*layerProperties).crossfade;
}

} // namespace style
Expand Down
6 changes: 6 additions & 0 deletions include/mbgl/style/types.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <mbgl/util/enum.hpp>

#include <cstdint>

namespace mbgl {
Expand Down Expand Up @@ -126,4 +128,8 @@ enum class LightAnchorType : bool {
};

} // namespace style

template <>
const char* Enum<style::SymbolAnchorType>::toString(style::SymbolAnchorType t);

} // namespace mbgl
8 changes: 4 additions & 4 deletions include/mbgl/util/bitmask_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
namespace mbgl {

template <typename Enum>
requires std::is_enum_v<Enum>
constexpr Enum operator|(Enum a, Enum b) {
static_assert(std::is_enum_v<Enum>, "Enum must be an enum type");
return Enum(mbgl::underlying_type(a) | mbgl::underlying_type(b));
}

template <typename Enum>
requires std::is_enum_v<Enum>
constexpr Enum& operator|=(Enum& a, Enum b) {
static_assert(std::is_enum_v<Enum>, "Enum must be an enum type");
return (a = a | b);
}

template <typename Enum>
requires std::is_enum_v<Enum>
constexpr bool operator&(Enum a, Enum b) {
static_assert(std::is_enum_v<Enum>, "Enum must be an enum type");
return bool(mbgl::underlying_type(a) & mbgl::underlying_type(b));
}

template <typename Enum>
requires std::is_enum_v<Enum>
constexpr Enum operator~(Enum value) {
static_assert(std::is_enum_v<Enum>, "Enum must be an enum type");
return Enum(~mbgl::underlying_type(value));
}

Expand Down
5 changes: 5 additions & 0 deletions include/mbgl/util/enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ class Enum {
return it == std::end(T##_names) ? std::optional<T>() : it->first; \
}

template <typename T>
constexpr uint8_t toUint8(T t) noexcept {
return uint8_t(mbgl::underlying_type(t));
}

} // namespace mbgl
7 changes: 4 additions & 3 deletions platform/android/MapLibreAndroid/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ android {

externalNativeBuild {
cmake {
arguments("-DMLN_LEGACY_RENDERER=ON", "-DMLN_DRAWABLE_RENDERER=OFF")
arguments.addAll(listOf())
}
}
}
Expand All @@ -77,22 +77,23 @@ android {
dimension = "renderer"
externalNativeBuild {
cmake {
arguments("-DMLN_LEGACY_RENDERER=ON", "-DMLN_DRAWABLE_RENDERER=OFF")
arguments.addAll(listOf("-DMLN_LEGACY_RENDERER=ON", "-DMLN_DRAWABLE_RENDERER=OFF"))
}
}
}
create("drawable") {
dimension = "renderer"
externalNativeBuild {
cmake {
arguments("-DMLN_LEGACY_RENDERER=OFF", "-DMLN_DRAWABLE_RENDERER=ON")
arguments.addAll(listOf("-DMLN_LEGACY_RENDERER=OFF", "-DMLN_DRAWABLE_RENDERER=ON", "-DCMAKE_UNITY_BUILD=ON"))
}
}
}
create("vulkan") {
dimension = "renderer"
externalNativeBuild {
cmake {
// arguments.addAll(listOf("-DMLN_LEGACY_RENDERER=OFF", "-DMLN_DRAWABLE_RENDERER=ON", "-DMLN_WITH_OPENGL=OFF", "-DMLN_WITH_VULKAN=ON"))
arguments("-DMLN_LEGACY_RENDERER=OFF", "-DMLN_DRAWABLE_RENDERER=ON")
arguments("-DMLN_WITH_OPENGL=OFF", "-DMLN_WITH_VULKAN=ON")
}
Expand Down
4 changes: 4 additions & 0 deletions platform/android/MapLibreAndroid/src/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,8 @@ target_link_libraries(maplibre
mbgl-core
mbgl-vendor-unique_resource)

set_target_properties(maplibre PROPERTIES
UNITY_BUILD OFF
)

install(TARGETS maplibre LIBRARY DESTINATION lib)
8 changes: 7 additions & 1 deletion platform/android/android.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ target_sources(
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/mbtiles_file_source.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/main_resource_loader.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/sqlite3.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_database.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/offline_download.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/online_file_source.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/storage/sqlite3.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/text/bidi.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/compression.cpp
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/util/filesystem.cpp
Expand All @@ -72,6 +72,12 @@ target_sources(
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/layermanager/layer_manager.cpp
)

set_source_files_properties(
${PROJECT_SOURCE_DIR}/platform/default/src/mbgl/layermanager/layer_manager.cpp
PROPERTIES
SKIP_UNITY_BUILD_INCLUSION 1
)

if(MLN_WITH_OPENGL)
target_sources(
mbgl-core
Expand Down
6 changes: 6 additions & 0 deletions platform/default/include/mbgl/storage/sqlite3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ class Query {
Statement& stmt;
};

template <>
std::string Query::get(int offset);

template <>
std::optional<std::string> Query::get(int offset);

class Transaction {
public:
Transaction(const Transaction&) = delete;
Expand Down
8 changes: 4 additions & 4 deletions platform/default/src/mbgl/storage/asset_file_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <mbgl/util/url.hpp>

namespace {
bool acceptsURL(const std::string& url) {
return 0 == url.rfind(mbgl::util::ASSET_PROTOCOL, 0);
bool isAssetURL(const std::string& url) {
return url.starts_with(mbgl::util::ASSET_PROTOCOL);
}
} // namespace

Expand All @@ -27,7 +27,7 @@ class AssetFileSource::Impl {
clientOptions(clientOptions_.clone()) {}

void request(const std::string& url, const ActorRef<FileSourceRequest>& req) {
if (!acceptsURL(url)) {
if (!isAssetURL(url)) {
Response response;
response.error = std::make_unique<Response::Error>(Response::Error::Reason::Other, "Invalid asset URL");
req.invoke(&FileSourceRequest::setResponse, response);
Expand Down Expand Up @@ -86,7 +86,7 @@ std::unique_ptr<AsyncRequest> AssetFileSource::request(const Resource& resource,
}

bool AssetFileSource::canRequest(const Resource& resource) const {
return acceptsURL(resource.url);
return isAssetURL(resource.url);
}

void AssetFileSource::pause() {
Expand Down
8 changes: 4 additions & 4 deletions platform/default/src/mbgl/storage/local_file_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <mbgl/storage/resource_options.hpp>

namespace {
bool acceptsURL(const std::string& url) {
return 0 == url.rfind(mbgl::util::FILE_PROTOCOL, 0);
bool isFileURL(const std::string& url) {
return url.starts_with(mbgl::util::FILE_PROTOCOL);
}
} // namespace

Expand All @@ -26,7 +26,7 @@ class LocalFileSource::Impl {
clientOptions(clientOptions_.clone()) {}

void request(const std::string& url, const ActorRef<FileSourceRequest>& req) {
if (!acceptsURL(url)) {
if (!isFileURL(url)) {
Response response;
response.error = std::make_unique<Response::Error>(Response::Error::Reason::Other, "Invalid file URL");
req.invoke(&FileSourceRequest::setResponse, response);
Expand Down Expand Up @@ -83,7 +83,7 @@ std::unique_ptr<AsyncRequest> LocalFileSource::request(const Resource& resource,
}

bool LocalFileSource::canRequest(const Resource& resource) const {
return acceptsURL(resource.url);
return isFileURL(resource.url);
}

void LocalFileSource::pause() {
Expand Down
6 changes: 3 additions & 3 deletions platform/default/src/mbgl/storage/mbtiles_file_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#endif

namespace {
bool acceptsURL(const std::string &url) {
return 0 == url.rfind(mbgl::util::MBTILES_PROTOCOL, 0);
bool isMBTilesURL(const std::string &url) {
return url.starts_with(mbgl::util::MBTILES_PROTOCOL);
}

std::string url_to_path(const std::string &url) {
Expand Down Expand Up @@ -313,7 +313,7 @@ std::unique_ptr<AsyncRequest> MBTilesFileSource::request(const Resource &resourc
}

bool MBTilesFileSource::canRequest(const Resource &resource) const {
return acceptsURL(resource.url);
return isMBTilesURL(resource.url);
}

MBTilesFileSource::~MBTilesFileSource() = default;
Expand Down
6 changes: 4 additions & 2 deletions scripts/style-code.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ export function iff(condition, val) {

/**
* @param {string} str
* @param {boolean=} pascalCase
* @returns {string}
*/
export function camelize(str) {
return str.replace(/(?:^|-)(.)/g, function (_, x) {
export function camelize(str, pascalCase = true) {
const pascalCaseStr = str.replace(/(?:^|-)(.)/g, function (_, x) {
return x.toUpperCase();
});
return pascalCase ? pascalCaseStr : pascalCaseStr.charAt(0).toLowerCase() + pascalCaseStr.slice(1);
};

/**
Expand Down
4 changes: 2 additions & 2 deletions src/mbgl/gfx/drawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ void Drawable::setIndexData(std::vector<std::uint16_t> indexes, std::vector<Uniq
setIndexData(std::make_shared<gfx::IndexVectorBase>(std::move(indexes)), std::move(segments));
}

static const gfx::Texture2DPtr noTexture;

const gfx::Texture2DPtr& Drawable::getTexture(size_t id) const {
static const gfx::Texture2DPtr noTexture;

return (id < textures.size()) ? textures[id] : noTexture;
}

Expand Down
3 changes: 1 addition & 2 deletions src/mbgl/gfx/drawable_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ void DrawableBuilder::resetDrawPriority(DrawPriority value) {
}
}

static const gfx::Texture2DPtr noTexture;

const gfx::Texture2DPtr& DrawableBuilder::getTexture(size_t id) const {
static const gfx::Texture2DPtr noTexture;
return (id < textures.size()) ? textures[id] : noTexture;
}

Expand Down
Loading
Loading