cmake_minimum_required(VERSION 3.0.2)
project(hesai_lidar)

## Compile as C++11, supported in ROS Kinetic and newer
add_compile_options(-std=c++11)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
  std_srvs
  message_generation
  message_runtime
  roslib
  sensor_msgs
  pcl_conversions
  common
)

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
find_package(Boost REQUIRED )
find_package(PCL REQUIRED)

find_package(PkgConfig REQUIRED)
pkg_check_modules(YAML_CPP REQUIRED yaml-cpp)
find_path(YAML_CPP_INCLUDE_DIR NAMES yaml_cpp.h PATHS ${YAML_CPP_INCLUDE_DIRS})
find_library(YAML_CPP_LIBRARY NAMES YAML_CPP PATHS ${YAML_CPP_LIBRARIES})

## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES titan_driver
  CATKIN_DEPENDS roscpp std_msgs common
#  DEPENDS system_lib
)

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
  include
  ${catkin_INCLUDE_DIRS}
)

###################################################################################################
# 1-PandarGeneralRaw
add_library(PandarGeneral
    src/hesai_lidar/PandarGeneral/src/PandarGeneralRaw/src/input.cc
    src/hesai_lidar/PandarGeneral/src/PandarGeneralRaw/src/pandarGeneral_internal.cc
    src/hesai_lidar/PandarGeneral/src/PandarGeneralRaw/src/pandarGeneral.cc
)
target_include_directories(PandarGeneral PRIVATE
    src/hesai_lidar/PandarGeneral/src/PandarGeneralRaw/include
    src/hesai_lidar/PandarGeneral/src/PandarGeneralRaw/
    ${Boost_INCLUDE_DIRS}
    ${PCL_INCLUDE_DIRS}
    ${catkin_INCLUDE_DIRS}
)
target_link_libraries(PandarGeneral
    ${Boost_LIBRARIES}
    ${PCL_IO_LIBRARIES}
)

# 2-PandarGeneralSDK
add_library(PandarGeneralSDK SHARED
    src/hesai_lidar/PandarGeneral/src/pandarGeneral_sdk.cc
    src/hesai_lidar/PandarGeneral/src/tcp_command_client.c
    src/hesai_lidar/PandarGeneral/src/util.c
)
target_include_directories(PandarGeneralSDK PRIVATE
    src/hesai_lidar/PandarGeneral/
    src/hesai_lidar/PandarGeneral/include/
    src/hesai_lidar/PandarGeneral/src/PandarGeneralRaw/include
    ${Boost_INCLUDE_DIRS}
    ${PCL_INCLUDE_DIRS}
    ${YAML_CPP_INCLUDE_DIRS}
    ${catkin_INCLUDE_DIRS}
)
target_link_libraries(PandarGeneralSDK 
    PandarGeneral
    ${Boost_LIBRARIES}
    ${PCL_IO_LIBRARIES}
    ${YAML_CPP_LIBRARIES}
    ${catkin_LIBRARIES}
)

# 3-hesai_lidar_node
add_executable(hesai_lidar_node
    src/hesai_lidar/main.cc
    src/hesai_lidar/HesaiPandar64PCLXYZIRT.cpp
)
target_include_directories(hesai_lidar_node PRIVATE
    src/hesai_lidar/PandarGeneral/include
    src/hesai_lidar/PandarGeneral/src/PandarGeneralRaw/include
    ${PCL_INCLUDE_DIRS}
    ${catkin_INCLUDE_DIRS}
    ${Boost_INCLUDE_DIRS}
)

add_dependencies(hesai_lidar_node ${catkin_EXPORTED_TARGETS} common_gencpp)

target_link_libraries(hesai_lidar_node 
    ${catkin_LIBRARIES}
    ${PCL_IO_LIBRARIES}
    PandarGeneralSDK
)
###################################################################################################