summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAxel Rasmussen <axelrasmussen@google.com>2015-06-15 09:28:55 -0600
committerAxel Rasmussen <axelrasmussen@google.com>2015-09-18 23:33:56 -0700
commite9e6df2c8f4a8577fcbcfdf56bf255ef9774b6ec (patch)
tree1b3737835e6e274be11db210a18974f2c40bff74
parent2be7855727acf829de989f92a8f97a31ec3a378a (diff)
downloadlibgit2-e9e6df2c8f4a8577fcbcfdf56bf255ef9774b6ec.tar.gz
cmake: Only provide USE_NSEC if struct stat members are avilable.
This allows us to remove OS checks from source code, instead relying on CMake to detect whether or not `struct stat` has the nanoseconds members we rely on.
-rw-r--r--CMakeLists.txt8
-rw-r--r--src/index.c3
-rw-r--r--tests/merge/workdir/dirty.c3
3 files changed, 9 insertions, 5 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5790a03c9..cb1f1b8b4 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,9 +19,13 @@ CMAKE_POLICY(SET CMP0015 NEW)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
INCLUDE(CheckLibraryExists)
+INCLUDE(CheckStructHasMember)
INCLUDE(AddCFlagIfSupported)
INCLUDE(FindPkgConfig)
+CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h
+ HAVE_STRUCT_STAT_NSEC LANGUAGE C)
+
# Build options
#
OPTION( SONAME "Set the (SO)VERSION of the target" ON )
@@ -37,7 +41,9 @@ OPTION( LIBGIT2_FILENAME "Name of the produced binary" OFF )
OPTION( USE_ICONV "Link with and use iconv library" OFF )
OPTION( USE_SSH "Link with libssh to enable SSH support" ON )
OPTION( USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF )
-OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" OFF )
+IF(HAVE_STRUCT_STAT_NSEC)
+ OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" OFF )
+ENDIF()
OPTION( VALGRIND "Configure build for valgrind" OFF )
OPTION( CURL "User curl for HTTP if available" ON)
diff --git a/src/index.c b/src/index.c
index 54a8b1eec..bd56cc794 100644
--- a/src/index.c
+++ b/src/index.c
@@ -858,8 +858,7 @@ void git_index_entry__init_from_stat(
{
entry->ctime.seconds = (git_time_t)st->st_ctime;
entry->mtime.seconds = (git_time_t)st->st_mtime;
-#if !defined(GIT_WIN32) && !defined(__APPLE__)
- /* Apple and Windows doesn't provide these struct stat fields. */
+#if defined(GIT_USE_NSEC)
entry->mtime.nanoseconds = st->st_mtim.tv_nsec;
entry->ctime.nanoseconds = st->st_ctim.tv_nsec;
#endif
diff --git a/tests/merge/workdir/dirty.c b/tests/merge/workdir/dirty.c
index ed402bd14..f168963b2 100644
--- a/tests/merge/workdir/dirty.c
+++ b/tests/merge/workdir/dirty.c
@@ -164,8 +164,7 @@ static void hack_index(char *files[])
entry->ctime.seconds = (git_time_t)statbuf.st_ctime;
entry->mtime.seconds = (git_time_t)statbuf.st_mtime;
-#if !defined(GIT_WIN32) && !defined(__APPLE__)
- /* Apple and Windows doesn't provide these struct stat fields. */
+#if defined(GIT_USE_NSEC)
entry->ctime.nanoseconds = statbuf.st_ctim.tv_nsec;
entry->mtime.nanoseconds = statbuf.st_mtim.tv_nsec;
#else