File: TriStateOption.cmake

package info (click to toggle)
seastar 25.05.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 7,256 kB
  • sloc: cpp: 89,250; python: 5,066; ansic: 3,452; sh: 1,272; xml: 177; makefile: 9
file content (38 lines) | stat: -rw-r--r-- 1,285 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# the "option()" defined by CMake represents a boolean. but somtimes, we want
# to enable/disable it depending on the CMAKE_BUILD_TYPE, if user leaves the
# option unset.
function (tri_state_option option)
  cmake_parse_arguments (
    parsed_args
    ""
    "CONDITION"
    "DEFAULT_BUILD_TYPES"
    ${ARGN})

  get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  if (is_multi_config)
    set (all_build_types ${CMAKE_CONFIGURATION_TYPES})
  else ()
    set (all_build_types ${CMAKE_BUILD_TYPE})
  endif ()

  # generic boolean values passed as string, potentially from configure.py
  set (True_STRING_VALUES "ON" "yes" "Yes" "YES" "true" "True" "TRUE")
  set (Default_STRING_VALUES "DEFAULT" "default" "Default")

  if ("${option}" IN_LIST True_STRING_VALUES)
    set (enabled_types ${all_build_types})
  elseif ("${option}" IN_LIST Default_STRING_VALUES)
    set (enabled_types ${parsed_args_DEFAULT_BUILD_TYPES})
  else ()
    set (enabled_types "")
  endif ()

  if (is_multi_config)
    set (${parsed_args_CONDITION} "$<IN_LIST:$<CONFIG>,${enabled_types}>" PARENT_SCOPE)
  elseif (CMAKE_BUILD_TYPE IN_LIST enabled_types)
    set (${parsed_args_CONDITION} 1 PARENT_SCOPE)
  else ()
    set (${parsed_args_CONDITION} 0 PARENT_SCOPE)
  endif ()
endfunction ()