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 | |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 6 | if(ENABLE_STATIC AND ENABLE_VALGRIND_TESTS) |
| 7 | message(WARNING "Can't run C valgrind tests on a static build") |
| 8 | else() |
| 9 | find_program(VALGRIND_FOUND valgrind) |
| 10 | endif() |
| 11 | |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 12 | configure_file("${PROJECT_SOURCE_DIR}/tests/config.h.in" "${PROJECT_BINARY_DIR}/tests/config.h" ESCAPE_QUOTES @ONLY) |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 13 | include_directories(SYSTEM ${CMOCKA_INCLUDE_DIR}) |
Radek Krejci | 1e88003 | 2018-09-20 12:17:12 +0200 | [diff] [blame] | 14 | include_directories(${PROJECT_BINARY_DIR}) |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 15 | |
| 16 | set(tests) |
Radek Krejci | 36bac2b | 2018-09-19 11:15:29 +0200 | [diff] [blame] | 17 | set(tests_wraps) |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 18 | add_subdirectory(src) |
| 19 | |
| 20 | foreach(test_name IN LISTS tests) |
Radek Krejci | aaf6d40 | 2018-09-20 15:14:47 +0200 | [diff] [blame] | 21 | message(STATUS ${test_name}) |
| 22 | string(REGEX REPLACE "[a-z]*_(.*)" "\\1" name "${test_name}") |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 23 | string(REGEX REPLACE "([a-z]*)_.*" "\\1" prefix "${test_name}") |
Radek Krejci | 9efa87a | 2018-09-26 15:14:03 +0200 | [diff] [blame] | 24 | add_executable(${test_name} ${prefix}/test_${name}.c) |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 25 | endforeach(test_name) |
| 26 | |
| 27 | # Set common attributes of all tests |
| 28 | foreach(test_name IN LISTS tests) |
Radek Krejci | f3f4784 | 2018-11-15 11:22:15 +0100 | [diff] [blame] | 29 | target_link_libraries(${test_name} ${CMOCKA_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${PCRE_LIBRARIES} m) |
Radek Krejci | 1b5ef9d | 2018-11-27 12:49:59 +0100 | [diff] [blame] | 30 | if (NOT APPLE) |
| 31 | list(GET tests_wraps 0 test_wrap) |
| 32 | set_target_properties(${test_name} PROPERTIES LINK_FLAGS "${test_wrap}") |
| 33 | list(REMOVE_AT tests_wraps 0) |
| 34 | endif() |
Radek Krejci | e84f12f | 2018-09-18 14:11:50 +0200 | [diff] [blame] | 35 | add_test(NAME ${test_name} COMMAND ${test_name}) |
| 36 | # set_property(TEST ${test_name} PROPERTY ENVIRONMENT "LIBYANG_EXTENSIONS_PLUGINS_DIR=${CMAKE_BINARY_DIR}/src/extensions") |
| 37 | # set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT "LIBYANG_USER_TYPES_PLUGINS_DIR=${CMAKE_BINARY_DIR}/src/user_types") |
| 38 | set_property(TEST ${test_name} APPEND PROPERTY ENVIRONMENT "MALLOC_CHECK_=3") |
| 39 | endforeach(test_name) |
| 40 | |
| 41 | if(ENABLE_VALGRIND_TESTS) |
| 42 | if(VALGRIND_FOUND) |
| 43 | foreach(test_name IN LISTS tests) |
| 44 | add_test(${test_name}_valgrind valgrind --leak-check=full --show-leak-kinds=all --suppressions=${PROJECT_SOURCE_DIR}/tests/ld.supp --error-exitcode=1 |
| 45 | ${CMAKE_BINARY_DIR}/tests/${test_name}) |
| 46 | # set_property(TEST ${test_name}_valgrind PROPERTY ENVIRONMENT "LIBYANG_EXTENSIONS_PLUGINS_DIR=${CMAKE_BINARY_DIR}/src/extensions") |
| 47 | # set_property(TEST ${test_name}_valgrind APPEND PROPERTY ENVIRONMENT "LIBYANG_USER_TYPES_PLUGINS_DIR=${CMAKE_BINARY_DIR}/src/user_types") |
| 48 | endforeach(test_name) |
| 49 | else(VALGRIND_FOUND) |
| 50 | message(WARNING "valgrind executable not found! Disabling memory leaks tests.") |
| 51 | endif(VALGRIND_FOUND) |
| 52 | endif() |