Mirror of Awesome WM window manager
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AutoOption.cmake 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Add a new option with default value "auto":
  2. # autoOption(FOOBAR "Support foobar")
  3. #
  4. # To check if FOOBAR support should be enabled, use:
  5. # if(FOOBAR)
  6. #
  7. # If necessary dependencies for FOOBAR are missing, use:
  8. # autoDisable(FOOBAR "Did not find baz")
  9. #
  10. # Example:
  11. # autoOption(FOOBAR "Support foobar")
  12. # if(FOOBAR)
  13. # Check for FOOBAR here.
  14. # if(NOT BAZ_FOUND)
  15. # autoDisable(FOOBAR "Did not find baz")
  16. # endif()
  17. # endif()
  18. function(autoOption name description)
  19. set(${name} AUTO CACHE STRING "${description}")
  20. set_property(CACHE ${name} PROPERTY STRINGS AUTO ON OFF)
  21. if((NOT ${name} STREQUAL ON) AND
  22. (NOT ${name} STREQUAL OFF) AND
  23. (NOT ${name} STREQUAL AUTO))
  24. message(FATAL_ERROR "Value of ${name} must be one of ON/OFF/AUTO, but is ${${name}}")
  25. endif()
  26. endfunction()
  27. function(autoDisable name reason)
  28. message(STATUS "${reason}")
  29. if(${name} STREQUAL AUTO)
  30. message(STATUS "Disabled.")
  31. SET(${name} OFF PARENT_SCOPE)
  32. elseif(${name} STREQUAL ON)
  33. message(SEND_ERROR "Aborting because ${name} was set to ON.")
  34. else()
  35. message(AUTHOR_WARNING "Unexpected value for ${name}: ${${name}}.")
  36. endif()
  37. endfunction()
  38. # vim: filetype=cmake:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80:foldmethod=marker