Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8.12) |
| 2 | |
| 3 | # Correct RPATH usage on OS X |
| 4 | set(CMAKE_MACOSX_RPATH TRUE) |
| 5 | |
| 6 | # Set TESTS_DIR to realpath |
| 7 | #get_filename_component(TESTS_DIR "${CMAKE_SOURCE_DIR}/tests" REALPATH) |
| 8 | |
| 9 | if(ENABLE_STATIC AND ENABLE_VALGRIND_TESTS) |
| 10 | message(WARNING "Can't run C valgrind tests on a static build") |
| 11 | else() |
| 12 | find_program(VALGRIND_FOUND valgrind) |
| 13 | endif() |
| 14 | |
| 15 | include_directories(SYSTEM ${CMOCKA_INCLUDE_DIR}) |
| 16 | |
| 17 | set(tests) |
Radek Krejci | 36bac2b | 2018-09-19 11:15:29 +0200 | [diff] [blame^] | 18 | set(tests_wraps) |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 19 | add_subdirectory(src) |
| 20 | |
| 21 | foreach(test_name IN LISTS tests) |
| 22 | string(REGEX REPLACE "[a-z]*_" "" name "${test_name}") |
| 23 | string(REGEX REPLACE "([a-z]*)_.*" "\\1" prefix "${test_name}") |
| 24 | add_executable(${test_name} ${prefix}/${name}.c) |
| 25 | endforeach(test_name) |
| 26 | |
| 27 | # Set common attributes of all tests |
| 28 | foreach(test_name IN LISTS tests) |
| 29 | target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} yang) |
Radek Krejci | 36bac2b | 2018-09-19 11:15:29 +0200 | [diff] [blame^] | 30 | list(GET tests_wraps 0 test_wrap) |
| 31 | set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${test_wrap}") |
| 32 | list(REMOVE_AT tests_wraps 0) |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 33 | add_test(NAME ${test_name} COMMAND ${test_name}) |
| 34 | # set_property(TEST ${test_name} PROPERTY ENVIRONMENT "LIBYANG_EXTENSIONS_PLUGINS_DIR=${CMAKE_BINARY_DIR}/src/extensions") |
| 35 | # set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT "LIBYANG_USER_TYPES_PLUGINS_DIR=${CMAKE_BINARY_DIR}/src/user_types") |
| 36 | set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT "MALLOC_CHECK_=3") |
| 37 | endforeach(test_name) |
| 38 | |
| 39 | if(ENABLE_VALGRIND_TESTS) |
| 40 | if(VALGRIND_FOUND) |
| 41 | foreach(test_name IN LISTS tests) |
| 42 | add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --suppressions=${PROJECT_SOURCE_DIR}/tests/ld.supp --error-exitcode=1 |
| 43 | ${CMAKE_BINARY_DIR}/tests/${test_name}) |
| 44 | # set_property(TEST ${test_name}_valgrind PROPERTY ENVIRONMENT "LIBYANG_EXTENSIONS_PLUGINS_DIR=${CMAKE_BINARY_DIR}/src/extensions") |
| 45 | # set_property(TEST ${test_name}_valgrind APPEND PROPERTY ENVIRONMENT "LIBYANG_USER_TYPES_PLUGINS_DIR=${CMAKE_BINARY_DIR}/src/user_types") |
| 46 | endforeach(test_name) |
| 47 | else(VALGRIND_FOUND) |
| 48 | message(WARNING "valgrind executable not found! Disabling memory leaks tests.") |
| 49 | endif(VALGRIND_FOUND) |
| 50 | endif() |