mirror of
https://github.com/libgit2/libgit2.git
synced 2026-01-25 02:56:17 +00:00
cmake: Sort source files for reproducible builds
We currently use `FILE(GLOB ...)` in most places to find source and header files. This is problematic in that the order of files returned depends on the operating system's directory iteration order and may thus not be deterministic. As a result, we link object files in unspecified order, which may cause the linker to emit different code across runs. Fix this issue by sorting all code used as input to the libgit2 library to improve the reliability of reproducible builds.
This commit is contained in:
@@ -56,4 +56,6 @@ ELSE()
|
||||
MESSAGE(FATAL_ERROR "Asked for unknown SHA1 backend: ${USE_SHA1}")
|
||||
ENDIF()
|
||||
|
||||
list(SORT SRC_SHA1)
|
||||
|
||||
ADD_FEATURE_INFO(SHA ON "using ${USE_SHA1}")
|
||||
|
||||
7
deps/http-parser/CMakeLists.txt
vendored
7
deps/http-parser/CMakeLists.txt
vendored
@@ -1,5 +1,6 @@
|
||||
FILE(GLOB SRC_HTTP "*.c" "*.h")
|
||||
file(GLOB SRC_HTTP "*.c" "*.h")
|
||||
list(SORT SRC_HTTP)
|
||||
|
||||
ADD_LIBRARY(http-parser OBJECT ${SRC_HTTP})
|
||||
add_library(http-parser OBJECT ${SRC_HTTP})
|
||||
|
||||
ENABLE_WARNINGS(implicit-fallthrough=1)
|
||||
enable_warnings(implicit-fallthrough=1)
|
||||
|
||||
1
deps/ntlmclient/CMakeLists.txt
vendored
1
deps/ntlmclient/CMakeLists.txt
vendored
@@ -1,4 +1,5 @@
|
||||
FILE(GLOB SRC_NTLMCLIENT "ntlm.c" "unicode_builtin.c" "util.c")
|
||||
LIST(SORT SRC_NTLMCLIENT)
|
||||
|
||||
ADD_DEFINITIONS(-DNTLM_STATIC=1)
|
||||
|
||||
|
||||
11
deps/zlib/CMakeLists.txt
vendored
11
deps/zlib/CMakeLists.txt
vendored
@@ -1,5 +1,6 @@
|
||||
DISABLE_WARNINGS(implicit-fallthrough)
|
||||
ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP)
|
||||
FILE(GLOB SRC_ZLIB "*.c" "*.h")
|
||||
INCLUDE_DIRECTORIES(".")
|
||||
ADD_LIBRARY(zlib OBJECT ${SRC_ZLIB})
|
||||
disable_warnings(implicit-fallthrough)
|
||||
add_definitions(-DNO_VIZ -DSTDC -DNO_GZIP)
|
||||
file(GLOB SRC_ZLIB "*.c" "*.h")
|
||||
list(SORT SRC_ZLIB)
|
||||
include_directories(".")
|
||||
add_library(zlib OBJECT ${SRC_ZLIB})
|
||||
|
||||
@@ -76,12 +76,13 @@ ENDIF()
|
||||
ADD_FEATURE_INFO(threadsafe THREADSAFE "threadsafe support")
|
||||
|
||||
|
||||
IF (WIN32 AND EMBED_SSH_PATH)
|
||||
FILE(GLOB SRC_SSH "${EMBED_SSH_PATH}/src/*.c")
|
||||
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES "${EMBED_SSH_PATH}/include")
|
||||
FILE(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
|
||||
SET(GIT_SSH 1)
|
||||
ENDIF()
|
||||
if(WIN32 AND EMBED_SSH_PATH)
|
||||
file(GLOB SRC_SSH "${EMBED_SSH_PATH}/src/*.c")
|
||||
list(SORT SRC_SSH)
|
||||
list(APPEND LIBGIT2_SYSTEM_INCLUDES "${EMBED_SSH_PATH}/include")
|
||||
file(WRITE "${EMBED_SSH_PATH}/src/libssh2_config.h" "#define HAVE_WINCNG\n#define LIBSSH2_WINCNG\n#include \"../win32/libssh2_config.h\"")
|
||||
set(GIT_SSH 1)
|
||||
endif()
|
||||
|
||||
IF (WIN32 AND WINHTTP)
|
||||
SET(GIT_WINHTTP 1)
|
||||
@@ -267,33 +268,38 @@ ENDIF()
|
||||
ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64)
|
||||
|
||||
# Collect sourcefiles
|
||||
FILE(GLOB SRC_H
|
||||
file(GLOB SRC_H
|
||||
"${libgit2_SOURCE_DIR}/include/git2.h"
|
||||
"${libgit2_SOURCE_DIR}/include/git2/*.h"
|
||||
"${libgit2_SOURCE_DIR}/include/git2/sys/*.h")
|
||||
list(SORT SRC_H)
|
||||
|
||||
# On Windows use specific platform sources
|
||||
IF (WIN32 AND NOT CYGWIN)
|
||||
IF(MSVC)
|
||||
if(WIN32 AND NOT CYGWIN)
|
||||
if(MSVC)
|
||||
SET(WIN_RC "win32/git2.rc")
|
||||
ENDIF()
|
||||
endif()
|
||||
|
||||
FILE(GLOB SRC_OS win32/*.c win32/*.h)
|
||||
ELSEIF (AMIGA)
|
||||
ADD_DEFINITIONS(-DNO_ADDRINFO -DNO_READDIR_R -DNO_MMAP)
|
||||
ELSE()
|
||||
FILE(GLOB SRC_OS unix/*.c unix/*.h)
|
||||
ENDIF()
|
||||
file(GLOB SRC_OS win32/*.c win32/*.h)
|
||||
list(SORT SRC_OS)
|
||||
elseif(AMIGA)
|
||||
add_definitions(-DNO_ADDRINFO -DNO_READDIR_R -DNO_MMAP)
|
||||
else()
|
||||
file(GLOB SRC_OS unix/*.c unix/*.h)
|
||||
list(SORT SRC_OS)
|
||||
endif()
|
||||
|
||||
IF (USE_LEAK_CHECKER STREQUAL "valgrind")
|
||||
ADD_DEFINITIONS(-DVALGRIND)
|
||||
ENDIF()
|
||||
|
||||
FILE(GLOB SRC_GIT2 *.c *.h
|
||||
file(GLOB SRC_GIT2 *.c *.h
|
||||
allocators/*.c allocators/*.h
|
||||
streams/*.c streams/*.h
|
||||
transports/*.c transports/*.h
|
||||
xdiff/*.c xdiff/*.h)
|
||||
list(SORT SRC_GIT2)
|
||||
|
||||
IF(APPLE)
|
||||
# The old Secure Transport API has been deprecated in macOS 10.15.
|
||||
SET_SOURCE_FILES_PROPERTIES(streams/stransport.c PROPERTIES COMPILE_FLAGS -Wno-deprecated)
|
||||
|
||||
Reference in New Issue
Block a user