@@ -8,23 +8,6 @@ project(libgit2 VERSION "1.3.0" LANGUAGES C)
88# Add find modules to the path
99set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${libgit2_SOURCE_DIR} /cmake" )
1010
11- # Modules
12-
13- include (CheckLibraryExists)
14- include (CheckFunctionExists)
15- include (CheckSymbolExists)
16- include (CheckStructHasMember)
17- include (CheckPrototypeDefinition)
18- include (AddCFlagIfSupported)
19- include (FindPkgLibraries)
20- include (FindThreads)
21- include (FindStatNsec)
22- include (Findfutimens)
23- include (GNUInstallDirs)
24- include (IdeSplitSources)
25- include (FeatureSummary)
26- include (EnableWarnings)
27-
2811#
2912# Build options
3013#
@@ -98,6 +81,24 @@ if(WIN32)
9881endif ()
9982
10083
84+ # Modules
85+
86+ include (CheckLibraryExists)
87+ include (CheckFunctionExists)
88+ include (CheckSymbolExists)
89+ include (CheckStructHasMember)
90+ include (CheckPrototypeDefinition)
91+ include (AddCFlagIfSupported)
92+ include (FindPkgLibraries)
93+ include (FindThreads)
94+ include (FindStatNsec)
95+ include (Findfutimens)
96+ include (GNUInstallDirs)
97+ include (IdeSplitSources)
98+ include (FeatureSummary)
99+ include (EnableWarnings)
100+ include (DefaultCFlags)
101+
101102#
102103# Compiler / linker flags
103104#
@@ -106,160 +107,6 @@ if(DEPRECATE_HARD)
106107 add_definitions (-DGIT_DEPRECATE_HARD)
107108endif ()
108109
109- # Platform specific compilation flags
110- if (MSVC )
111- add_definitions (-D_SCL_SECURE_NO_WARNINGS)
112- add_definitions (-D_CRT_SECURE_NO_DEPRECATE)
113- add_definitions (-D_CRT_NONSTDC_NO_DEPRECATE)
114-
115- string (REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS} " )
116-
117- # /GF - String pooling
118- # /MP - Parallel build
119- set (CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS} " )
120-
121- # /Gd - explicitly set cdecl calling convention
122- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gd" )
123-
124- if (NOT (MSVC_VERSION LESS 1900))
125- # /guard:cf - Enable Control Flow Guard
126- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:cf" )
127- endif ()
128-
129- if (STATIC_CRT)
130- set (CRT_FLAG_DEBUG "/MTd" )
131- set (CRT_FLAG_RELEASE "/MT" )
132- else ()
133- set (CRT_FLAG_DEBUG "/MDd" )
134- set (CRT_FLAG_RELEASE "/MD" )
135- endif ()
136-
137- if (WIN32_LEAKCHECK)
138- set (GIT_WIN32_LEAKCHECK 1)
139- set (CRT_FLAG_DEBUG "${CRT_FLAG_DEBUG} " )
140- set (CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} Dbghelp.lib" )
141- endif ()
142-
143- # /Zi - Create debugging information
144- # /Od - Disable optimization
145- # /D_DEBUG - #define _DEBUG
146- # /MTd - Statically link the multithreaded debug version of the CRT
147- # /MDd - Dynamically link the multithreaded debug version of the CRT
148- # /RTC1 - Run time checks
149- set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG} " )
150-
151- # /DNDEBUG - Disables asserts
152- # /MT - Statically link the multithreaded release version of the CRT
153- # /MD - Dynamically link the multithreaded release version of the CRT
154- # /O2 - Optimize for speed
155- # /Oy - Enable frame pointer omission (FPO) (otherwise CMake will automatically turn it off)
156- # /GL - Link time code generation (whole program optimization)
157- # /Gy - Function-level linking
158- set (CMAKE_C_FLAGS_RELEASE "/DNDEBUG /O2 /Oy /GL /Gy ${CRT_FLAG_RELEASE} " )
159-
160- # /Oy- - Disable frame pointer omission (FPO)
161- set (CMAKE_C_FLAGS_RELWITHDEBINFO "/DNDEBUG /Zi /O2 /Oy- /GL /Gy ${CRT_FLAG_RELEASE} " )
162-
163- # /O1 - Optimize for size
164- set (CMAKE_C_FLAGS_MINSIZEREL "/DNDEBUG /O1 /Oy /GL /Gy ${CRT_FLAG_RELEASE} " )
165-
166- # /IGNORE:4221 - Ignore empty compilation units
167- set (CMAKE_STATIC_LINKER_FLAGS "/IGNORE:4221" )
168-
169- # /DYNAMICBASE - Address space load randomization (ASLR)
170- # /NXCOMPAT - Data execution prevention (DEP)
171- # /LARGEADDRESSAWARE - >2GB user address space on x86
172- # /VERSION - Embed version information in PE header
173- set (CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${libgit2_VERSION_MAJOR} .${libgit2_VERSION_MINOR} " )
174-
175- if (NOT (MSVC_VERSION LESS 1900))
176- # /GUARD:CF - Enable Control Flow Guard
177- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /GUARD:CF" )
178- endif ()
179-
180- # /DEBUG - Create a PDB
181- # /LTCG - Link time code generation (whole program optimization)
182- # /OPT:REF /OPT:ICF - Fold out duplicate code at link step
183- # /INCREMENTAL:NO - Required to use /LTCG
184- # /DEBUGTYPE:cv,fixup - Additional data embedded in the PDB (requires /INCREMENTAL:NO, so not on for Debug)
185- set (CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG" )
186- set (CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO" )
187- set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup" )
188- set (CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO" )
189-
190- # Same linker settings for DLL as EXE
191- set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} " )
192- set (CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} " )
193- set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} " )
194- set (CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} " )
195- set (CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} " )
196- else ()
197- if (ENABLE_REPRODUCIBLE_BUILDS)
198- set (CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>" )
199- set (CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> Dq <TARGET> <LINK_FLAGS> <OBJECTS>" )
200- set (CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>" )
201- endif ()
202-
203- if (NOT BUILD_SHARED_LIBS )
204- set (CMAKE_FIND_LIBRARY_SUFFIXES ".a" )
205- endif ()
206-
207- set (CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS} " )
208-
209- enable_warnings(all )
210- enable_warnings(extra)
211-
212- if (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)" )
213- set (CMAKE_C_FLAGS "-D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS} " )
214- endif ()
215-
216- set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -O0" )
217-
218- if (MINGW OR MSYS) # MinGW and MSYS always do PIC and complain if we tell them to
219- string (REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS} " )
220- elseif (BUILD_SHARED_LIBS )
221- add_c_flag_IF_SUPPORTED(-fvisibility=hidden)
222-
223- set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC" )
224- endif ()
225-
226- if (MINGW)
227- # MinGW >= 3.14 uses the C99-style stdio functions
228- # automatically, but forks like mingw-w64 still want
229- # us to define this in order to use them
230- add_definitions (-D__USE_MINGW_ANSI_STDIO=1)
231- endif ()
232-
233- enable_warnings(documentation)
234- disable_warnings(documentation-deprecated-sync)
235- disable_warnings(missing-field-initializers)
236- enable_warnings(strict-aliasing)
237- enable_warnings(strict-prototypes)
238- enable_warnings(declaration-after-statement)
239- enable_warnings(shift-count-overflow)
240- enable_warnings(unused-const-variable )
241- enable_warnings(unused-function)
242- enable_warnings(int-conversion)
243- enable_warnings(c11-extensions)
244- enable_warnings(c99-c11-compat)
245-
246- # MinGW uses gcc, which expects POSIX formatting for printf, but
247- # uses the Windows C library, which uses its own format specifiers.
248- # Disable format specifier warnings.
249- if (MINGW)
250- disable_warnings(format)
251- disable_warnings(format-security)
252- else ()
253- enable_warnings(format)
254- enable_warnings(format-security)
255- endif ()
256- endif ()
257-
258- # Ensure that MinGW provides the correct header files.
259- if (WIN32 AND NOT CYGWIN )
260- add_definitions (-DWIN32 -D_WIN32_WINNT=0x0600)
261- endif ()
262-
263110if (NOT CMAKE_CONFIGURATION_TYPES )
264111 # Build Debug by default
265112 if (NOT CMAKE_BUILD_TYPE )
0 commit comments