Skip to content

Commit fc963f9

Browse files
awnawabwdeconinck
authored andcommitted
Add utility to purge compiler flags for a given language
1 parent b6fc8a6 commit fc963f9

File tree

1 file changed

+40
-4
lines changed

1 file changed

+40
-4
lines changed

‎cmake/ecbuild_compiler_flags.cmake‎

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,45 @@ macro( ecbuild_compiler_flags _lang )
7272

7373
endmacro()
7474

75+
##############################################################################
76+
#.rst:
77+
#
78+
# ecbuild_purge_compiler_flags
79+
# ======================
80+
#
81+
# Purge compiler flags for a given language ::
82+
#
83+
# ecbuild_purge_compiler_flags( <lang> )
84+
#
85+
##############################################################################
86+
87+
macro( ecbuild_purge_compiler_flags _lang )
88+
89+
set( options WARN )
90+
set( oneValueArgs "" )
91+
set( multiValueArgs "" )
92+
93+
cmake_parse_arguments( _PAR "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
94+
95+
if( CMAKE_${_lang}_COMPILER_LOADED )
96+
97+
# Clear default compilation flags potentially inherited from parent scope
98+
# when using custom compilation flags
99+
if( ECBUILD_SOURCE_FLAGS OR ECBUILD_COMPILE_FLAGS )
100+
set(CMAKE_${_lang}_FLAGS "")
101+
foreach(_btype ALL RELEASE RELWITHDEBINFO PRODUCTION BIT DEBUG)
102+
set(CMAKE_${_lang}_FLAGS_${_btype} "")
103+
endforeach()
104+
endif()
105+
106+
endif()
107+
108+
if( ${_PAR_WARN} )
109+
ecbuild_warn( "Purging compiler flags set for ${_lang}" )
110+
endif()
111+
112+
endmacro()
113+
75114
##############################################################################
76115
#.rst:
77116
#
@@ -189,10 +228,7 @@ foreach( _lang C CXX Fortran )
189228
# Clear default compilation flags potentially inherited from parent scope
190229
# when using custom compilation flags
191230
if( ECBUILD_SOURCE_FLAGS OR ECBUILD_COMPILE_FLAGS )
192-
set(CMAKE_${_lang}_FLAGS "")
193-
foreach(_btype ALL RELEASE RELWITHDEBINFO PRODUCTION BIT DEBUG)
194-
set(CMAKE_${_lang}_FLAGS_${_btype} "")
195-
endforeach()
231+
ecbuild_purge_compiler_flags( ${_lang} )
196232
# Load default compilation flags only if custom compilation flags not enabled
197233
else()
198234
ecbuild_compiler_flags( ${_lang} )

0 commit comments

Comments
 (0)