Skip to content

Commit 3ea1a7a

Browse files
committed
Enable distinction between enabled/disabled features
- Add enabled/disabled features marker in project summary - Force once enabled features to be displayed as enabled, regardless of of any disabled use Re Github #65
1 parent ec37dd2 commit 3ea1a7a

File tree

2 files changed

+33
-11
lines changed

2 files changed

+33
-11
lines changed

cmake/ecbuild_add_option.cmake

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ macro( ecbuild_add_option )
109109
set( _p_DEFAULT ON )
110110
else()
111111
if( NOT _p_DEFAULT MATCHES "[Oo][Nn]" AND NOT _p_DEFAULT MATCHES "[Oo][Ff][Ff]" )
112-
ecbuild_critical("In macro ecbuild_add_option(), DEFAULT is either ON or OFF: \"${_p_DEFAULT}\"")
112+
ecbuild_critical("In macro ecbuild_add_option(), DEFAULT must be either ON or OFF, but found: \"${_p_DEFAULT}\"")
113113
endif()
114114
endif()
115115
ecbuild_debug("ecbuild_add_option(${_p_FEATURE}): defaults to ${_p_DEFAULT}")
@@ -153,12 +153,6 @@ macro( ecbuild_add_option )
153153
# define the option -- for cmake GUI
154154

155155
option( ENABLE_${_p_FEATURE} "${_p_DESCRIPTION}" ${_p_DEFAULT} )
156-
get_property( _feature_desc GLOBAL PROPERTY _CMAKE_${_p_FEATURE}_DESCRIPTION )
157-
if( _feature_desc )
158-
add_feature_info( ${_p_FEATURE} ENABLE_${_p_FEATURE} "${_feature_desc}, ${PROJECT_NAME}: ${_p_DESCRIPTION}" )
159-
else()
160-
add_feature_info( ${_p_FEATURE} ENABLE_${_p_FEATURE} "${PROJECT_NAME}: ${_p_DESCRIPTION}" )
161-
endif()
162156

163157
ecbuild_debug("ecbuild_add_option(${_p_FEATURE}): defining option ENABLE_${_p_FEATURE} '${_p_DESCRIPTION}' ${_p_DEFAULT}")
164158
ecbuild_debug("ecbuild_add_option(${_p_FEATURE}): ENABLE_${_p_FEATURE}=${ENABLE_${_p_FEATURE}}")
@@ -176,6 +170,26 @@ macro( ecbuild_add_option )
176170
set( ENABLE_${_p_FEATURE} ${${PNAME}_ENABLE_${_p_FEATURE}} )
177171
endif()
178172

173+
## Update the description of the feature summary
174+
# Choose the correct tick
175+
if (ENABLE_${_p_FEATURE})
176+
set ( _tick "✔")
177+
else()
178+
set ( _tick "✘")
179+
endif()
180+
set(_enabled "${ENABLE_${_p_FEATURE}}")
181+
get_property( _enabled_features GLOBAL PROPERTY ENABLED_FEATURES )
182+
if( "${_p_FEATURE}" IN_LIST _enabled_features )
183+
set(_enabled ON)
184+
endif()
185+
# Retrieve any existing description (n.b. occurs when the same feature is added at multiple projects)
186+
get_property( _feature_desc GLOBAL PROPERTY _CMAKE_${_p_FEATURE}_DESCRIPTION )
187+
# Append the new description
188+
if( _feature_desc )
189+
add_feature_info( ${_p_FEATURE} ${_enabled} "${_feature_desc}, ${PROJECT_NAME}(${_tick}): '${_p_DESCRIPTION}'" )
190+
else()
191+
add_feature_info( ${_p_FEATURE} ${_enabled} "${PROJECT_NAME}(${_tick}): '${_p_DESCRIPTION}'" )
192+
endif()
179193

180194
set( ${PROJECT_NAME}_HAVE_${_p_FEATURE} 0 )
181195

@@ -250,7 +264,7 @@ macro( ecbuild_add_option )
250264

251265
else() # if user provided input and we cannot satisfy FAIL otherwise WARN
252266

253-
ecbuild_disable_feature( ${_p_FEATURE} )
267+
ecbuild_disable_unused_feature( ${_p_FEATURE} )
254268

255269
if( ${_p_FEATURE}_user_provided_input )
256270
if( NOT _${_p_FEATURE}_condition )
@@ -267,16 +281,16 @@ macro( ecbuild_add_option )
267281
ecbuild_info( "Feature ${_p_FEATURE} was not enabled (also not requested) -- following required packages weren't found: ${_failed_to_find_packages}" )
268282
endif()
269283
set( ENABLE_${_p_FEATURE} OFF )
270-
ecbuild_disable_feature( ${_p_FEATURE} )
284+
ecbuild_disable_unused_feature( ${_p_FEATURE} )
271285
endif()
272286

273287
endif()
274288

275289
else()
276290

277-
ecbuild_debug("ecbuild_add_option(${_p_FEATURE}): feature disabled")
291+
ecbuild_info( "Feature ${_p_FEATURE} disabled" )
278292
set( ${PROJECT_NAME}_HAVE_${_p_FEATURE} 0 )
279-
ecbuild_disable_feature( ${_p_FEATURE} )
293+
ecbuild_disable_unused_feature( ${_p_FEATURE} )
280294

281295
endif()
282296

cmake/ecbuild_features.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,11 @@ function( ecbuild_disable_feature _name )
5555
set_property(GLOBAL PROPERTY DISABLED_FEATURES "${_disabled_features}" )
5656

5757
endfunction()
58+
59+
# Disable the feature ${_name} globally (if it has not been enabled in any subproject)
60+
function( ecbuild_disable_unused_feature _name )
61+
get_property( _enabled GLOBAL PROPERTY ENABLED_FEATURES )
62+
if ( NOT _name IN_LIST _enabled ) # if not already disabled
63+
ecbuild_disable_feature( ${_name} )
64+
endif()
65+
endfunction()

0 commit comments

Comments
 (0)