# Sets the minimum version of CMake required to build the native
# library. You should either keep the default value or only pass a
# value of 3.4.0 or lower.

cmake_minimum_required(VERSION 3.4.1)

SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG -DDEBUG -D_DEBUG -Werror=return-type")
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -Werror=return-type")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch arm64 -g -DDEBUG")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch arm64 -g -DDEBUG")
message("CMAKE_CXX_FLAGS_DEBUG is ${CMAKE_CXX_FLAGS_DEBUG}")
message("CMAKE_CXX_FLAGS_RELEASE is ${CMAKE_CXX_FLAGS_RELEASE}")
message("CMAKE_CXX_FLAGS_RELWITHDEBINFO is ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
message("CMAKE_CXX_FLAGS is ${CMAKE_CXX_FLAGS}")
message("Build type: ${CMAKE_BUILD_TYPE}")

macro( add_recursive dir retVal )
    file( GLOB_RECURSE ${retVal} ${dir}/*.h ${dir}/*.cpp ${dir}/*.c )
endmacro()

#add_recursive( src/main/cpp/SamplesCommon/ SAMPLES_COMMON_FILES )
#add_recursive( src/main/cpp/CustomRenderable/ CUSTOM_RENDERABLE_FILES )
#add_recursive( src/main/cpp/PbsMaterials/ PBS_MATERIALS_FILES )

SET(OGRE_ANDROID_BUILD_INCLUDE_PATH /Users/sebastian/Downloads/ogre-1/build2)
SET(OGRE_ZZIPLIB_PATH /Users/sebastian/Downloads/ogredeps/src)
SET(OGRE_INCLUDE_PATH /Users/sebastian/Downloads/ogre-1)
SET(OGREDEPS_BUILD_INCLUDE_PATH /Users/sebastian/Downloads/ogre-1/iOSDependencies)
SET(SRC_PATH ../android/src/main/jni)

include_directories(
${OGRE_ANDROID_BUILD_INCLUDE_PATH}/include
${OGRE_ZZIPLIB_PATH}/zziplib/
${OGRE_INCLUDE_PATH}/OgreMain/include/
${OGRE_INCLUDE_PATH}/OgreMain/include/Android
${OGRE_INCLUDE_PATH}/OgreMain/include/Math/Array
${OGRE_INCLUDE_PATH}/Components/Hlms/Common/include/
${OGRE_INCLUDE_PATH}/Components/Hlms/Pbs/include/
${OGRE_INCLUDE_PATH}/Components/Hlms/Unlit/include/
${OGRE_INCLUDE_PATH}/Components/Hlms/PbsMobile/include/
${OGRE_INCLUDE_PATH}/Components/Hlms/UnlitMobile/include/
${OGRE_INCLUDE_PATH}/Components/MeshLodGenerator/include/
${OGRE_INCLUDE_PATH}/Components/Overlay/include/
${OGRE_INCLUDE_PATH}/PlugIns/ParticleFX/include/
${OGRE_INCLUDE_PATH}/RenderSystems/GLES3/include
${OGRE_INCLUDE_PATH}/RenderSystems/GLES3/include/EAGL
${OGRE_INCLUDE_PATH}/RenderSystems/GLES3/include/EGL
${OGRE_INCLUDE_PATH}/RenderSystems/GLES3/include/EGL/Android
${OGRE_INCLUDE_PATH}/RenderSystems/GLES3/include/EGL/GLES3
${OGRE_INCLUDE_PATH}/RenderSystems/GLES3/include/EGL/KHR
${OGRE_INCLUDE_PATH}/RenderSystems/GLES3/include/EGL/Vao
${OGRE_INCLUDE_PATH}/RenderSystems/Metal/include/
${OGRE_INCLUDE_PATH}/Samples/2.0/Common/include/
${OGRE_INCLUDE_PATH}/Samples/2.0/Common/include/System
${OGRE_INCLUDE_PATH}/Samples/2.0/Common/include/System/iOS
/Users/sebastian/Library/Java/JavaVirtualMachines/corretto-1.8.0_302/Contents/Home/include
/Users/sebastian/Library/Java/JavaVirtualMachines/corretto-1.8.0_302/Contents/Home/include/darwin
#${OGREDEPS_BUILD_INCLUDE_PATH}/include/
#"src/main/cpp/SamplesCommon/"
#"src/main/cpp/CustomRenderable/"
#"src/main/cpp/PbsMaterials/"
)

# build native_app_glue as a static lib
#add_library(app-glue STATIC
#            ${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds it for you.
# Gradle automatically packages shared libraries with your APK.

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")

add_library( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             STATIC

             # Provides a relative path to your source file(s).
             # Associated headers in the same location as their source
             # file are automatically included.
             ${SRC_PATH}/blackholedarksunmain.cpp
             ${SRC_PATH}/HotshotGorillaGUI.cpp
             ${SRC_PATH}/HotshotGorillaGUISprite.cpp
             ${SRC_PATH}/HotshotGorillaGUINinePatch.cpp
             ${SRC_PATH}/HotshotGorillaGUIScreenRenderable.cpp
             ${SRC_PATH}/HotshotGorillaGUIScreen.cpp
             ${SRC_PATH}/HotshotVector.cpp
             ${SRC_PATH}/HotshotLoadingScreen.cpp
             ${SRC_PATH}/JniCommon.cpp
             ${SRC_PATH}/RayQueryExecuteFrameEndListenerExecutor.cpp
             ${SRC_PATH}/CommandBufferUtility.cpp
             ${SRC_PATH}/DynamicOverlayBox.cpp
             ${SRC_PATH}/DynamicOverlayElement.cpp
             ${SRC_PATH}/HotshotTiledAnimation.cpp
             ${SRC_PATH}/HotshotTiledAnimationFrameEndListener.cpp
             ${SRC_PATH}/HotshotSceneCompositor.cpp
             ${SRC_PATH}/HotshotFullQuadAnimationController.cpp
             ${SRC_PATH}/HotshotCommon.cpp
             ${SRC_PATH}/GameViewControllerImpl.cpp
             ${SRC_PATH}/MetalViewCallbacksImpl.cpp
             #${SAMPLES_COMMON_FILES}
             #${CUSTOM_RENDERABLE_FILES}
             #${PBS_MATERIALS_FILES}
)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because system libraries are included in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

#find_library( # Sets the name of the path variable.
#              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
#              log )
#find_library( # Sets the name of the path variable.
#              gles2-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
#              GLESv2 )
#find_library( # Sets the name of the path variable.
#              egl-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
#              EGL )
#find_library( # Sets the name of the path variable.
#              android-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
#              android )
#find_library( # Sets the name of the path variable.
#              zlib-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
#              z )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in the
# build script, prebuilt third-party libraries, or system libraries.

#target_include_directories(native-lib PRIVATE
#                           ${ANDROID_NDK}/sources/android/native_app_glue)
                           
SET(OGRE_LIB_PATH /Users/sebastian/Downloads/ogre-1/build2/lib/iphoneos/Debug)
SET(OGRE_LIB_SAMPLES_COMMON_PATH /Users/sebastian/Downloads/ogre-1/build2/lib/Debug)
SET(OGRE_DEPS_LIB_PATH /Users/sebastian/Downloads/ogre-1/iOSDependencies/lib/Release)

target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
#                       ${log-lib}
#                       ${gles2-lib}
#                       ${egl-lib}
#                       ${android-lib}
#                       ${zlib-lib}
                       #app-glue
                       ${OGRE_LIB_PATH}/libOgreOverlayStatic.a
                       ${OGRE_LIB_PATH}/libOgreHlmsPbsStatic.a
                       ${OGRE_LIB_PATH}/libOgreHlmsUnlitStatic.a
                       ${OGRE_LIB_PATH}/libOgreMeshLodGeneratorStatic.a
                       ${OGRE_LIB_PATH}/libPlugin_ParticleFXStatic.a
                       ${OGRE_LIB_PATH}/libRenderSystem_MetalStatic.a
                       ${OGRE_LIB_PATH}/libOgreMainStatic.a
                       ${OGRE_LIB_PATH}/libRenderSystem_MetalStatic.a
                       ${OGRE_LIB_SAMPLES_COMMON_PATH}/libOgreSamplesCommon.a
                       #${OGRE_LIB_PATH}/libOgre.a
                       ${OGRE_DEPS_LIB_PATH}/libfreetype.a
                       ${OGRE_DEPS_LIB_PATH}/libzzip.a
                       ${OGRE_DEPS_LIB_PATH}/libFreeImage.a
)

macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY}
    ${XCODE_VALUE})
endmacro (set_xcode_property)

# Debug symbols set in XCode project
set_xcode_property (native-lib GCC_GENERATE_DEBUGGING_SYMBOLS YES "All")

#set_target_properties(native-lib PROPERTIES
#    LINK_FLAGS "-Wl,-all_load"
#)

# Installation
#set (CMAKE_INSTALL_PREFIX "${example-ios_SOURCE_DIR}/../example-app/example-lib")
#install (TARGETS example helloworld DESTINATION lib)
#install (FILES ${HEADERS} DESTINATION include)

#message("End reached")
