Skip to content

Commit f722594

Browse files
authored
Merge pull request libgit2#4513 from libgit2/ethomson/cmake_fixes
CMake: minor fixups
2 parents 26f5d36 + f8a2dda commit f722594

File tree

4 files changed

+63
-60
lines changed

4 files changed

+63
-60
lines changed

CMakeLists.txt

Lines changed: 7 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@
1414
PROJECT(libgit2 C)
1515
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
1616
CMAKE_POLICY(SET CMP0015 NEW)
17-
IF (NOT CMAKE_VERSION VERSION_LESS 3.1)
17+
IF (POLICY CMP0051)
1818
CMAKE_POLICY(SET CMP0051 NEW)
1919
ENDIF()
20+
IF (POLICY CMP0042)
21+
CMAKE_POLICY(SET CMP0042 NEW)
22+
ENDIF()
2023

2124
# Add find modules to the path
2225
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR}/cmake/Modules/")
@@ -28,7 +31,10 @@ INCLUDE(CheckStructHasMember)
2831
INCLUDE(AddCFlagIfSupported)
2932
INCLUDE(FindPkgConfig)
3033
INCLUDE(FindThreads)
34+
INCLUDE(FindStatNsec)
35+
INCLUDE(IdeSplitSources)
3136
INCLUDE(FeatureSummary)
37+
INCLUDE(EnableWarnings)
3238

3339
# Build options
3440
#
@@ -91,50 +97,6 @@ IF(MSVC)
9197
OPTION(MSVC_CRTDBG "Enable CRTDBG memory leak reporting" OFF)
9298
ENDIF()
9399

94-
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim "sys/types.h;sys/stat.h"
95-
HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C)
96-
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec "sys/types.h;sys/stat.h"
97-
HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE C)
98-
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtime_nsec sys/stat.h
99-
HAVE_STRUCT_STAT_MTIME_NSEC LANGUAGE C)
100-
101-
IF (HAVE_STRUCT_STAT_ST_MTIM)
102-
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h
103-
HAVE_STRUCT_STAT_NSEC LANGUAGE C)
104-
ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC)
105-
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec sys/stat.h
106-
HAVE_STRUCT_STAT_NSEC LANGUAGE C)
107-
ELSE ()
108-
SET( HAVE_STRUCT_STAT_NSEC ON )
109-
ENDIF()
110-
111-
IF (HAVE_STRUCT_STAT_NSEC OR WIN32)
112-
OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" ON )
113-
ENDIF()
114-
115-
# This function splits the sources files up into their appropriate
116-
# subdirectories. This is especially useful for IDEs like Xcode and
117-
# Visual Studio, so that you can navigate into the libgit2_clar project,
118-
# and see the folders within the tests folder (instead of just seeing all
119-
# source and tests in a single folder.)
120-
FUNCTION(IDE_SPLIT_SOURCES target)
121-
IF(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode)
122-
GET_TARGET_PROPERTY(sources ${target} SOURCES)
123-
FOREACH(source ${sources})
124-
IF(source MATCHES ".*/")
125-
STRING(REPLACE ${libgit2_SOURCE_DIR}/ "" rel ${source})
126-
IF(rel)
127-
STRING(REGEX REPLACE "/([^/]*)$" "" rel ${rel})
128-
IF(rel)
129-
STRING(REPLACE "/" "\\\\" rel ${rel})
130-
SOURCE_GROUP(${rel} FILES ${source})
131-
ENDIF()
132-
ENDIF()
133-
ENDIF()
134-
ENDFOREACH()
135-
ENDIF()
136-
ENDFUNCTION()
137-
138100
FILE(STRINGS "${libgit2_SOURCE_DIR}/include/git2/version.h" GIT2_HEADER REGEX "^#define LIBGIT2_VERSION \"[^\"]*\"$")
139101

140102
STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"([0-9]+).*$" "\\1" LIBGIT2_VERSION_MAJOR "${GIT2_HEADER}")
@@ -230,21 +192,6 @@ ELSE ()
230192

