diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index f59c9b847e..d035fadb91 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -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.") @@ -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) @@ -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) @@ -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}) @@ -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}) diff --git a/core/provider/CMakeLists.txt b/core/provider/CMakeLists.txt index 5c3cccbb50..0b47ea3966 100644 --- a/core/provider/CMakeLists.txt +++ b/core/provider/CMakeLists.txt @@ -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() \ No newline at end of file diff --git a/core/unittest/CMakeLists.txt b/core/unittest/CMakeLists.txt index 0c7f5b504a..1f8231e2d6 100644 --- a/core/unittest/CMakeLists.txt +++ b/core/unittest/CMakeLists.txt @@ -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) @@ -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)