# Copyright(c) 2019 livoxtech limited.
cmake_minimum_required(VERSION 2.8.3)


#---------------------------------------------------------------------------------------
# Start livox_ros_driver project
#---------------------------------------------------------------------------------------

project(navigation)

#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
#SET(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Using protobuf ${Protobuf_VERSION}")

set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf)
set(_REFLECTION gRPC::grpc++_reflection)
if(CMAKE_CROSSCOMPILING)
	find_program(_PROTOBUF_PROTOC protoc)
else()
	set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
endif()

# Find gRPC installation
# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation.
find_package(gRPC CONFIG REQUIRED)
message(STATUS "Using gRPC ${gRPC_VERSION}")

set(_GRPC_GRPCPP gRPC::grpc++)
if(CMAKE_CROSSCOMPILING)
	find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
else()
	set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
endif()

find_package (Eigen3 REQUIRED CONFIG QUIET)


#---------------------------------------------------------------------------------------
# Set default build to release
#---------------------------------------------------------------------------------------
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose Release or Debug" FORCE)
endif()

#---------------------------------------------------------------------------------------
# Compiler config
#---------------------------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)


include_directories(
		define
		/usr/include
		/usr/local/include
		${EIGEN3_INCLUDE_DIR}
		${GRPC_INCLUDE_DIR}
		)
link_directories("/usr/local/lib")
## PCL library
#link_directories(${PCL_LIBRARY_DIRS})
#add_definitions(${PCL_DEFINITIONS})

#---------------------------------------------------------------------------------------
# generate excutable and add libraries
#---------------------------------------------------------------------------------------

add_executable(${PROJECT_NAME}
		controller.cpp
		define/TimerRecord.cpp
		MPC/parameter.pb.cc
		MPC/custom_type.h
		MPC/loaded_mpc.cpp
		MPC/rotate_mpc.cpp
		MPC/trajectory.cpp
		MPC/pose2d.cpp
		MPC/navigation.cpp

		MPC/monitor/monitor_emqx.cpp
		MPC/monitor/emqx/mqttmsg.cpp
		MPC/monitor/emqx/paho_client.cpp
		MPC/monitor/emqx/message.pb.cc
		MPC/monitor/emqx/message.grpc.pb.cc
		MPC/monitor/terminator_emqx.cpp
		tool/pathcreator.cpp
		tool/singleton.cpp
		tool/proto_tool.cpp
        MPC/navigation_main.cpp
		nav_server.cpp)

#---------------------------------------------------------------------------------------
# link libraries ${Boost_LIBRARY} -lpthread
#---------------------------------------------------------------------------------------
target_link_libraries(${PROJECT_NAME}
		absl::flags
		absl::flags_parse
		${_REFLECTION}
		${_GRPC_GRPCPP}
		${_PROTOBUF_LIBPROTOBUF}
		libglog.a libgflags.a
		paho-mqtt3a
		ipopt
		)
#---------------------------------------------------------------------------------------
# end of CMakeList.txt
#---------------------------------------------------------------------------------------
