cmake_minimum_required(VERSION 3.16)
project(AQTPackageMachinePlug LANGUAGES CXX)

# 添加更多调试输出
message(STATUS "Current source dir: ${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS "FastDDS lib dir: ${fastdds_DIR}")
message(STATUS "FastCDR lib dir: ${fastcdr_DIR}")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

find_package(Qt6 REQUIRED COMPONENTS Core Quick)

# 添加 FastDDS 依赖
if(NOT fastcdr_FOUND)
    find_package(fastcdr 2 REQUIRED)
endif()

if(NOT fastdds_FOUND)
    find_package(fastdds 3 REQUIRED)
endif()

# 创建插件库
add_library(AQTPackageMachinePlug SHARED
    AQTPackageMachinePlug.cxx
    AQTPackageMachinePlug.hpp
    AQTPackageMachinePlug.json
    HelloWorldPubSubTypes.cxx
    HelloWorldPubSubTypes.hpp
    HelloWorldCdrAux.hpp
    HelloWorldCdrAux.ipp
    HelloWorld.hpp
    HelloWorldTypeObjectSupport.cxx
    HelloWorldTypeObjectSupport.hpp
)

# 定义导出宏
target_compile_definitions(AQTPackageMachinePlug
    PRIVATE 
        AQTPACKAGEMACHINEPLUG_LIBRARY
        QT_PLUGIN
        FASTRTPS_NO_LIB
        FASTRTPS_DYN_LINK
)

# 添加包含目录
target_include_directories(AQTPackageMachinePlug
    PRIVATE
        ${CMAKE_SOURCE_DIR}
        ${Qt6Core_INCLUDE_DIRS}
        ${Qt6Quick_INCLUDE_DIRS}
)

target_include_directories(AQTPackageMachinePlug
    PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(AQTPackageMachinePlug
    PRIVATE 
        Qt6::Core
        Qt6::Quick
        fastdds
        fastcdr
)

# 修改属性设置
set_target_properties(AQTPackageMachinePlug PROPERTIES
    OUTPUT_NAME "AQTPackageMachinePlug"
    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
    PREFIX ""
    SUFFIX ".so"
    POSITION_INDEPENDENT_CODE ON
    SKIP_BUILD_RPATH FALSE
    BUILD_WITH_INSTALL_RPATH FALSE
    INSTALL_RPATH "$ORIGIN:${CMAKE_INSTALL_PREFIX}/lib"
    INSTALL_RPATH_USE_LINK_PATH TRUE
)

# 安装配置
install(TARGETS AQTPackageMachinePlug
    LIBRARY DESTINATION bin
    RUNTIME DESTINATION bin
) 