1111# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
1212# or implied. See the License for the specific language governing permissions and limitations under
1313# the License.
14- #
14+ find_package (GTest REQUIRED)
1515
1616include (jsoncpp)
1717if (NOT EMSCRIPTEN)
@@ -30,6 +30,26 @@ configure_file(
3030 "${CMAKE_CURRENT_BINARY_DIR} /libsinsp_test_var.h"
3131)
3232
33+ file (GLOB_RECURSE TEST_HELPERS CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR} /helpers/*.cpp)
34+
35+ # sinsp_test_support library to be used to run integration tests in other projects (e.g., plugins)
36+ add_library (sinsp_test_support STATIC sinsp_with_test_input.cpp test_utils.cpp "${TEST_HELPERS} " )
37+
38+ target_include_directories (
39+ sinsp_test_support
40+ PUBLIC ${LIBS_DIR} # needed for driver/event_stats.h
41+ ${CMAKE_CURRENT_BINARY_DIR} # needed for libsinsp_test_var.h
42+ ${CMAKE_CURRENT_SOURCE_DIR} ${UTHASH_INCLUDE} ${JSONCPP_INCLUDE}
43+ )
44+
45+ target_link_libraries (sinsp_test_support PUBLIC sinsp GTest::gtest "${JSONCPP_LIB} " )
46+
47+ add_dependencies (sinsp_test_support uthash)
48+
49+ if (NOT EMSCRIPTEN)
50+ target_link_libraries (sinsp_test_support PUBLIC "${TBB_LIB} " )
51+ endif ()
52+
3353file (GLOB_RECURSE TEST_PLUGINS CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR} /plugins/*.cpp)
3454
3555if (NOT WIN32 )
@@ -48,8 +68,11 @@ endif()
4868
4969option (SCAP_FILES_SUITE_ENABLE "Enable scap-file tests in sinsp" "ON" )
5070# Scap-files on Big Endian systems are not supported
51- if ((NOT ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "s390x" ) AND ${SCAP_FILES_SUITE_ENABLE} )
52- # Binary dir in which we will save all our Cmake files
71+ if ((NOT ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "s390x" )
72+ AND ${SCAP_FILES_SUITE_ENABLE}
73+ AND TARGET unit-test -libsinsp
74+ )
75+ # Binary dir in which we will save all our scap files
5376 file (MAKE_DIRECTORY "${CMAKE_BINARY_DIR} /scap_files" )
5477 # Add here the name for new scap-files
5578 set (SCAP_FILE_NAMES
@@ -66,22 +89,20 @@ if((NOT ${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "s390x") AND ${SCAP_FILES_SUITE_
6689 )
6790 message (STATUS "Download all scap-files from: ${SCAP_FILE_DOWNLOAD_PREFIX} " )
6891 foreach (FILE_NAME ${SCAP_FILE_NAMES} )
69- message (STATUS "Downloading scap-file: ${SCAP_FILE_DOWNLOAD_PREFIX} /${FILE_NAME} " )
7092 if (NOT EXISTS "${CMAKE_BINARY_DIR} /scap_files/${FILE_NAME} " )
93+ message (STATUS "Downloading scap-file: ${FILE_NAME} " )
7194 file (DOWNLOAD "${SCAP_FILE_DOWNLOAD_PREFIX} /${FILE_NAME} "
7295 "${CMAKE_BINARY_DIR} /scap_files/${FILE_NAME} " SHOW_PROGRESS
7396 )
7497 else ()
75- message (STATUS "Skipping download, file already present" )
98+ message (STATUS "Skipping download, file already present: ${FILE_NAME} " )
7699 endif ()
77100 endforeach ()
78101 file (GLOB_RECURSE SCAP_FILES_SUITE CONFIGURE_DEPENDS
79102 ${CMAKE_CURRENT_SOURCE_DIR} /scap_files/*.cpp
80103 )
81104endif ()
82105
83- file (GLOB_RECURSE TEST_HELPERS CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR} /helpers/*.cpp)
84-
85106set (LIBSINSP_UNIT_TESTS_SOURCES
86107 ast_exprs.ut.cpp
87108 test_utils.cpp
@@ -196,9 +217,14 @@ target_include_directories(
196217 ${CMAKE_CURRENT_SOURCE_DIR}
197218)
198219
199- target_link_libraries (
200- unit-test -libsinsp sinsp "${GTEST_LIB} " "${GTEST_MAIN_LIB} " "${TBB_LIB} " "${JSONCPP_LIB} "
201- )
220+ # Link against sinsp and gtest - using both old-style variables and new targets for compatibility
221+ if (NOT EMSCRIPTEN)
222+ target_link_libraries (
223+ unit-test -libsinsp sinsp GTest::gtest GTest::gtest_main "${TBB_LIB} " "${JSONCPP_LIB} "
224+ )
225+ else ()
226+ target_link_libraries (unit-test -libsinsp sinsp GTest::gtest GTest::gtest_main "${JSONCPP_LIB} " )
227+ endif ()
202228
203229# Add some additional include directories associated with `ADDITIONAL_SINSP_TESTS_SUITE`
204230# `ADDITIONAL_SINSP_TESTS_INCLUDE_FOLDERS` is a list of include paths `;` separated
0 commit comments