cmake_minimum_required(VERSION 3.10)

project(robot_nav_2d_msgs VERSION 1.0.0 LANGUAGES CXX)

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

# Tìm tất cả header files
file(GLOB_RECURSE HEADERS "include/robot_nav_2d_msgs/*.h")

# Tạo INTERFACE library (header-only)
add_library(robot_nav_2d_msgs INTERFACE)

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

# Link dependencies (header-only, chỉ cần include paths)
# Các dependencies này cũng là header-only từ common_msgs
target_link_libraries(robot_nav_2d_msgs
    INTERFACE
        robot_std_msgs
        geometry_msgs
)

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

# Cài đặt target
install(TARGETS robot_nav_2d_msgs
        EXPORT robot_nav_2d_msgs-targets
        ARCHIVE DESTINATION lib
        LIBRARY DESTINATION lib
        RUNTIME DESTINATION bin)

# Export targets
# Bây giờ có thể export dependencies vì robot_std_msgs và geometry_msgs đã được export
install(EXPORT robot_nav_2d_msgs-targets
        FILE robot_nav_2d_msgs-targets.cmake
        NAMESPACE robot_nav_2d_msgs::
        DESTINATION lib/cmake/robot_nav_2d_msgs)

# In thông tin cấu hình
message(STATUS "=================================")
message(STATUS "Project: ${PROJECT_NAME} (Header-Only)")
message(STATUS "Version: ${PROJECT_VERSION}")
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
message(STATUS "Headers found:")
foreach(hdr ${HEADERS})
    message(STATUS "  - ${hdr}")
endforeach()
message(STATUS "Dependencies: robot_std_msgs, geometry_msgs")
message(STATUS "=================================")

