@@ -27,7 +27,6 @@ endfunction()
27
27
28
28
CheckCompilerCXX11Flag ()
29
29
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )
30
-
31
30
# safe_set_flag
32
31
#
33
32
# Set a compile flag only if compiler is support
@@ -71,6 +70,20 @@ macro(safe_set_nvflag flag_name)
71
70
endif ()
72
71
endmacro ()
73
72
73
+ macro (safe_set_static_flag ) # set c_flags and cxx_flags to static or shared
74
+ if (BUILD_SHARED_LIBS )
75
+ return () # if build shared libs, the flags keep same with '/MD'
76
+ endif (BUILD_SHARED_LIBS )
77
+ foreach (flag_var
78
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
79
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
80
+ CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
81
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO )
82
+ if (${flag_var} MATCHES "/MD" )
83
+ string (REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var} }" )
84
+ endif (${flag_var} MATCHES "/MD" )
85
+ endforeach (flag_var )
86
+ endmacro ()
74
87
75
88
CHECK_CXX_SYMBOL_EXISTS (UINT64_MAX "stdint.h" UINT64_MAX_EXISTS )
76
89
if (NOT UINT64_MAX_EXISTS )
@@ -97,9 +110,13 @@ SET(CMAKE_EXTRA_INCLUDE_FILES "")
97
110
98
111
# Common flags. the compiler flag used for C/C++ sources whenever release or debug
99
112
# Do not care if this flag is support for gcc.
113
+
114
+ # https://github.com/PaddlePaddle/Paddle/issues/12773
115
+ if (NOT WIN32 )
100
116
set (COMMON_FLAGS
101
117
-fPIC
102
118
-fno-omit-frame-pointer
119
+ -Werror
103
120
-Wall
104
121
-Wextra
105
122
-Wnon-virtual-dtor
@@ -114,11 +131,6 @@ set(COMMON_FLAGS
114
131
-Wno-error=terminate # Warning in PADDLE_ENFORCE
115
132
)
116
133
117
- # https://github.com/PaddlePaddle/Paddle/issues/12773
118
- if (NOT WIN32 )
119
- list (APPEND COMMON_FLAGS -Werror )
120
- endif ()
121
-
122
134
set (GPU_COMMON_FLAGS
123
135
-fPIC
124
136
-fno-omit-frame-pointer
@@ -133,30 +145,53 @@ set(GPU_COMMON_FLAGS
133
145
-Wno-error=array-bounds # Warnings in Eigen::array
134
146
)
135
147
148
+ else (NOT WIN32 )
149
+ set (COMMON_FLAGS
150
+ "/w" ) #disable all warnings.
151
+ set (GPU_COMMON_FLAGS
152
+ "/w" ) #disable all warnings
153
+ endif (NOT WIN32 )
154
+
136
155
if (APPLE )
137
156
if (NOT CMAKE_CROSSCOMPILING )
138
157
# On Mac OS X build fat binaries with x86_64 architectures by default.
139
158
set (CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for OSX" FORCE )
140
159
endif ()
141
- else ()
160
+ endif (APPLE )
161
+
162
+ if (LINUX )
142
163
set (GPU_COMMON_FLAGS
143
164
-Wall
144
165
-Wextra
145
166
-Werror
146
167
${GPU_COMMON_FLAGS} )
147
- endif ()
168
+ endif (LINUX )
148
169
149
170
if (UNIX AND NOT APPLE )
150
171
# except apple from nix*Os family
151
172
set (LINUX TRUE )
152
173
endif (UNIX AND NOT APPLE )
153
174
154
-
155
175
foreach (flag ${COMMON_FLAGS} )
156
176
safe_set_cflag (CMAKE_C_FLAGS ${flag} )
157
177
safe_set_cxxflag (CMAKE_CXX_FLAGS ${flag} )
178
+
158
179
endforeach ()
159
180
160
181
foreach (flag ${GPU_COMMON_FLAGS} )
161
182
safe_set_nvflag (${flag} )
162
183
endforeach ()
184
+
185
+ if (WIN32 )
186
+ # windows build turn off warnings.
187
+ safe_set_static_flag ()
188
+ foreach (flag_var
189
+ CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
190
+ CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
191
+ CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
192
+ CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO )
193
+ if (${flag_var} MATCHES "/W3" )
194
+ string (REGEX REPLACE "/W3" "/w" ${flag_var} "${${flag_var} }" )
195
+ endif (${flag_var} MATCHES "/W3" )
196
+ endforeach (flag_var )
197
+ endif (WIN32 )
0 commit comments