summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJosh Junon <josh.junon@protonmail.com>2021-12-23 18:23:34 +0100
committerJosh Junon <josh.junon@protonmail.com>2021-12-23 18:23:34 +0100
commitc5cd71b203cd73a815aa4bc8b9ef603800fa8b4b (patch)
treecb525c3a4d2809f6d9c101968348accb027fe97b /tests
parent12b53eb0318b0529514ad7e318de70b8325d43f2 (diff)
downloadlibgit2-c5cd71b203cd73a815aa4bc8b9ef603800fa8b4b.tar.gz
cmake: use PROJECT_SOURCE_DIR of CMAKE_SOURCE_DIR
Also applies to *_BINARY_DIR. This effectively reverts 84083dcc8bd41332ccac9d7b537f3e254d79011c, which broke all users of libgit2 that use it as a CMake subdirectory (via `add_subdirectory()`). This is because CMAKE_SOURCE_DIR refers to the root-most CMake directory, which in the case of `add_subdirectory()` is a parent project to libgit2 and thus the paths don't make any sense to the configuration files. Corollary, CMAKE_SOURCE_DIR only makes sense if the CMake project is always the root project - which can rarely be guaranteed. In all honesty, CMake should deprecate and eventually remove CMAKE_SOURCE_DIR and CMAKE_BINARY_DIR. It's been the source of headaches and confusion for years, they're rarely useful over CMAKE_CURRENT_(SOURCE|BINARY)_DIR or PROJECT_(SOURCE|BINARY)_DIR, and they cause a lot of confusing configuration and source code layouts to boot. Any time they are used, they break `add_subdirectory()` almost 100% of the time, cause confusing error messages, and hide subtle bugs.
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt6
1 files changed, 3 insertions, 3 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 2272dec98..fdf194d0e 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -38,7 +38,7 @@ set_source_files_properties(
add_executable(libgit2_tests ${SRC_CLAR} ${SRC_TEST} ${LIBGIT2_OBJECTS})
set_target_properties(libgit2_tests PROPERTIES C_STANDARD 90)
-set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
+set_target_properties(libgit2_tests PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
target_include_directories(libgit2_tests PRIVATE ${TEST_INCLUDES} ${LIBGIT2_INCLUDES} ${LIBGIT2_DEPENDENCY_INCLUDES})
target_include_directories(libgit2_tests SYSTEM PRIVATE ${LIBGIT2_SYSTEM_INCLUDES})
@@ -62,9 +62,9 @@ endif()
function(ADD_CLAR_TEST name)
if(NOT USE_LEAK_CHECKER STREQUAL "OFF")
- add_test(${name} "${CMAKE_SOURCE_DIR}/script/${USE_LEAK_CHECKER}.sh" "${CMAKE_BINARY_DIR}/libgit2_tests" ${ARGN})
+ add_test(${name} "${PROJECT_SOURCE_DIR}/script/${USE_LEAK_CHECKER}.sh" "${PROJECT_BINARY_DIR}/libgit2_tests" ${ARGN})
else()
- add_test(${name} "${CMAKE_BINARY_DIR}/libgit2_tests" ${ARGN})
+ add_test(${name} "${PROJECT_BINARY_DIR}/libgit2_tests" ${ARGN})
endif()
endfunction(ADD_CLAR_TEST)