cmake_minimum_required(VERSION 3.10)

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

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

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif()

set(PACKAGES_DIR robot_nav_2d_msgs robot_nav_2d_utils nav_core nav_core2 geometry_msgs mkt_msgs angles)

find_package(Boost REQUIRED COMPONENTS filesystem system)

# Thư mục include
include_directories(
        ${PROJECT_SOURCE_DIR}/include
)
# Tạo thư viện shared (.so)

add_library(score_algorithm src/score_algorithm.cpp)
target_link_libraries(score_algorithm 
  PUBLIC
    ${PACKAGES_DIR}
    robot_cpp
  PRIVATE
    Boost::filesystem
    Boost::system

    )
set_target_properties(score_algorithm PROPERTIES
  LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
)

target_include_directories(score_algorithm PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>)

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

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

# Export targets
install(EXPORT score_algorithm-targets
        FILE score_algorithm-targets.cmake
        DESTINATION lib/cmake/score_algorithm)

# 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: ${PROJECT_NAME}")
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 "=================================")