# Sets the minimum version of CMake required to build your native library.
# This ensures that a certain set of CMake features is available to
# your build.

cmake_minimum_required(VERSION 3.10)

project(PanoPainterAndroidNative LANGUAGES C CXX)

include(../cmake/PanoPainterAndroidVendorPatches.cmake)
pp_apply_android_nanort_patch()

link_directories(
	../../libs/curl-android-ios/android/${ANDROID_ABI}
	../../libs/mp4v2/lib/android/${ANDROID_ABI}
)

# build native_app_glue as a static lib
add_library(
	app-glue STATIC
	../../libs/native_app_glue/android_native_app_glue.c
)

add_library(openh264 SHARED IMPORTED)
set_target_properties(openh264 PROPERTIES IMPORTED_LOCATION
	${CMAKE_SOURCE_DIR}/../../libs/openh264/lib/android/${ANDROID_ABI}/libopenh264.so)

add_library(yuv SHARED IMPORTED)
set_target_properties(yuv PROPERTIES IMPORTED_LOCATION
	${CMAKE_SOURCE_DIR}/../../libs/libyuv/lib/android/${ANDROID_ABI}/libyuv.so)

set(PP_MODERN_COMPONENT_SOURCES
	../../src/app_core/document_export.cpp
	../../src/app_core/document_route.cpp
	../../src/app_core/document_session.cpp
	../../src/assets/brush_package.cpp
	../../src/assets/image_format.cpp
	../../src/assets/image_metadata.cpp
	../../src/assets/image_pixels.cpp
	../../src/assets/ppi_header.cpp
	../../src/assets/settings_document.cpp
	../../src/document/document.cpp
	../../src/document/ppi_export.cpp
	../../src/document/ppi_import.cpp
	../../src/foundation/binary_stream.cpp
	../../src/foundation/event.cpp
	../../src/foundation/log.cpp
	../../src/foundation/parse.cpp
	../../src/foundation/task_queue.cpp
	../../src/foundation/trace.cpp
	../../src/paint/blend.cpp
	../../src/paint/brush.cpp
	../../src/paint/stroke.cpp
	../../src/paint/stroke_script.cpp
	../../src/paint_renderer/compositor.cpp
	../../src/platform_api/asset_file_load_policy.cpp
	../../src/platform_api/network_tls_policy.cpp
	../../src/platform_api/platform_policy.cpp
	../../src/platform_api/platform_services.cpp
	../../src/platform_legacy/legacy_platform_services.cpp
	../../src/renderer_api/recording_renderer.cpp
	../../src/renderer_api/renderer_api.cpp
	../../src/renderer_api/shader_catalog.cpp
	../../src/renderer_gl/command_plan.cpp
	../../src/renderer_gl/opengl_capabilities.cpp
	../../src/renderer_gl/shader_bindings.cpp
	../../src/legacy_app_dialog_services.cpp
	../../src/legacy_app_preference_services.cpp
	../../src/legacy_app_shell_services.cpp
	../../src/legacy_app_startup_services.cpp
	../../src/legacy_brush_package_export_services.cpp
	../../src/legacy_brush_package_import_services.cpp
	../../src/legacy_brush_ui_services.cpp
	../../src/legacy_canvas_tool_services.cpp
	../../src/legacy_canvas_view_services.cpp
	../../src/legacy_cloud_services.cpp
	../../src/legacy_document_animation_services.cpp
	../../src/legacy_document_canvas_services.cpp
	../../src/legacy_document_export_services.cpp
	../../src/legacy_document_layer_services.cpp
	../../src/legacy_document_open_services.cpp
	../../src/legacy_document_session_services.cpp
	../../src/legacy_grid_ui_services.cpp
	../../src/legacy_history_services.cpp
	../../src/legacy_preference_storage.cpp
	../../src/legacy_quick_ui_services.cpp
	../../src/legacy_recording_services.cpp
	../../src/legacy_ui_overlay_services.cpp
)

