]>
Commit | Line | Data |
---|---|---|
e579e0f7 MB |
1 | # Platform specific compilation flags |
2 | if(MSVC) | |
3 | add_definitions(-D_SCL_SECURE_NO_WARNINGS) | |
4 | add_definitions(-D_CRT_SECURE_NO_DEPRECATE) | |
5 | add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) | |
6 | ||
7 | string(REPLACE "/Zm1000" " " CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") | |
8 | ||
9 | # /GF - String pooling | |
10 | # /MP - Parallel build | |
11 | set(CMAKE_C_FLAGS "/GF /MP /nologo ${CMAKE_C_FLAGS}") | |
12 | ||
13 | # /Gd - explicitly set cdecl calling convention | |
14 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gd") | |
15 | ||
16 | if(NOT (MSVC_VERSION LESS 1900)) | |
17 | # /guard:cf - Enable Control Flow Guard | |
18 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:cf") | |
19 | endif() | |
20 | ||
21 | if(STATIC_CRT) | |
22 | set(CRT_FLAG_DEBUG "/MTd") | |
23 | set(CRT_FLAG_RELEASE "/MT") | |
24 | else() | |
25 | set(CRT_FLAG_DEBUG "/MDd") | |
26 | set(CRT_FLAG_RELEASE "/MD") | |
27 | endif() | |
28 | ||
29 | if(WIN32_LEAKCHECK) | |
30 | set(GIT_WIN32_LEAKCHECK 1) | |
31 | set(CRT_FLAG_DEBUG "${CRT_FLAG_DEBUG}") | |
32 | set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} Dbghelp.lib") | |
33 | endif() | |
34 | ||
35 | # /Zi - Create debugging information | |
36 | # /Od - Disable optimization | |
37 | # /D_DEBUG - #define _DEBUG | |
38 | # /MTd - Statically link the multithreaded debug version of the CRT | |
39 | # /MDd - Dynamically link the multithreaded debug version of the CRT | |
40 | # /RTC1 - Run time checks | |
41 | set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /Zi /Od /D_DEBUG /RTC1 ${CRT_FLAG_DEBUG}") | |
42 | ||
43 | # /DNDEBUG - Disables asserts | |
44 | # /MT - Statically link the multithreaded release version of the CRT | |
45 | # /MD - Dynamically link the multithreaded release version of the CRT | |
46 | # /O2 - Optimize for speed | |
47 | # /Oy - Enable frame pointer omission (FPO) (otherwise CMake will automatically turn it off) | |
48 | # /GL - Link time code generation (whole program optimization) | |
49 | # /Gy - Function-level linking | |
50 | set(CMAKE_C_FLAGS_RELEASE "/DNDEBUG /O2 /Oy /GL /Gy ${CRT_FLAG_RELEASE}") | |
51 | ||
52 | # /Oy- - Disable frame pointer omission (FPO) | |
53 | set(CMAKE_C_FLAGS_RELWITHDEBINFO "/DNDEBUG /Zi /O2 /Oy- /GL /Gy ${CRT_FLAG_RELEASE}") | |
54 | ||
55 | # /O1 - Optimize for size | |
56 | set(CMAKE_C_FLAGS_MINSIZEREL "/DNDEBUG /O1 /Oy /GL /Gy ${CRT_FLAG_RELEASE}") | |
57 | ||
58 | # /IGNORE:4221 - Ignore empty compilation units | |
59 | set(CMAKE_STATIC_LINKER_FLAGS "/IGNORE:4221") | |
60 | ||
61 | # /DYNAMICBASE - Address space load randomization (ASLR) | |
62 | # /NXCOMPAT - Data execution prevention (DEP) | |
63 | # /LARGEADDRESSAWARE - >2GB user address space on x86 | |
64 | # /VERSION - Embed version information in PE header | |
65 | set(CMAKE_EXE_LINKER_FLAGS "/DYNAMICBASE /NXCOMPAT /LARGEADDRESSAWARE /VERSION:${libgit2_VERSION_MAJOR}.${libgit2_VERSION_MINOR}") | |
66 | ||
67 | if(NOT (MSVC_VERSION LESS 1900)) | |
68 | # /GUARD:CF - Enable Control Flow Guard | |
69 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /GUARD:CF") | |
70 | endif() | |
71 | ||
72 | # /DEBUG - Create a PDB | |
73 | # /LTCG - Link time code generation (whole program optimization) | |
74 | # /OPT:REF /OPT:ICF - Fold out duplicate code at link step | |
75 | # /INCREMENTAL:NO - Required to use /LTCG | |
76 | # /DEBUGTYPE:cv,fixup - Additional data embedded in the PDB (requires /INCREMENTAL:NO, so not on for Debug) | |
77 | set(CMAKE_EXE_LINKER_FLAGS_DEBUG "/DEBUG") | |
78 | set(CMAKE_EXE_LINKER_FLAGS_RELEASE "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO") | |
79 | set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "/DEBUG /RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO /DEBUGTYPE:cv,fixup") | |
80 | set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "/RELEASE /LTCG /OPT:REF /OPT:ICF /INCREMENTAL:NO") | |
81 | ||
82 | # Same linker settings for DLL as EXE | |
83 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") | |
84 | set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") | |
85 | set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") | |
86 | set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}") | |
87 | set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}") | |
88 | else() | |
89 | if(ENABLE_REPRODUCIBLE_BUILDS) | |
90 | set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> Dqc <TARGET> <LINK_FLAGS> <OBJECTS>") | |
91 | set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> Dq <TARGET> <LINK_FLAGS> <OBJECTS>") | |
92 | set(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> -D <TARGET>") | |
93 | endif() | |
94 | ||
95 | if(NOT BUILD_SHARED_LIBS AND LINK_WITH_STATIC_LIBRARIES) | |
96 | set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") | |
97 | endif() | |
98 | ||
99 | set(CMAKE_C_FLAGS "-D_GNU_SOURCE ${CMAKE_C_FLAGS}") | |
100 | ||
101 | enable_warnings(all) | |
102 | enable_warnings(extra) | |
103 | ||
104 | if(CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") | |
105 | set(CMAKE_C_FLAGS "-D_POSIX_C_SOURCE=200112L -D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS ${CMAKE_C_FLAGS}") | |
106 | endif() | |
107 | ||
108 | set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG -O0") | |
109 | ||
110 | if(MINGW OR MSYS) # MinGW and MSYS always do PIC and complain if we tell them to | |
111 | string(REGEX REPLACE "-fPIC" "" CMAKE_SHARED_LIBRARY_C_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}") | |
112 | elseif(BUILD_SHARED_LIBS) | |
113 | add_c_flag_IF_SUPPORTED(-fvisibility=hidden) | |
114 | ||
115 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") | |
116 | endif() | |
117 | ||
118 | if(MINGW) | |
119 | # MinGW >= 3.14 uses the C99-style stdio functions | |
120 | # automatically, but forks like mingw-w64 still want | |
121 | # us to define this in order to use them | |
122 | add_definitions(-D__USE_MINGW_ANSI_STDIO=1) | |
123 | endif() | |
124 | ||
125 | enable_warnings(documentation) | |
126 | disable_warnings(documentation-deprecated-sync) | |
127 | disable_warnings(missing-field-initializers) | |
128 | enable_warnings(missing-declarations) | |
129 | enable_warnings(strict-aliasing) | |
130 | enable_warnings(strict-prototypes) | |
131 | enable_warnings(declaration-after-statement) | |
132 | enable_warnings(shift-count-overflow) | |
133 | enable_warnings(unused-const-variable) | |
134 | enable_warnings(unused-function) | |
135 | enable_warnings(int-conversion) | |
136 | enable_warnings(c11-extensions) | |
137 | enable_warnings(c99-c11-compat) | |
138 | ||
139 | # MinGW uses gcc, which expects POSIX formatting for printf, but | |
140 | # uses the Windows C library, which uses its own format specifiers. | |
141 | # Disable format specifier warnings. | |
142 | if(MINGW) | |
143 | disable_warnings(format) | |
144 | disable_warnings(format-security) | |
145 | else() | |
146 | enable_warnings(format) | |
147 | enable_warnings(format-security) | |
148 | endif() | |
149 | endif() | |
150 | ||
151 | # Ensure that MinGW provides the correct header files. | |
152 | if(WIN32 AND NOT CYGWIN) | |
153 | add_definitions(-DWIN32 -D_WIN32_WINNT=0x0600) | |
154 | endif() |