cmake_minimum_required(VERSION 2.8.3)
project(jfxmap_python)

option(TARGET_CORE_LIB "Core lib" ON)
option(TARGET_MAP_PRE_EXE "map pre exe" OFF)
option(TARGET_MAPPER_LIB "mapper lib" OFF)
option(TARGET_MAPPER_EXE "mapper exe" OFF)

set(CMAKE_DEBUG_POSTFIX _d)

if("${BUILD_PLATFORM}" STREQUAL "")
    set(BUILD_PLATFORM "BUILD_ON_LINUX" CACHE STRING "Build on target platform")
endif()
message(STATUS "============= ${PROJECT_NAME} : ${BUILD_PLATFORM} ===========")

if("${BUILD_PLATFORM}" STREQUAL "BUILD_ON_LINUX")
    set(CMAKE_C_STANDARD 99)
    set(CMAKE_CXX_STANDARD 11)
endif()


set(PYBIND11_CPP_STANDARD -std=c++11)
find_package(pybind11 REQUIRED)
INCLUDE_DIRECTORIES(
  ${pybind11_INCLUDE_DIRS}
  ./
)

if(TARGET_CORE_LIB )
    file(GLOB SRC_LIST
            "../jfxmap/offline/Core/*.cpp"
            "../jfxmap/submodules/xxtea-c/*.c"
            )
    add_library(jfxmap_python SHARED ${SRC_LIST} MapInterface.cpp jfxmap_python.cpp)
    set_target_properties(jfxmap_python PROPERTIES OUTPUT_NAME "jfxmap_python")
    if("${BUILD_PLATFORM}" STREQUAL "BUILD_ON_ANDROID")
        target_link_libraries(jfxmap_python pybind11::module log)
    else()
        target_link_libraries(jfxmap_python pybind11::module pthread)
    endif()
    set(local_include_directories
            ${local_include_directories}
            ${PROJECT_SOURCE_DIR}/../jfxmap/offline/Core
            ${PROJECT_SOURCE_DIR}/../jfxmap/offline/Public
            ${PROJECT_SOURCE_DIR}/../jfxmap/submodules/ajson
            ${PROJECT_SOURCE_DIR}/../jfxmap/submodules/spdlog/include
            )
endif()

if(TARGET_MAP_PRE_EXE)
#    file(GLOB SRC_LIST
#            "offline/MapPre/*.cpp"
#            "submodules/tinyxml/src/*.cpp"
#            )
#    add_executable(map_pre_exe ${SRC_LIST})
#    # add_dependencies(map_pre_exe core_lib_dynamic)
#    add_definitions(-DSTANDALONE)
#    link_directories(${PROJECT_SOURCE_DIR}/build)
#    link_directories(${PROJECT_SOURCE_DIR}/submodules/shapelib/build)
#    link_directories(/usr/local/lib)
#    target_link_libraries(map_pre_exe core_lib_dynamic)
#    target_link_libraries(map_pre_exe shp)
#    set(local_include_directories
#            ${local_include_directories}
#            ${PROJECT_SOURCE_DIR}/offline/core
#            ${PROJECT_SOURCE_DIR}/offline/mapPre
#            ${PROJECT_SOURCE_DIR}/submodules/shapelib
#            )
endif()

if(TARGET_UNIT_TEST_EXE)
#    file(GLOB SRC_LIST
#            "offline/Core/*.cpp"
#            "offline/Projects/qichecheng/*.cpp"
#            "offline/UnitTest/*.cpp"
#            "submodules/xxtea-c/*.c"
#            )
#    add_executable(unit_test_exe ${SRC_LIST})
#    add_definitions(-DSTANDALONE)
#    add_dependencies(unit_test_exe core_lib_dynamic)
#    link_directories(${PROJECT_SOURCE_DIR}/build/devel/lib)
#    message(STATUS "dir = ${PROJECT_SOURCE_DIR}/build/devel/lib")
#    link_directories(/usr/local/lib)
#    # target_link_libraries(unit_test_exe core_lib_dynamic)
#    # target_link_libraries(unit_test_exe ${PROJECT_SOURCE_DIR}/build/devel/lib/libcore_lib_d.so)
#    target_link_libraries(unit_test_exe pthread)
#    set(local_include_directories
#            ${local_include_directories}
#            ${PROJECT_SOURCE_DIR}/offline/Core
#            ${PROJECT_SOURCE_DIR}/offline/UnitTest
#            ${PROJECT_SOURCE_DIR}/offline/UnitTest/fusion_localization/include
#            ${PROJECT_SOURCE_DIR}/offline/UnitTest/hd_map/hd_map_common/include
#            ${PROJECT_SOURCE_DIR}/offline/UnitTest/utils/common/include
#            ${PROJECT_SOURCE_DIR}/offline/Projects
#            )
endif()

set(local_include_directories
        ${local_include_directories}
        ${PROJECT_SOURCE_DIR}/../jfxmap/submodules/ajson
        ${PROJECT_SOURCE_DIR}/../jfxmap/submodules/tinyxml/include
        ${PROJECT_SOURCE_DIR}/../jfxmap/submodules/boolinq/include/boolinq
        ${PROJECT_SOURCE_DIR}/../jfxmap/submodules/jfxthread/include
        ${PROJECT_SOURCE_DIR}/../jfxmap/submodules/queue-thread-safe
        ${PROJECT_SOURCE_DIR}/../jfxmap/submodules/spdlog/include
        ${PROJECT_SOURCE_DIR}/../jfxmap/submodules/xxtea-c
        )
include_directories(${local_include_directories})

get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
    set(jfxoffline_include_directories ${local_include_directories} PARENT_SCOPE)
endif()