
cmake_minimum_required(VERSION 3.20)

project("system")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)

set(fastcdr_DIR "/opt/fastdds/v3.2.2/lib/cmake/fastcdr")
set(fastdds_DIR "/opt/fastdds/v3.2.2/share/fastdds/cmake")
set(foonathan_memory_DIR "/opt/foonathan_memory/lib/foonathan_memory/cmake")

# Find requirements
find_package(fastcdr REQUIRED)
find_package(fastdds 3 REQUIRED)

# Set CMAKE_BUILD_TYPE to Release by default.
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
    message(STATUS "Setting build type to 'Release' as none was specified.")
    set(CMAKE_BUILD_TYPE Release CACHE STRING
        "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
        FORCE)
    set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()

include_directories(common)
include_directories(lib)

message(STATUS "Configuring System...")
add_library(System_lib lib/SystemTypeObjectSupport.cxx lib/SystemPubSubTypes.cxx)
target_link_libraries(System_lib fastcdr fastdds)

# Demo Application.
add_executable(Demo
                demo/main.cxx
                demo/Publisher.cxx
                demo/Subscriber.cxx
              )
target_include_directories(Demo PRIVATE demo)
target_link_libraries(Demo fastcdr fastdds
        System_lib
        )

# IoCtrl Application.
add_executable(IoCtrl
                ioctrl/main.cxx
                ioctrl/Publisher.cxx
                ioctrl/Subscriber.cxx
                ioctrl/MsgHandler.cxx
                common/CanMsgHandler.cxx
              )
target_include_directories(IoCtrl PRIVATE ioctrl)
target_link_libraries(IoCtrl fastcdr fastdds
        System_lib
        )

# HttpServer Application.
add_executable(HttpServer
                httpserver/main.cxx
                httpserver/Publisher.cxx
                httpserver/Subscriber.cxx
                httpserver/httpserver.cxx
              )
target_include_directories(HttpServer PRIVATE httpserver)
target_link_libraries(HttpServer fastcdr fastdds
        System_lib
        )

# Print Application.
add_executable(Print
                print/main.cxx
                print/Publisher.cxx
                print/Subscriber.cxx
                print/MsgHandler.cxx
                common/SerialMsgHandler.cxx
                lib/strcode.cpp
              )
target_include_directories(Print PRIVATE print)
target_link_libraries(Print fastcdr fastdds
        System_lib
        )

# Weigh Application.
add_executable(Weigh
                weigh/main.cxx
                weigh/Publisher.cxx
                weigh/Subscriber.cxx
                weigh/MsgHandler.cxx
                weigh/WeightStabilityDetector.cxx
                common/SerialMsgHandler.cxx
              )
target_include_directories(Weigh PRIVATE weigh)
target_link_libraries(Weigh fastcdr fastdds
        System_lib
        )