add_library(
	native-lib SHARED
	${PP_MODERN_COMPONENT_SOURCES}
	../../libs/yoga/yoga/event/event.cpp
	../../libs/yoga/yoga/internal/experiments.cpp
	../../libs/yoga/yoga/log.cpp
	../../libs/yoga/yoga/Utils.cpp
	../../libs/yoga/yoga/YGConfig.cpp
	../../libs/yoga/yoga/YGEnums.cpp
	../../libs/yoga/yoga/YGLayout.cpp
	../../libs/yoga/yoga/YGNode.cpp
	../../libs/yoga/yoga/YGNodePrint.cpp
	../../libs/yoga/yoga/YGStyle.cpp
	../../libs/yoga/yoga/YGValue.cpp
	../../libs/yoga/yoga/Yoga.cpp
	../../libs/tinyxml2/tinyxml2.cpp
	../../libs/jpeg/jpgd.cpp
	../../libs/jpeg/jpge.cpp
	../../libs/poly2tri/poly2tri/common/shapes.cc
	../../libs/poly2tri/poly2tri/sweep/advancing_front.cc
	../../libs/poly2tri/poly2tri/sweep/cdt.cc
	../../libs/poly2tri/poly2tri/sweep/sweep_context.cc
	../../libs/poly2tri/poly2tri/sweep/sweep.cc
	../../libs/fmt/src/format.cc
	../src/cpp/main.cpp
	../../src/pch.cpp
	../../src/util.cpp
	../../src/rtt.cpp
	../../src/bezier.cpp
	../../src/asset.cpp
	../../src/image.cpp
	../../src/texture.cpp
	../../src/font.cpp
	../../src/shader.cpp
	../../src/shape.cpp
	../../src/app.cpp
	../../src/app_cloud.cpp
	../../src/app_dialogs.cpp
	../../src/app_events.cpp
	../../src/app_layout.cpp
	../../src/app_shaders.cpp
	../../src/app_vr.cpp
	../../src/brush.cpp
	../../src/canvas.cpp
	../../src/canvas_layer.cpp
	../../src/canvas_actions.cpp
	../../src/canvas_modes.cpp
	../../src/log.cpp
	../../src/action.cpp
	../../src/layout.cpp
	../../src/version.cpp
	../../src/node.cpp
	../../src/node_about.cpp
	../../src/node_border.cpp
	../../src/node_button.cpp
	../../src/node_button_custom.cpp
	../../src/node_canvas.cpp
	../../src/node_checkbox.cpp
	../../src/node_color_quad.cpp
	../../src/node_colorwheel.cpp
	../../src/node_combobox.cpp
	../../src/node_changelog.cpp
	../../src/node_dialog_browse.cpp
	../../src/node_dialog_cloud.cpp
	../../src/node_dialog_open.cpp
	../../src/node_dialog_picker.cpp
	../../src/node_dialog_layer_rename.cpp
	../../src/node_dialog_resize.cpp
	../../src/node_icon.cpp
	../../src/node_image.cpp
	../../src/node_image_texture.cpp
	../../src/node_message_box.cpp
	../../src/node_panel_brush.cpp
	../../src/node_panel_color.cpp
	../../src/node_panel_grid.cpp
	../../src/node_panel_floating.cpp
	../../src/node_panel_layer.cpp
	../../src/node_panel_stroke.cpp
	../../src/node_panel_quick.cpp
	../../src/node_popup_menu.cpp
	../../src/node_progress_bar.cpp
	../../src/node_settings.cpp
	../../src/node_slider.cpp
	../../src/node_stroke_preview.cpp
	../../src/node_text.cpp
	../../src/node_text_input.cpp
	../../src/node_tool_bucket.cpp
	../../src/node_usermanual.cpp
	../../src/node_viewport.cpp
	../../src/node_scroll.cpp
	../../src/abr.cpp
	../../src/binary_stream.cpp
	../../src/serializer.cpp
	../../src/settings.cpp
	../../src/node_input_box.cpp
	../../src/node_dialog_export_ppbr.cpp
	../../src/node_panel_animation.cpp
	../../src/mp4enc.cpp
	../../src/node_remote_page.cpp
	../../src/node_shorcuts.cpp
	../../src/node_metadata.cpp
)

target_compile_features(native-lib PRIVATE cxx_std_23)
set_target_properties(native-lib PROPERTIES CXX_EXTENSIONS OFF)

target_include_directories(native-lib PRIVATE
	src/main/cpp
	../src/cpp
	../../src
	../../libs/glm
	../../libs/tinyxml2
	../../libs/yoga
	../../libs/stb
	../../libs/jpeg
	../../libs/curl-android-ios/android/include
	../../libs/poly2tri/poly2tri
	../../libs/base64
	../../libs/sqlite3
	../../libs/nanort
	../../libs/native_app_glue
	../../libs/hash-library
	../../libs/fmt/include
	../../libs/openh264/include
	../../libs/mp4v2/include
	../../libs/libyuv/include
)

# add lib dependencies
target_link_libraries(
	native-lib
	libmp4v2.a
	yuv
	openh264
	android
	app-glue
	libcurl.a
	EGL
	GLESv3
	log
	z
)
