Skip to content

Commit 3e71ad0

Browse files
authored
flags (#13540)
* flags * "fix ci"
1 parent 01fda93 commit 3e71ad0

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

cmake/flags.cmake

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ endfunction()
2727

2828
CheckCompilerCXX11Flag()
2929
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
30-
3130
# safe_set_flag
3231
#
3332
# Set a compile flag only if compiler is support
@@ -71,6 +70,20 @@ macro(safe_set_nvflag flag_name)
7170
endif()
7271
endmacro()
7372

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()
7487

7588
CHECK_CXX_SYMBOL_EXISTS(UINT64_MAX "stdint.h" UINT64_MAX_EXISTS)
7689
if(NOT UINT64_MAX_EXISTS)
@@ -97,9 +110,13 @@ SET(CMAKE_EXTRA_INCLUDE_FILES "")
97110

98111
# Common flags. the compiler flag used for C/C++ sources whenever release or debug
99112
# Do not care if this flag is support for gcc.
113+
114+
# https://github.com/PaddlePaddle/Paddle/issues/12773
115+
if (NOT WIN32)
100116
set(COMMON_FLAGS
101117
-fPIC
102118
-fno-omit-frame-pointer
119+
-Werror
103120
-Wall
104121
-Wextra
105122
-Wnon-virtual-dtor
@@ -114,11 +131,6 @@ set(COMMON_FLAGS
114131
-Wno-error=terminate # Warning in PADDLE_ENFORCE
115132
)
116133

117-
# https://github.com/PaddlePaddle/Paddle/issues/12773
118-
if (NOT WIN32)
119-
list(APPEND COMMON_FLAGS -Werror)
120-
endif()
121-
122134
set(GPU_COMMON_FLAGS
123135
-fPIC
124136
-fno-omit-frame-pointer
@@ -133,30 +145,53 @@ set(GPU_COMMON_FLAGS
133145
-Wno-error=array-bounds # Warnings in Eigen::array
134146
)
135147

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+
136155
if (APPLE)
137156
if(NOT CMAKE_CROSSCOMPILING)
138157
# On Mac OS X build fat binaries with x86_64 architectures by default.
139158
set (CMAKE_OSX_ARCHITECTURES "x86_64" CACHE STRING "Build architectures for OSX" FORCE)
140159
endif()
141-
else()
160+
endif(APPLE)
161+
162+
if(LINUX)
142163
set(GPU_COMMON_FLAGS
143164
-Wall
144165
-Wextra
145166
-Werror
146167
${GPU_COMMON_FLAGS})
147-
endif()
168+
endif(LINUX)
148169

149170
if(UNIX AND NOT APPLE)
150171
# except apple from nix*Os family
151172
set(LINUX TRUE)
152173
endif(UNIX AND NOT APPLE)
153174

154-
155175
foreach(flag ${COMMON_FLAGS})
156176
safe_set_cflag(CMAKE_C_FLAGS ${flag})
157177
safe_set_cxxflag(CMAKE_CXX_FLAGS ${flag})
178+
158179
endforeach()
159180

160181
foreach(flag ${GPU_COMMON_FLAGS})
161182
safe_set_nvflag(${flag})
162183
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

Comments
 (0)