ctkMacroOptionUtils.cmake 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. function(ctk_option_logical_expression_to_message varname logical_expr)
  2. set(enabling_msg)
  3. foreach(arg ${logical_expr})
  4. if(NOT "${${arg}}" STREQUAL "")
  5. set(value_as_int 0)
  6. if(${${arg}})
  7. set(value_as_int 1)
  8. endif()
  9. set(enabling_msg "${enabling_msg} ${arg}:${value_as_int}")
  10. else()
  11. set(enabling_msg "${enabling_msg} ${arg}")
  12. endif()
  13. endforeach()
  14. set(${varname} ${enabling_msg} PARENT_SCOPE)
  15. endfunction()
  16. macro(ctk_option option_prefix name doc default)
  17. option(${option_prefix}_${name} ${doc} ${default})
  18. mark_as_advanced(${option_prefix}_${name})
  19. list(APPEND ${option_prefix}S ${name})
  20. set(_logical_expr ${ARGN})
  21. if(_logical_expr AND NOT ${option_prefix}_${name})
  22. if(${ARGN})
  23. # Force the option to ON. This is okay since the
  24. # logical expression should contain a CTK_ENABLE_*
  25. # option value, which requires the current option to be ON.
  26. get_property(_doc_string CACHE ${option_prefix}_${name} PROPERTY HELPSTRING)
  27. set(${option_prefix}_${name} ON CACHE BOOL ${_doc_string} FORCE)
  28. # Generate user-friendly message
  29. set(enabling_msg)
  30. ctk_option_logical_expression_to_message(enabling_msg "${ARGN}")
  31. message(STATUS "Enabling [${option_prefix}_${name}] because of [${enabling_msg}] evaluates to True")
  32. endif()
  33. endif()
  34. endmacro()
  35. macro(ctk_lib_option name doc default)
  36. ctk_option(CTK_LIB ${name} ${doc} ${default} ${ARGN})
  37. if(CTK_BUILD_ALL_LIBRARIES)
  38. set(CTK_LIB_${name} 1)
  39. endif()
  40. endmacro()
  41. macro(ctk_plugin_option name doc default)
  42. ctk_option(CTK_PLUGIN ${name} ${doc} ${default} ${ARGN})
  43. if(CTK_BUILD_ALL_PLUGINS)
  44. set(CTK_PLUGIN_${name} 1)
  45. endif()
  46. endmacro()
  47. macro(ctk_app_option name doc default)
  48. ctk_option(CTK_APP ${name} ${doc} ${default} ${ARGN})
  49. if(CTK_BUILD_ALL_APPS)
  50. set(CTK_APP_${name} 1)
  51. endif()
  52. endmacro()
  53. macro(ctk_enable_option_raw name doc default)
  54. option(${name} "${doc}" ${default})
  55. if(DEFINED ${name}_internal)
  56. if(${${name}} AND ${${name}_internal})
  57. if(NOT (${ARGN}))
  58. get_property(_doc_string CACHE ${name} PROPERTY HELPSTRING)
  59. set(${name} OFF CACHE BOOL ${_doc_string} FORCE)
  60. message("Full support for [${name}] disabled")
  61. endif()
  62. endif()
  63. endif()
  64. set(${name}_internal ${${name}} CACHE INTERNAL "" FORCE)
  65. endmacro()
  66. macro(ctk_enable_option name doc default)
  67. ctk_enable_option_raw(CTK_ENABLE_${name} ${doc} ${default} ${ARGN})
  68. endmacro()