blob: 6f36f31d4565668d18940c3705fd7ad59989ae2f [file] [log] [blame]
Radek Krejcie84f12f2018-09-18 14:11:50 +02001# Correct RPATH usage on OS X
2set(CMAKE_MACOSX_RPATH TRUE)
3
Radek Krejcief5f7672021-04-01 17:04:12 +02004configure_file("${PROJECT_SOURCE_DIR}/tests/tests_config.h.in" "${PROJECT_BINARY_DIR}/tests/tests_config.h" ESCAPE_QUOTES @ONLY)
Radek Krejcie84f12f2018-09-18 14:11:50 +02005include_directories(SYSTEM ${CMOCKA_INCLUDE_DIR})
Radek Krejcief5f7672021-04-01 17:04:12 +02006include_directories(${PROJECT_BINARY_DIR}/tests/)
Radek Krejcie84f12f2018-09-18 14:11:50 +02007
Radek Krejci18abde42020-06-13 20:04:39 +02008function(ly_add_utest)
9 cmake_parse_arguments(ADDTEST "" "NAME;WRAP" "SOURCES" ${ARGN})
10 set(TEST_NAME utest_${ADDTEST_NAME})
Radek Krejcie84f12f2018-09-18 14:11:50 +020011
Radek Krejci18abde42020-06-13 20:04:39 +020012 foreach(TEST_SOURCE ${ADDTEST_SOURCES})
Michal Vasko0666d052021-05-21 11:12:13 +020013 list(APPEND TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_SOURCE})
Radek Krejci18abde42020-06-13 20:04:39 +020014 endforeach()
Radek Krejcie84f12f2018-09-18 14:11:50 +020015
Michal Vasko0666d052021-05-21 11:12:13 +020016 add_executable(${TEST_NAME} ${TEST_SOURCES} $<TARGET_OBJECTS:yangobj>)
Jan Kundrát5ee38862021-12-12 00:10:09 +010017 target_compile_definitions(${TEST_NAME} PRIVATE LIBYANG_BUILD)
Michal Vasko0666d052021-05-21 11:12:13 +020018
Radek Krejci18abde42020-06-13 20:04:39 +020019 # Set common attributes of all tests
20 set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
Jan Kundrát3b75bb62021-12-10 00:42:36 +010021 target_link_libraries(${TEST_NAME} ${CMOCKA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${PCRE2_LIBRARIES} ${CMAKE_DL_LIBS})
22 if (NOT WIN32)
23 target_link_libraries(${TEST_NAME} m)
Jan Kundrát08fda682021-12-11 23:52:14 +010024 else()
25 target_link_libraries(${TEST_NAME} ${COMPAT_WIN_LIBRARIES})
Jan Kundrát3b75bb62021-12-10 00:42:36 +010026 endif()
Radek Krejci1b5ef9d2018-11-27 12:49:59 +010027 if (NOT APPLE)
Radek Krejci18abde42020-06-13 20:04:39 +020028 if (ADDTEST_WRAP)
29 set_target_properties(${TEST_NAME} PROPERTIES LINK_FLAGS "${ADDTEST_WRAP}")
30 endif()
Radek Krejci1b5ef9d2018-11-27 12:49:59 +010031 endif()
Radek Krejci18abde42020-06-13 20:04:39 +020032
33 add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME})
Radek Krejci18abde42020-06-13 20:04:39 +020034 set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "MALLOC_CHECK_=3")
Radek Krejcie84f12f2018-09-18 14:11:50 +020035
Radek Krejci1fd5ad62020-05-15 15:48:42 +020036 if(ENABLE_VALGRIND_TESTS)
Michal Vaskof74be502021-06-04 08:52:26 +020037 add_test(${TEST_NAME}_valgrind valgrind --leak-check=full --show-leak-kinds=all --suppressions=${PROJECT_SOURCE_DIR}/tests/ld.supp --error-exitcode=1 ${CMAKE_BINARY_DIR}/tests/${TEST_NAME})
38 endif()
39endfunction()
Radek Krejci18abde42020-06-13 20:04:39 +020040
Michal Vasko99544ca2021-06-29 10:45:19 +020041if(ENABLE_TESTS)
Michal Vasko99544ca2021-06-29 10:45:19 +020042 add_subdirectory(plugins)
43 add_subdirectory(utests)
Jan Kundrátaece6662021-12-11 22:24:28 +010044 if(NOT WIN32)
45 add_subdirectory(style)
46 add_subdirectory(fuzz)
47 endif()
Michal Vasko99544ca2021-06-29 10:45:19 +020048endif()
49if(ENABLE_PERF_TESTS)
50 add_subdirectory(perf)
51endif()
Radek Krejcib4ac5a92020-11-23 17:54:33 +010052
53set(format_sources ${format_sources} PARENT_SCOPE)