cmake_minimum_required(VERSION 3.22.1)
project("mosis")

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

#set(ANDROID_SDK "/Users/omar/Library/Android/sdk")
set(BINDER_DIR "${ANDROID_SDK}/platforms/android-36/optional/libbinder_ndk_cpp")
set(AIDL_EXE "${ANDROID_SDK}/build-tools/36.1.0/aidl.exe")

find_package(RmlUi CONFIG REQUIRED)

#get_cmake_property(_variableNames VARIABLES)
#list(SORT _variableNames)
#foreach(_variableName ${_variableNames})
#    message(STATUS "${_variableName}=${${_variableName}}")
#endforeach()

add_custom_command(
    OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/com/omixlab/mosis/IMosisService.cpp"
    COMMAND ${AIDL_EXE} --lang=ndk --min_sdk_version=36 -o ${CMAKE_CURRENT_BINARY_DIR} -h ${CMAKE_CURRENT_BINARY_DIR} -I ..\\aidl ..\\aidl\\com\\omixlab\\mosis\\IMosisService.aidl
    DEPENDS ../aidl/com/omixlab/mosis/IMosisService.aidl
    WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
    VERBATIM
)

add_custom_command(
    OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/com/omixlab/mosis/IMosisListener.cpp"
    COMMAND ${AIDL_EXE} --lang=ndk --min_sdk_version=36 -o ${CMAKE_CURRENT_BINARY_DIR} -h ${CMAKE_CURRENT_BINARY_DIR} -I ..\\aidl ..\\aidl\\com\\omixlab\\mosis\\IMosisListener.aidl
    DEPENDS ../aidl/com/omixlab/mosis/IMosisListener.aidl
    WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}
    VERBATIM
)

add_library(mosis-service SHARED
    mosis-service.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/com/omixlab/mosis/IMosisService.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/com/omixlab/mosis/IMosisListener.cpp
    assets_manager.cpp
    shader.cpp
    external_texture.cpp
    quad.cpp
    egl_context.cpp
    render_target.cpp
    logger.cpp
    kernel.cpp
    glad/src/egl.c
    glad/src/gles2.c
    RmlUi_Renderer_GL3.cpp
)
target_compile_definitions(mosis-service PUBLIC
    RMLUI_NUM_MSAA_SAMPLES=2
    RMLUI_GL3_CUSTOM_LOADER=<glad/gles2.h>
)
target_include_directories(mosis-service PUBLIC
    ${CMAKE_CURRENT_LIST_DIR}
    ${CMAKE_CURRENT_BINARY_DIR}
    ${BINDER_DIR}
    glad/include
)
target_link_libraries(mosis-service
    android log binder_ndk EGL GLESv2 nativewindow
    RmlUi::RmlUi
)

add_library(mosis-test SHARED
    ${CMAKE_CURRENT_BINARY_DIR}/com/omixlab/mosis/IMosisService.cpp
    ${CMAKE_CURRENT_BINARY_DIR}/com/omixlab/mosis/IMosisListener.cpp
    mosis-test.cpp
    assets_manager.cpp
    shader.cpp
    external_texture.cpp
    quad.cpp
    egl_context.cpp
    render_target.cpp
    logger.cpp
    glad/src/egl.c
    glad/src/gles2.c
)
target_include_directories(mosis-test PUBLIC
    ${CMAKE_CURRENT_LIST_DIR}
    ${CMAKE_CURRENT_BINARY_DIR}
    ${BINDER_DIR}
    glad/include
)
target_link_libraries(mosis-test
    android log binder_ndk EGL GLESv2 nativewindow
)
