Skip to content

Commit

Permalink
fix: enable APSARA_UNIT_TEST_MAIN in provider (#2003)
Browse files Browse the repository at this point in the history
  • Loading branch information
Abingcbc authored Jan 1, 2025
1 parent ed38617 commit f107577
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
14 changes: 8 additions & 6 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ option(WITHOUTGDB "Build Logtail without gdb")
option(WITHSPL "Build Logtail and UT with SPL" ON)
option(BUILD_LOGTAIL_UT "Build unit test for Logtail")
cmake_dependent_option(ENABLE_ADDRESS_SANITIZER "Enable address sanitizer" ON "CMAKE_BUILD_TYPE STREQUAL Debug;NOT ANDROID" OFF)
set(PROVIDER_PATH "provider" CACHE PATH "Path to the provider module") # external provider path can be set with -DPROVIDER_PATH
set(UNITTEST_PATH "unittest" CACHE PATH "Path to the unittest module") # external unittest path can be set with -DUNITTEST_PATH
set(PROVIDER_PATH ${CMAKE_CURRENT_SOURCE_DIR}/provider CACHE PATH "Path to the provider module") # external provider path can be set with -DPROVIDER_PATH
set(UNITTEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/unittest CACHE PATH "Path to the unittest module") # external unittest path can be set with -DUNITTEST_PATH

if (BUILD_LOGTAIL_SHARED_LIBRARY AND WITHSPL)
message(FATEL_ERROR, "Generating logtail shared library is not supported to be linked with SPL. WITHSPL should be set OFF.")
Expand Down Expand Up @@ -77,7 +77,6 @@ if (UNIX)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
add_definitions(-DAPSARA_UNIT_TEST_MAIN)
endif ()
elseif (MSVC)
add_definitions(-DNOMINMAX)
Expand Down Expand Up @@ -164,9 +163,6 @@ endif()
# remove several files in go_pipeline
list(REMOVE_ITEM FRAMEWORK_SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/go_pipeline/LogtailPluginAdapter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/go_pipeline/LogtailPluginAdapter.h)

# add provider
add_subdirectory("${PROVIDER_PATH}" "${CMAKE_BINARY_DIR}/provider")

if(MSVC)
# remove linux event listener
file(GLOB REMOVE_EVENT_LISTENER_SOURCES file_server/event_listener/*_Linux.cpp file_server/event_listener/*_Linux.h)
Expand All @@ -185,6 +181,9 @@ set(SRC_FILES ${SRC_FILES} ${FRAMEWORK_SOURCE_FILES} ${PLUGIN_SOURCE_FILES_CORE}

# Logtail executable or shared library.
if (BUILD_LOGTAIL)
# add provider
set(PROVIDER_BASE_TARGET "provider")
add_subdirectory("${PROVIDER_PATH}" ${CMAKE_BINARY_DIR}/${PROVIDER_BASE_TARGET})
if (ENABLE_ENTERPRISE)
if (UNIX)
add_executable(${LOGTAIL_TARGET} enterprise_logtail.cpp ${SRC_FILES})
Expand All @@ -201,6 +200,9 @@ if (BUILD_LOGTAIL)
endif()

if (BUILD_LOGTAIL_SHARED_LIBRARY)
# add provider
set(PROVIDER_BASE_TARGET "provider")
add_subdirectory("${PROVIDER_PATH}" ${CMAKE_BINARY_DIR}/${PROVIDER_BASE_TARGET})
if (ENABLE_ENTERPRISE)
if (UNIX)
add_library(${LOGTAIL_TARGET} SHARED enterprise_logtail.cpp ${SRC_FILES})
Expand Down
4 changes: 2 additions & 2 deletions core/provider/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ foreach(DIR_NAME IN LISTS PROVIDER_SUB_DIRECTORIES_LIST)
list(APPEND LIB_SOURCE_FILES ${TEMP_SOURCE_FILES})
endforeach()

add_library(${PROJECT_NAME} STATIC ${LIB_SOURCE_FILES})
add_library(${PROVIDER_BASE_TARGET} STATIC ${LIB_SOURCE_FILES})

# message(STATUS "PROVIDER SOURCE FILES: ${LIB_SOURCE_FILES}")

foreach(DIR_NAME IN LISTS PROVIDER_SUB_DIRECTORIES_LIST)
target_include_directories(provider PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../${DIR_NAME})
target_include_directories(${PROVIDER_BASE_TARGET} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../${DIR_NAME})
endforeach()
7 changes: 6 additions & 1 deletion core/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ project(unittest_base)
# Unittest should be able to visit private members
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-access-control")

add_definitions(-DAPSARA_UNIT_TEST_MAIN)
set(NO_TCMALLOC TRUE)
add_definitions(-DLOGTAIL_NO_TC_MALLOC)
if (MSVC)
Expand Down Expand Up @@ -73,12 +74,16 @@ macro(ut_link ut_link_withspl)
flusher_link(${UT_BASE_TARGET})
all_link(${UT_BASE_TARGET})
common_link(${UT_BASE_TARGET})
target_link_libraries(${UT_BASE_TARGET} provider)
target_link_libraries(${UT_BASE_TARGET} provider_unittest_base)
endmacro()

set(SOURCE_FILES_CORE ${FRAMEWORK_SOURCE_FILES} ${PLUGIN_SOURCE_FILES_CORE})
set(SOURCE_FILES_CORE_WITHSPL ${SOURCE_FILES_CORE} ${PLUGIN_SOURCE_FILES_SPL})

# add provider
set(PROVIDER_BASE_TARGET "provider_unittest_base")
add_subdirectory("${PROVIDER_PATH}" ${CMAKE_BINARY_DIR}/${PROVIDER_BASE_TARGET})

if (UNIX)
if (LINUX)
if (WITHSPL)
Expand Down

0 comments on commit f107577

Please sign in to comment.