set(LIBRARY_NAME measure_alg)

option(OPTION_ENABLE_TEST_CODE "Whether enable test code." ON)
message("<=${LIBRARY_NAME}=> OPTION_ENABLE_TEST_CODE: " ${OPTION_ENABLE_TEST_CODE})
option(OPTION_ENABLE_DATA_FROM_LOCAL "" OFF)
message("<=${LIBRARY_NAME}=> OPTION_ENABLE_DATA_FROM_LOCAL: " ${OPTION_ENABLE_DATA_FROM_LOCAL})

if (OPTION_ENABLE_DATA_FROM_LOCAL)
    add_compile_definitions(OPTION_ENABLE_DATA_FROM_LOCAL=1)
else ()
    add_compile_definitions(OPTION_ENABLE_DATA_FROM_LOCAL=0)
endif ()
aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/communication communication )
aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/match3d match3d )
aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/ceres ceres )
set(LIBRARY_SOURCE_LIST
        ${communication}
        ${match3d}
        ${ceres}
        alg.cpp
        alg.h
        velodyne_config.pb.cc
        velodyne_config.pb.h
)

set(LIBRARY_DEPEND_LIST
    zx
    ${CERES_LIBRARIES}
)

add_library(${LIBRARY_NAME} ${LIBRARY_SOURCE_LIST})
target_link_libraries(${LIBRARY_NAME} PUBLIC ${LIBRARY_DEPEND_LIST})

if (OPTION_ENABLE_TEST_CODE)
    set(LIBRARY_TEST_NAME "${LIBRARY_NAME}_test")
    set(LIBRARY_TEST_SOURCE_LIST
            ${CMAKE_CURRENT_LIST_DIR}/test.h
            ${CMAKE_CURRENT_LIST_DIR}/test.cpp
    )
    add_executable(${LIBRARY_TEST_NAME} ${LIBRARY_TEST_SOURCE_LIST})
    target_link_libraries(${LIBRARY_TEST_NAME} ${LIBRARY_NAME} )

    install(TARGETS ${LIBRARY_TEST_NAME}
            LIBRARY DESTINATION lib  # 动态库安装路径
            ARCHIVE DESTINATION lib  # 静态库安装路径
            RUNTIME DESTINATION bin  # 可执行文件安装路径
            PUBLIC_HEADER DESTINATION include  # 头文件安装路径
    )
endif ()
