# ========================================================
# ROOT CMakeLists.txt
# Đặt ở: Navigations/CMakeLists.txt
# ========================================================
cmake_minimum_required(VERSION 3.0.2)
project(navigations VERSION 1.0.0 LANGUAGES CXX)

# Chuẩn C++
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Build type
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif()

# Flags chung
# Warning flags - disabled to suppress warnings during build
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w")  # -w suppresses all warnings
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")

message(STATUS "========================================")
message(STATUS "Building Navigations Project")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
message(STATUS "========================================")

# Build các packages theo thứ tự phụ thuộc
# 1. Core libraries (header-only hoặc base libraries)

if (NOT TARGET tf3)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Libraries/tf3)
endif()

if (NOT TARGET robot_time)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Libraries/robot_time)
endif()

if (NOT TARGET xmlrpcpp)
   add_subdirectory(${CMAKE_SOURCE_DIR}/src/Libraries/xmlrpcpp) 
endif()

if (NOT TARGET robot_cpp)
   add_subdirectory(${CMAKE_SOURCE_DIR}/src/Libraries/robot_cpp) 
endif()

if (NOT TARGET data_convert)
   add_subdirectory(${CMAKE_SOURCE_DIR}/src/Libraries/data_convert) 
endif()

if (NOT TARGET geometry2)
   add_subdirectory(${CMAKE_SOURCE_DIR}/src/Libraries/geometry2) 
endif()

if (NOT TARGET common_msgs)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Libraries/common_msgs) 
endif()

if (NOT TARGET laser_geometry)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Libraries/laser_geometry) 
endif()

if (NOT TARGET voxel_grid)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Libraries/voxel_grid) 
endif()

if (NOT TARGET robot_nav_2d_msgs)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Libraries/robot_nav_2d_msgs) 
endif()

if (NOT TARGET costmap_2d)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Libraries/costmap_2d)
endif()

if (NOT TARGET robot_nav_2d_utils)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Libraries/robot_nav_2d_utils) 
endif()

if (NOT TARGET nav_core)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Navigations/Cores/nav_core)
endif()

if (NOT TARGET nav_grid)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Navigations/Libraries/nav_grid) 
endif()

if (NOT TARGET nav_core2)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Navigations/Cores/nav_core2)
endif()

if (NOT TARGET nav_core_adapter)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Navigations/Cores/nav_core_adapter)
endif()

if (NOT TARGET move_base_core)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Navigations/Cores/move_base_core)
endif()

if (NOT TARGET mkt_msgs)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Algorithms/Libraries/mkt_msgs)
endif()

if (NOT TARGET angles)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Algorithms/Libraries/angles)
endif()

if (NOT TARGET kalman)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Algorithms/Libraries/kalman)
endif()

if (NOT TARGET score_algorithm)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Algorithms/Cores/score_algorithm)
endif()

if (NOT TARGET mkt_plugins)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Algorithms/Libraries/mkt_plugins)
endif()

if (NOT TARGET mkt_algorithm)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Algorithms/Libraries/mkt_algorithm)
endif()

if (NOT TARGET two_points_planner)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Algorithms/Packages/global_planners/two_points_planner)
endif()

if (NOT TARGET custom_planner)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Algorithms/Packages/global_planners/custom_planner)
endif()

if (NOT TARGET dock_planner)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Algorithms/Packages/global_planners/dock_planner)
endif()

if (NOT TARGET pnkx_local_planner)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Algorithms/Packages/local_planners/pnkx_local_planner)
endif()


# 2. Main packages (phụ thuộc vào cores)
# message(STATUS "[move_base] Shared library configured")
if (NOT TARGET move_base)
    add_subdirectory(${CMAKE_SOURCE_DIR}/src/Navigations/Packages/move_base)
endif()

# C API for .NET/C# integration
# if (NOT TARGET navigation_c_api)
#     add_subdirectory(${CMAKE_SOURCE_DIR}/src/APIs/c_api)
# endif()

message(STATUS "========================================")
message(STATUS "All packages configured successfully")
message(STATUS "========================================")


