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