diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2018-02-07 17:35:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-07 17:35:57 +0000 |
commit | f7225946edeae35f48e3d402e2e0c94ea07f9666 (patch) | |
tree | bd6da1aa32a775b9d50c9507b425d19ca2736649 | |
parent | 26f5d36d2f14dc1d711ed0a2c844ef4d7887a9b3 (diff) | |
parent | f8a2dda8266e09540b9821e20bf081da2355b105 (diff) | |
download | libgit2-f7225946edeae35f48e3d402e2e0c94ea07f9666.tar.gz |
Merge pull request #4513 from libgit2/ethomson/cmake_fixes
CMake: minor fixups
-rw-r--r-- | CMakeLists.txt | 67 | ||||
-rw-r--r-- | cmake/Modules/EnableWarnings.cmake | 14 | ||||
-rw-r--r-- | cmake/Modules/FindStatNsec.cmake | 20 | ||||
-rw-r--r-- | cmake/Modules/IdeSplitSources.cmake | 22 |
4 files changed, 63 insertions, 60 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d5ad9d05..53f10ba94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,9 +14,12 @@ PROJECT(libgit2 C) CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11) CMAKE_POLICY(SET CMP0015 NEW) -IF (NOT CMAKE_VERSION VERSION_LESS 3.1) +IF (POLICY CMP0051) CMAKE_POLICY(SET CMP0051 NEW) ENDIF() +IF (POLICY CMP0042) + CMAKE_POLICY(SET CMP0042 NEW) +ENDIF() # Add find modules to the path SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake/Modules/") @@ -28,7 +31,10 @@ INCLUDE(CheckStructHasMember) INCLUDE(AddCFlagIfSupported) INCLUDE(FindPkgConfig) INCLUDE(FindThreads) +INCLUDE(FindStatNsec) +INCLUDE(IdeSplitSources) INCLUDE(FeatureSummary) +INCLUDE(EnableWarnings) # Build options # @@ -91,50 +97,6 @@ IF(MSVC) OPTION(MSVC_CRTDBG "Enable CRTDBG memory leak reporting" OFF) ENDIF() -CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim "sys/types.h;sys/stat.h" - HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C) -CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec "sys/types.h;sys/stat.h" - HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE C) -CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtime_nsec sys/stat.h - HAVE_STRUCT_STAT_MTIME_NSEC LANGUAGE C) - -IF (HAVE_STRUCT_STAT_ST_MTIM) - CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h - HAVE_STRUCT_STAT_NSEC LANGUAGE C) -ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC) - CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec sys/stat.h - HAVE_STRUCT_STAT_NSEC LANGUAGE C) -ELSE () - SET( HAVE_STRUCT_STAT_NSEC ON ) -ENDIF() - -IF (HAVE_STRUCT_STAT_NSEC OR WIN32) - OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" ON ) -ENDIF() - -# This function splits the sources files up into their appropriate -# subdirectories. This is especially useful for IDEs like Xcode and -# Visual Studio, so that you can navigate into the libgit2_clar project, -# and see the folders within the tests folder (instead of just seeing all -# source and tests in a single folder.) -FUNCTION(IDE_SPLIT_SOURCES target) - IF(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode) - GET_TARGET_PROPERTY(sources ${target} SOURCES) - FOREACH(source ${sources}) - IF(source MATCHES ".*/") - STRING(REPLACE ${libgit2_SOURCE_DIR}/ "" rel ${source}) - IF(rel) - STRING(REGEX REPLACE "/([^/]*)$" "" rel ${rel}) - IF(rel) - STRING(REPLACE "/" "\\\\" rel ${rel}) - SOURCE_GROUP(${rel} FILES ${source}) - ENDIF() - ENDIF() - ENDIF() - ENDFOREACH() - ENDIF() -ENDFUNCTION() - FILE(STRINGS "${libgit2_SOURCE_DIR}/include/git2/version.h" GIT2_HEADER REGEX "^#define LIBGIT2_VERSION \"[^\"]*\"$") STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"([0-9]+).*$" "\\1" LIBGIT2_VERSION_MAJOR "${GIT2_HEADER}") @@ -230,21 +192,6 @@ ELSE () SET(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}") - MACRO(ENABLE_WARNINGS flag) - IF(ENABLE_WERROR) - ADD_C_FLAG_IF_SUPPORTED(-Werror=${flag}) - ELSE() - ADD_C_FLAG_IF_SUPPORTED(-W${flag}) - ENDIF() - ENDMACRO() - - MACRO(DISABLE_WARNINGS flag) - ADD_C_FLAG_IF_SUPPORTED(-Wno-${flag}) - IF(ENABLE_WERROR) - ADD_C_FLAG_IF_SUPPORTED(-Wno-error=${flag}) - ENDIF() - ENDMACRO() - ENABLE_WARNINGS(all) ENABLE_WARNINGS(extra) diff --git a/cmake/Modules/EnableWarnings.cmake b/cmake/Modules/EnableWarnings.cmake new file mode 100644 index 000000000..e7d7d3986 --- /dev/null +++ b/cmake/Modules/EnableWarnings.cmake @@ -0,0 +1,14 @@ +MACRO(ENABLE_WARNINGS flag) + IF(ENABLE_WERROR) + ADD_C_FLAG_IF_SUPPORTED(-Werror=${flag}) + ELSE() + ADD_C_FLAG_IF_SUPPORTED(-W${flag}) + ENDIF() +ENDMACRO() + +MACRO(DISABLE_WARNINGS flag) + ADD_C_FLAG_IF_SUPPORTED(-Wno-${flag}) + IF(ENABLE_WERROR) + ADD_C_FLAG_IF_SUPPORTED(-Wno-error=${flag}) + ENDIF() +ENDMACRO() diff --git a/cmake/Modules/FindStatNsec.cmake b/cmake/Modules/FindStatNsec.cmake new file mode 100644 index 000000000..fa550a214 --- /dev/null +++ b/cmake/Modules/FindStatNsec.cmake @@ -0,0 +1,20 @@ +CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim "sys/types.h;sys/stat.h" + HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C) +CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec "sys/types.h;sys/stat.h" + HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE C) +CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtime_nsec sys/stat.h + HAVE_STRUCT_STAT_MTIME_NSEC LANGUAGE C) + +IF (HAVE_STRUCT_STAT_ST_MTIM) + CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h + HAVE_STRUCT_STAT_NSEC LANGUAGE C) +ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC) + CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec sys/stat.h + HAVE_STRUCT_STAT_NSEC LANGUAGE C) +ELSE () + SET( HAVE_STRUCT_STAT_NSEC ON ) +ENDIF() + +IF (HAVE_STRUCT_STAT_NSEC OR WIN32) + OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" ON ) +ENDIF() diff --git a/cmake/Modules/IdeSplitSources.cmake b/cmake/Modules/IdeSplitSources.cmake new file mode 100644 index 000000000..e2e09b4ce --- /dev/null +++ b/cmake/Modules/IdeSplitSources.cmake @@ -0,0 +1,22 @@ +# This function splits the sources files up into their appropriate +# subdirectories. This is especially useful for IDEs like Xcode and +# Visual Studio, so that you can navigate into the libgit2_clar project, +# and see the folders within the tests folder (instead of just seeing all +# source and tests in a single folder.) +FUNCTION(IDE_SPLIT_SOURCES target) + IF(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode) + GET_TARGET_PROPERTY(sources ${target} SOURCES) + FOREACH(source ${sources}) + IF(source MATCHES ".*/") + STRING(REPLACE ${libgit2_SOURCE_DIR}/ "" rel ${source}) + IF(rel) + STRING(REGEX REPLACE "/([^/]*)$" "" rel ${rel}) + IF(rel) + STRING(REPLACE "/" "\\\\" rel ${rel}) + SOURCE_GROUP(${rel} FILES ${source}) + ENDIF() + ENDIF() + ENDIF() + ENDFOREACH() + ENDIF() +ENDFUNCTION() |