cmake: create separate CMakeLists.txt for tests Our CMakeLists.txt is very unwieldy in its current size, spanning more than 700 lines of code. Furthermore, it has several issues regarding scoping, where for example some defines, includes, etc. from our test suite are also applied to our normal library code. To fix this, we can separate out build instructions for our tests and move them into their own CMakeLists.txt in the "tests" directory. This reduced complexity of the root CMakeLists.txt file and fixes the issues regarding leaking build context from tests into the library.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5224496..4695801 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -677,71 +677,8 @@ INSTALL(FILES include/git2.h DESTINATION ${INCLUDE_INSTALL_DIR} )
# Tests
IF (BUILD_CLAR)
- FIND_PACKAGE(PythonInterp)
-
- IF(NOT PYTHONINTERP_FOUND)
- MESSAGE(FATAL_ERROR "Could not find a python interpeter, which is needed to build the tests. "
- "Make sure python is available, or pass -DBUILD_CLAR=OFF to skip building the tests")
- ENDIF()
-
- SET(CLAR_FIXTURES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources/")
- SET(CLAR_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tests")
- ADD_DEFINITIONS(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\")
- ADD_DEFINITIONS(-DCLAR_TMPDIR=\"libgit2_tests\")
-
- INCLUDE_DIRECTORIES(${CLAR_PATH})
- FILE(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h)
- SET(SRC_CLAR "${CLAR_PATH}/main.c" "${CLAR_PATH}/clar_libgit2.c" "${CLAR_PATH}/clar_libgit2_trace.c" "${CLAR_PATH}/clar_libgit2_timer.c" "${CLAR_PATH}/clar.c")
-
- IF(MSVC_IDE)
- LIST(APPEND SRC_CLAR "${CLAR_PATH}/precompiled.c")
- ENDIF()
-
- ADD_CUSTOM_COMMAND(
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite
- COMMAND ${PYTHON_EXECUTABLE} generate.py -o "${CMAKE_CURRENT_BINARY_DIR}" -f -xonline -xstress .
- DEPENDS ${SRC_TEST}
- WORKING_DIRECTORY ${CLAR_PATH}
- )
- INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
-
- SET_SOURCE_FILES_PROPERTIES(
- ${CLAR_PATH}/clar.c
- PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite)
-
- ADD_EXECUTABLE(libgit2_clar ${SRC_CLAR} ${SRC_TEST} $<TARGET_OBJECTS:git2internal>)
-
- IF (${CMAKE_VERSION} VERSION_GREATER 2.8.11)
- TARGET_INCLUDE_DIRECTORIES(libgit2_clar PRIVATE src PUBLIC include)
- ENDIF()
-
- TARGET_LINK_LIBRARIES(libgit2_clar ${COREFOUNDATION_DIRS})
- TARGET_LINK_LIBRARIES(libgit2_clar ${SECURITY_DIRS})
- TARGET_LINK_LIBRARIES(libgit2_clar ${SSL_LIBRARIES})
- TARGET_LINK_LIBRARIES(libgit2_clar ${SSH_LIBRARIES})
- TARGET_LINK_LIBRARIES(libgit2_clar ${GSSAPI_LIBRARIES})
- TARGET_LINK_LIBRARIES(libgit2_clar ${ICONV_LIBRARIES})
- TARGET_OS_LIBRARIES(libgit2_clar)
- IDE_SPLIT_SOURCES(libgit2_clar)
-
- IF (MSVC_IDE)
- # Precompiled headers
- SET_TARGET_PROPERTIES(libgit2_clar PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h")
- SET_SOURCE_FILES_PROPERTIES("${CLAR_PATH}/tests/precompiled.c" COMPILE_FLAGS "/Ycprecompiled.h")
- ENDIF ()
-
ENABLE_TESTING()
- IF (WINHTTP OR OPENSSL_FOUND OR SECURITY_FOUND)
- ADD_TEST(libgit2_clar libgit2_clar -ionline -xclone::local::git_style_unc_paths -xclone::local::standard_unc_paths_are_written_git_style)
- ELSE ()
- ADD_TEST(libgit2_clar libgit2_clar -v -xclone::local::git_style_unc_paths -xclone::local::standard_unc_paths_are_written_git_style)
- ENDIF ()
-
- # Add a test target which runs the cred callback tests, to be
- # called after setting the url and user
- ADD_TEST(libgit2_clar-cred_callback libgit2_clar -v -sonline::clone::cred_callback)
- ADD_TEST(libgit2_clar-proxy_credentials_in_url libgit2_clar -v -sonline::clone::proxy_credentials_in_url)
- ADD_TEST(libgit2_clar-proxy_credentials_request libgit2_clar -v -sonline::clone::proxy_credentials_request)
+ ADD_SUBDIRECTORY(tests)
ENDIF ()
IF (TAGS)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..31144c6
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,66 @@
+FIND_PACKAGE(PythonInterp)
+
+IF(NOT PYTHONINTERP_FOUND)
+ MESSAGE(FATAL_ERROR "Could not find a python interpeter, which is needed to build the tests. "
+ "Make sure python is available, or pass -DBUILD_CLAR=OFF to skip building the tests")
+ENDIF()
+
+SET(CLAR_FIXTURES "${CMAKE_CURRENT_SOURCE_DIR}/resources/")
+SET(CLAR_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
+ADD_DEFINITIONS(-DCLAR_FIXTURE_PATH=\"${CLAR_FIXTURES}\")
+ADD_DEFINITIONS(-DCLAR_TMPDIR=\"libgit2_tests\")
+
+INCLUDE_DIRECTORIES(${CLAR_PATH})
+FILE(GLOB_RECURSE SRC_TEST ${CLAR_PATH}/*/*.c ${CLAR_PATH}/*/*.h)
+SET(SRC_CLAR "main.c" "clar_libgit2.c" "clar_libgit2_trace.c" "clar_libgit2_timer.c" "clar.c")
+
+IF(MSVC_IDE)
+ LIST(APPEND SRC_CLAR "precompiled.c")
+ENDIF()
+
+ADD_CUSTOM_COMMAND(
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/clar.suite
+ COMMAND ${PYTHON_EXECUTABLE} generate.py -o "${CMAKE_CURRENT_BINARY_DIR}" -f -xonline -xstress .
+ DEPENDS ${SRC_TEST}
+ WORKING_DIRECTORY ${CLAR_PATH}
+)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
+
+SET_SOURCE_FILES_PROPERTIES(
+ ${CLAR_PATH}/clar.c
+ PROPERTIES OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clar.suite)
+
+ADD_EXECUTABLE(libgit2_clar ${SRC_CLAR} ${SRC_TEST} ${GIT2INTERNAL_OBJECTS})
+
+SET_TARGET_PROPERTIES(libgit2_clar PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
+
+IF (${CMAKE_VERSION} VERSION_GREATER 2.8.11)
+ TARGET_INCLUDE_DIRECTORIES(libgit2_clar PRIVATE ../src PUBLIC ../include)
+ENDIF()
+
+TARGET_LINK_LIBRARIES(libgit2_clar ${COREFOUNDATION_DIRS})
+TARGET_LINK_LIBRARIES(libgit2_clar ${SECURITY_DIRS})
+TARGET_LINK_LIBRARIES(libgit2_clar ${SSL_LIBRARIES})
+TARGET_LINK_LIBRARIES(libgit2_clar ${SSH_LIBRARIES})
+TARGET_LINK_LIBRARIES(libgit2_clar ${GSSAPI_LIBRARIES})
+TARGET_LINK_LIBRARIES(libgit2_clar ${ICONV_LIBRARIES})
+TARGET_OS_LIBRARIES(libgit2_clar)
+IDE_SPLIT_SOURCES(libgit2_clar)
+
+IF (MSVC_IDE)
+ # Precompiled headers
+ SET_TARGET_PROPERTIES(libgit2_clar PROPERTIES COMPILE_FLAGS "/Yuprecompiled.h /FIprecompiled.h")
+ SET_SOURCE_FILES_PROPERTIES("precompiled.c" COMPILE_FLAGS "/Ycprecompiled.h")
+ENDIF ()
+
+IF (WINHTTP OR OPENSSL_FOUND OR SECURITY_FOUND)
+ ADD_TEST(libgit2_clar "${CMAKE_BINARY_DIR}/libgit2_clar" -ionline -xclone::local::git_style_unc_paths -xclone::local::standard_unc_paths_are_written_git_style)
+ELSE ()
+ ADD_TEST(libgit2_clar "${CMAKE_BINARY_DIR}/libgit2_clar" -v -xclone::local::git_style_unc_paths -xclone::local::standard_unc_paths_are_written_git_style)
+ENDIF ()
+
+# Add a test target which runs the cred callback tests, to be
+# called after setting the url and user
+ADD_TEST(libgit2_clar-cred_callback "${CMAKE_BINARY_DIR}/libgit2_clar" -v -sonline::clone::cred_callback)
+ADD_TEST(libgit2_clar-proxy_credentials_in_url "${CMAKE_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_in_url)
+ADD_TEST(libgit2_clar-proxy_credentials_request "${CMAKE_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_request)