cmake_minimum_required(VERSION 3.10)

project(nav_grid 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/nav_grid/*.h")

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

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

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

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

# Export targets
install(EXPORT nav_grid-targets
        FILE nav_grid-targets.cmake
        NAMESPACE nav_grid::
        DESTINATION lib/cmake/nav_grid)

# Tùy chọn build tests
option(BUILD_TESTING "Build test programs" OFF)

if(BUILD_TESTING)
    find_package(GTest REQUIRED)
    
    # Tạo test executable
    add_executable(nav_grid_test test/utest.cpp)
    target_link_libraries(nav_grid_test 
        PRIVATE 
            nav_grid
            GTest::GTest
            GTest::Main
    )
    
    # Thêm test vào CTest
    enable_testing()
    add_test(NAME nav_grid_test COMMAND nav_grid_test)
endif()

# 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 "Build tests: ${BUILD_TESTING}")
message(STATUS "=================================")
