mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
Due to our split of CMake files into multiple modules, we had to replace
some uses of the `${CMAKE_CURRENT_SOURCE_DIR}` and
`${CMAKE_CURRENT_BINARY_DIR}` variables and replace them with
`${CMAKE_SOURCE_DIR}` and `${CMAKE_BINARY_DIR}`. This enabled us to
still be able to refer to top-level files when defining build
instructions inside of a subdirectory.
When replacing all variables, it was assumed that the absolute set of
variables is always relative to the current project. But in fact, this
is not the case, as these variables always point to the source and
binary directory as given by the top-levl project. So the change
actually broke the ability to include libgit2 directly as a subproject,
as source files cannot be found anymore.
Fix this by instead using project-specific source and binary directories
with `${libgit2_SOURCE_DIR}` and `${libgit2_BINARY_DIR}`.
66 lines
2.7 KiB
CMake
66 lines
2.7 KiB
CMake
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} ${libgit2_BINARY_DIR}/src)
|
|
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)
|
|
|
|
LINK_DIRECTORIES(${LIBGIT2_LIBDIRS})
|
|
INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDES})
|
|
|
|
ADD_EXECUTABLE(libgit2_clar ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS})
|
|
|
|
SET_TARGET_PROPERTIES(libgit2_clar PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${libgit2_BINARY_DIR})
|
|
|
|
IF (${CMAKE_VERSION} VERSION_LESS 2.8.12)
|
|
# Already handled by a global INCLUDE_DIRECTORY()
|
|
ELSE()
|
|
TARGET_INCLUDE_DIRECTORIES(libgit2_clar PRIVATE ../src PUBLIC ../include)
|
|
ENDIF()
|
|
|
|
TARGET_LINK_LIBRARIES(libgit2_clar ${LIBGIT2_LIBS})
|
|
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 "${libgit2_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 "${libgit2_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 "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::cred_callback)
|
|
ADD_TEST(libgit2_clar-proxy_credentials_in_url "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_in_url)
|
|
ADD_TEST(libgit2_clar-proxy_credentials_request "${libgit2_BINARY_DIR}/libgit2_clar" -v -sonline::clone::proxy_credentials_request)
|