set(INFRA tuple packet_parser packet_io snowflake ip_reassembly tcp_reassembly session_manager plugin_manager core)
set(DEPS bitmap dablooms interval_tree logger nmx_pool rbtree timeout toml)
set(DECODERS http lpi)
set(WHOLE_ARCHIVE ${DEPS} ${INFRA} ${DECODERS})

foreach(infra ${INFRA})
    add_subdirectory(${infra})
endforeach()

file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/stellar_lib.c "")

add_library(stellar_lib SHARED stellar_lib.c)
set_target_properties(stellar_lib PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/version.map")
target_link_libraries(stellar_lib PRIVATE pthread -Wl,--whole-archive ${WHOLE_ARCHIVE} -Wl,--no-whole-archive)
target_link_options(stellar_lib PRIVATE -rdynamic)
set_target_properties(stellar_lib PROPERTIES OUTPUT_NAME "stellar")

add_executable(stellar main.c)
set_target_properties(stellar PROPERTIES LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/version.map")
target_link_libraries(stellar PRIVATE pthread -Wl,--whole-archive ${WHOLE_ARCHIVE} -Wl,--no-whole-archive)
target_link_options(stellar PRIVATE -rdynamic)

install(TARGETS stellar_lib LIBRARY DESTINATION lib COMPONENT LIBRARIES)
install(TARGETS stellar RUNTIME DESTINATION bin COMPONENT PROGRAM)