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