]> git.proxmox.com Git - libgit2.git/blob - tests/CMakeLists.txt
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / CMakeLists.txt
1 set(Python_ADDITIONAL_VERSIONS 3 2.7)
2 find_package(PythonInterp)
3
4 if(NOT PYTHONINTERP_FOUND)
5 message(FATAL_ERROR "Could not find a python interpreter, which is needed to build the tests. "
6 "Make sure python is available, or pass -DBUILD_TESTS=OFF to skip building the tests")
7 ENDIF()
8
9 set(CLAR_FIXTURES "${CMAKE_CURRENT_SOURCE_DIR}/resources/")
10 set(CLAR_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
11 add_definitions(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\")
12 add_definitions(-DCLAR_TMPDIR=\"libgit2_tests\")
13 add_definitions(-DCLAR_WIN32_LONGPATHS)
14 add_definitions(-D_FILE_OFFSET_BITS=64)
15
16 # Ensure that we do not use deprecated functions internally
17 add_definitions(-DGIT_DEPRECATE_HARD)
18
19 set(TEST_INCLUDES "${CLAR_PATH}" "${CMAKE_CURRENT_BINARY_DIR}")
20 file(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h)
21 set(SRC_CLAR "main.c" "clar_libgit2.c" "clar_libgit2_trace.c" "clar_libgit2_timer.c" "clar.c")
22
23 if(MSVC_IDE)
24 list(APPEND SRC_CLAR "precompiled.c")
25 endif()
26
27 add_custom_command(
28 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite ${CMAKE_CURRENT_BINARY_DIR}/clar_suite.h
29 COMMAND ${PYTHON_EXECUTABLE} generate.py -o "${CMAKE_CURRENT_BINARY_DIR}" -f -xonline -xstress -xperf .
30 DEPENDS ${SRC_TEST}
31 WORKING_DIRECTORY ${CLAR_PATH}
32 )
33
34 set_source_files_properties(
35 ${CLAR_PATH}/clar.c
36 PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite)
37
38 add_executable(libgit2_tests ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS})
39
40 set_target_properties(libgit2_tests PROPERTIES C_STANDARD 90)
41 set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
42
43 target_include_directories(libgit2_tests PRIVATE ${TEST_INCLUDES} ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES})
44 target_include_directories(libgit2_tests SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
45 target_link_libraries(libgit2_tests ${LIBGIT2_SYSTEM_LIBS})
46
47 ide_split_sources(libgit2_tests)
48
49 #
50 # Old versions of gcc require us to declare our test functions; don't do
51 # this on newer compilers to avoid unnecessary recompilation.
52 #
53 if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
54 target_compile_options(libgit2_tests PRIVATE -include "clar_suite.h")
55 endif()
56
57 if(MSVC_IDE)
58 # Precompiled headers
59 set_target_properties(libgit2_tests PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h")
60 set_source_files_properties("precompiled.c" COMPILE_FLAGS "/Ycprecompiled.h")
61 endif()
62
63 function(ADD_CLAR_TEST name)
64 if(NOT USE_LEAK_CHECKER STREQUAL "OFF")
65 add_test(${name} "${PROJECT_SOURCE_DIR}/script/${USE_LEAK_CHECKER}.sh" "${PROJECT_BINARY_DIR}/libgit2_tests" ${ARGN})
66 else()
67 add_test(${name} "${PROJECT_BINARY_DIR}/libgit2_tests" ${ARGN})
68 endif()
69 endfunction(ADD_CLAR_TEST)
70
71 add_clar_test(offline -v -xonline)
72 add_clar_test(invasive -v -score::ftruncate -sfilter::stream::bigfile -sodb::largefiles -siterator::workdir::filesystem_gunk -srepo::init -srepo::init::at_filesystem_root)
73 add_clar_test(online -v -sonline -xonline::customcert)
74 add_clar_test(online_customcert -v -sonline::customcert)
75 add_clar_test(gitdaemon -v -sonline::push)
76 add_clar_test(ssh -v -sonline::push -sonline::clone::ssh_cert -sonline::clone::ssh_with_paths -sonline::clone::path_whitespace_ssh)
77 add_clar_test(proxy -v -sonline::clone::proxy)
78 add_clar_test(auth_clone -v -sonline::clone::cred)
79 add_clar_test(auth_clone_and_push -v -sonline::clone::push -sonline::push)
80
81 #
82 # Header file validation project: ensure that we do not publish any sloppy
83 # definitions in our headers and that a consumer can include <git2.dll>
84 # even when they have aggressive C90 warnings enabled.
85 #
86
87 add_executable(headertest headertest.c)
88 set_target_properties(headertest PROPERTIES C_STANDARD 90)
89 set_target_properties(headertest PROPERTIES C_EXTENSIONS OFF)
90 target_include_directories(headertest PRIVATE ${LIBGIT2_INCLUDES})
91
92 if (MSVC)
93 target_compile_options(headertest PUBLIC /W4 /WX)
94 else()
95 target_compile_options(headertest PUBLIC -Wall -Wextra -pedantic -Werror)
96 endif()