cmake_minimum_required(VERSION 3.16)

set(PROJECT_NAME compLib_server)
project(${PROJECT_NAME})

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})

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

set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-psabi")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

find_package(Protobuf REQUIRED)
find_package(spdlog REQUIRED)
find_package(pigpio REQUIRED)

set(PROTO_FILES
        protos/CompLib.proto
        )

set(SRC_FILES
        src/main.cpp
        src/spi.cpp
        src/encoder.cpp
        src/motor.cpp
        src/pid.cpp
        )

set(HDR_FILES
        include/messageBuilder.hpp
        include/errorMessages.hpp
        include/spi.hpp
        include/reset.hpp
        include/mathUtils.hpp
        include/encoder.hpp
        include/robot.hpp
        include/motor.hpp
        include/pid.hpp
        )

include_directories(third_party/asio)

PROTOBUF_GENERATE_CPP(PROTO_SRC PROTO_HDR ${PROTO_FILES})
add_executable(${PROJECT_NAME} ${SRC_FILES} ${HDR_FILES} ${PROTO_SRC} ${PROTO_HDR} ${PROTO_FILES})
target_include_directories(${PROJECT_NAME}
        PUBLIC ${CMAKE_CURRENT_BINARY_DIR}
        PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
        PUBLIC ${PROTOBUF_INCLUDE_DIRS}
        )
target_link_libraries(${PROJECT_NAME} ${PROTOBUF_LIBRARIES} pigpio spdlog::spdlog)
