blob: 7516a90edf17b8eaba3df06b620ef72ebf566aa6 [file] [log] [blame]
Radek Krejcie84f12f2018-09-18 14:11:50 +02001# Correct RPATH usage on OS X
2set(CMAKE_MACOSX_RPATH TRUE)
3
Radek Krejcie84f12f2018-09-18 14:11:50 +02004if(ENABLE_STATIC AND ENABLE_VALGRIND_TESTS)
5 message(WARNING "Can't run C valgrind tests on a static build")
6else()
7 find_program(VALGRIND_FOUND valgrind)
8endif()
9
Radek Krejcief5f7672021-04-01 17:04:12 +020010configure_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 +020011include_directories(SYSTEM ${CMOCKA_INCLUDE_DIR})
Radek Krejcief5f7672021-04-01 17:04:12 +020012include_directories(${PROJECT_BINARY_DIR}/tests/)
Radek Krejcie84f12f2018-09-18 14:11:50 +020013
Radek Krejci18abde42020-06-13 20:04:39 +020014function(ly_add_utest)
15 cmake_parse_arguments(ADDTEST "" "NAME;WRAP" "SOURCES" ${ARGN})
16 set(TEST_NAME utest_${ADDTEST_NAME})
Radek Krejcie84f12f2018-09-18 14:11:50 +020017
Radek Krejci18abde42020-06-13 20:04:39 +020018 foreach(TEST_SOURCE ${ADDTEST_SOURCES})
Michal Vasko0666d052021-05-21 11:12:13 +020019 list(APPEND TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_SOURCE})
Radek Krejci18abde42020-06-13 20:04:39 +020020 endforeach()
Radek Krejcie84f12f2018-09-18 14:11:50 +020021
Michal Vasko0666d052021-05-21 11:12:13 +020022 add_executable(${TEST_NAME} ${TEST_SOURCES} $<TARGET_OBJECTS:yangobj>)
23
Radek Krejci18abde42020-06-13 20:04:39 +020024 # Set common attributes of all tests
25 set_target_properties(${TEST_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
Radek Krejcibf940f92021-03-24 21:04:13 +010026 target_link_libraries(${TEST_NAME} ${CMOCKA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${PCRE2_LIBRARIES} ${CMAKE_DL_LIBS} m)
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)
37 if(VALGRIND_FOUND)
Radek Krejci18abde42020-06-13 20:04:39 +020038 add_test(${TEST_NAME}_valgrind valgrind --leak-check=full --show-leak-kinds=all --suppressions=${PROJECT_SOURCE_DIR}/tests/ld.supp --error-exitcode=1
39 ${CMAKE_BINARY_DIR}/tests/${TEST_NAME})
Radek Krejci1fd5ad62020-05-15 15:48:42 +020040 else(VALGRIND_FOUND)
41 message(WARNING "valgrind executable not found! Disabling memory leaks tests.")
42 endif(VALGRIND_FOUND)
43 endif(ENABLE_VALGRIND_TESTS)
Radek Krejci18abde42020-06-13 20:04:39 +020044endfunction(ly_add_utest)
45
Radek Krejcicc3a1b62020-07-20 07:43:08 +020046add_subdirectory(style)
Radek Krejci5902be92021-03-25 21:25:14 +010047add_subdirectory(plugins)
Radek Krejcicc3a1b62020-07-20 07:43:08 +020048add_subdirectory(utests)
Juraj Vijtiukd7989422020-09-15 13:54:00 +020049add_subdirectory(fuzz)
Radek Krejcib4ac5a92020-11-23 17:54:33 +010050
51set(format_sources ${format_sources} PARENT_SCOPE)