Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable APSARA_UNIT_TEST_MAIN in provider #2003

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -71,12 +72,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
Loading