mirror of
https://github.com/libgit2/libgit2.git
synced 2026-01-25 11:06:32 +00:00
Also applies to *_BINARY_DIR.
This effectively reverts 84083dcc8b,
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.
35 lines
1.3 KiB
CMake
35 lines
1.3 KiB
CMake
# Optional external dependency: zlib
|
|
include(SanitizeBool)
|
|
|
|
SanitizeBool(USE_BUNDLED_ZLIB)
|
|
if(USE_BUNDLED_ZLIB STREQUAL ON)
|
|
set(USE_BUNDLED_ZLIB "Bundled")
|
|
endif()
|
|
|
|
if(USE_BUNDLED_ZLIB STREQUAL "OFF")
|
|
find_package(ZLIB)
|
|
if(ZLIB_FOUND)
|
|
list(APPEND LIBGIT2_SYSTEM_INCLUDES ${ZLIB_INCLUDE_DIRS})
|
|
list(APPEND LIBGIT2_SYSTEM_LIBS ${ZLIB_LIBRARIES})
|
|
if(APPLE OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
|
list(APPEND LIBGIT2_PC_LIBS "-lz")
|
|
else()
|
|
list(APPEND LIBGIT2_PC_REQUIRES "zlib")
|
|
endif()
|
|
add_feature_info(zlib ON "using system zlib")
|
|
else()
|
|
message(STATUS "zlib was not found; using bundled 3rd-party sources." )
|
|
endif()
|
|
endif()
|
|
if(USE_BUNDLED_ZLIB STREQUAL "Chromium")
|
|
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/chromium-zlib" "${PROJECT_BINARY_DIR}/deps/chromium-zlib")
|
|
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/chromium-zlib")
|
|
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:chromium_zlib>)
|
|
add_feature_info(zlib ON "using (Chromium) bundled zlib")
|
|
elseif(USE_BUNDLED_ZLIB OR NOT ZLIB_FOUND)
|
|
add_subdirectory("${PROJECT_SOURCE_DIR}/deps/zlib" "${PROJECT_BINARY_DIR}/deps/zlib")
|
|
list(APPEND LIBGIT2_DEPENDENCY_INCLUDES "${PROJECT_SOURCE_DIR}/deps/zlib")
|
|
list(APPEND LIBGIT2_DEPENDENCY_OBJECTS $<TARGET_OBJECTS:zlib>)
|
|
add_feature_info(zlib ON "using bundled zlib")
|
|
endif()
|