cmake_minimum_required(VERSION 3.10)

# Tên dự án
project(two_points_planner VERSION 1.0.0 LANGUAGES CXX)

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

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

# Find system dependencies
find_package(Boost REQUIRED COMPONENTS filesystem system)

# Thư mục include
include_directories(
    ${PROJECT_SOURCE_DIR}/include
)

# Tìm tất cả file source
file(GLOB SOURCES "src/two_points_planner.cpp")
file(GLOB HEADERS "include/two_points_planner/*.h")

# Dependencies packages (internal libraries)
set(PACKAGES_DIR
    robot_costmap_2d
    nav_core
    geometry_msgs
    robot_nav_msgs
    robot_std_msgs
    tf3
    robot_tf3_geometry_msgs
)

# Tạo thư viện shared (.so)
add_library(two_points_planner SHARED ${SOURCES} ${HEADERS})

# Link libraries
target_link_libraries(two_points_planner
    PUBLIC ${PACKAGES_DIR}
    PUBLIC robot_cpp
    PRIVATE Boost::boost
)

set_target_properties(two_points_planner PROPERTIES
    LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)

# Set include directories
target_include_directories(two_points_planner
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include>
)

# Cài đặt header files
install(DIRECTORY include/two_points_planner
    DESTINATION include
    FILES_MATCHING PATTERN "*.h"
    PATTERN ".svn" EXCLUDE
)

# Cài đặt library
install(TARGETS two_points_planner
    EXPORT two_points_planner-targets
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    RUNTIME DESTINATION bin
)
# Export targets
install(EXPORT two_points_planner-targets
    FILE two_points_planner-targets.cmake
    DESTINATION lib/cmake/two_points_planner
)

# Tùy chọn build
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
option(BUILD_TESTS "Build test programs" OFF)

# Flags biên dịch
# 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")

# In thông tin cấu hình
message(STATUS "=================================")
message(STATUS "Project: two_points_planner")
message(STATUS "Version: ${PROJECT_VERSION}")
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Headers found:")
foreach(hdr ${HEADERS})
    message(STATUS "  - ${hdr}")
endforeach()
message(STATUS "=================================")