231193
SET(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}")
232194

233-
MACRO(ENABLE_WARNINGS flag)
234-
IF(ENABLE_WERROR)
235-
ADD_C_FLAG_IF_SUPPORTED(-Werror=${flag})
236-
ELSE()
237-
ADD_C_FLAG_IF_SUPPORTED(-W${flag})
238-
ENDIF()
239-
ENDMACRO()
240-
241-
MACRO(DISABLE_WARNINGS flag)
242-
ADD_C_FLAG_IF_SUPPORTED(-Wno-${flag})
243-
IF(ENABLE_WERROR)
244-
ADD_C_FLAG_IF_SUPPORTED(-Wno-error=${flag})
245-
ENDIF()
246-
ENDMACRO()
247-
248195
ENABLE_WARNINGS(all)
249196
ENABLE_WARNINGS(extra)
250197

cmake/Modules/EnableWarnings.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
MACRO(ENABLE_WARNINGS flag)
2+
IF(ENABLE_WERROR)
3+
ADD_C_FLAG_IF_SUPPORTED(-Werror=${flag})
4+
ELSE()
5+
ADD_C_FLAG_IF_SUPPORTED(-W${flag})
6+
ENDIF()
7+
ENDMACRO()
8+
9+
MACRO(DISABLE_WARNINGS flag)
10+
ADD_C_FLAG_IF_SUPPORTED(-Wno-${flag})
11+
IF(ENABLE_WERROR)
12+
ADD_C_FLAG_IF_SUPPORTED(-Wno-error=${flag})
13+
ENDIF()
14+
ENDMACRO()

cmake/Modules/FindStatNsec.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtim "sys/types.h;sys/stat.h"
2+
HAVE_STRUCT_STAT_ST_MTIM LANGUAGE C)
3+
CHECK_STRUCT_HAS_MEMBER ("struct stat" st_mtimespec "sys/types.h;sys/stat.h"
4+
HAVE_STRUCT_STAT_ST_MTIMESPEC LANGUAGE C)
5+
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtime_nsec sys/stat.h
6+
HAVE_STRUCT_STAT_MTIME_NSEC LANGUAGE C)
7+
8+
IF (HAVE_STRUCT_STAT_ST_MTIM)
9+
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h
10+
HAVE_STRUCT_STAT_NSEC LANGUAGE C)
11+
ELSEIF (HAVE_STRUCT_STAT_ST_MTIMESPEC)
12+
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtimespec.tv_nsec sys/stat.h
13+
HAVE_STRUCT_STAT_NSEC LANGUAGE C)
14+
ELSE ()
15+
SET( HAVE_STRUCT_STAT_NSEC ON )
16+
ENDIF()
17+
18+
IF (HAVE_STRUCT_STAT_NSEC OR WIN32)
19+
OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" ON )
20+
ENDIF()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This function splits the sources files up into their appropriate
2+
# subdirectories. This is especially useful for IDEs like Xcode and
3+
# Visual Studio, so that you can navigate into the libgit2_clar project,
4+
# and see the folders within the tests folder (instead of just seeing all
5+
# source and tests in a single folder.)
6+
FUNCTION(IDE_SPLIT_SOURCES target)
7+
IF(MSVC_IDE OR CMAKE_GENERATOR STREQUAL Xcode)
8+
GET_TARGET_PROPERTY(sources ${target} SOURCES)
9+
FOREACH(source ${sources})
10+
IF(source MATCHES ".*/")
11+
STRING(REPLACE ${libgit2_SOURCE_DIR}/ "" rel ${source})
12+
IF(rel)
13+
STRING(REGEX REPLACE "/([^/]*)$" "" rel ${rel})
14+
IF(rel)
15+
STRING(REPLACE "/" "\\\\" rel ${rel})
16+
SOURCE_GROUP(${rel} FILES ${source})
17+
ENDIF()
18+
ENDIF()
19+
ENDIF()
20+
ENDFOREACH()
21+
ENDIF()
22+
ENDFUNCTION()

0 commit comments

Comments
 (0)