FindFeature.cmake 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # types: DISABLED < RUNTIME < OPTIONAL < RECOMMENDED < REQUIRED
  2. macro(find_feature _feature _type _purpose _description)
  3. string(TOUPPER ${_feature} _feature_upper)
  4. string(TOLOWER ${_type} _type_lower)
  5. if(${_type} STREQUAL "DISABLED")
  6. set(_feature_default "OFF")
  7. message(STATUS "Skipping ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
  8. else()
  9. if(${_type} STREQUAL "REQUIRED")
  10. set(_feature_default "ON")
  11. message(STATUS "Finding ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
  12. find_package(${_feature} REQUIRED)
  13. elseif(${_type} STREQUAL "RECOMMENDED")
  14. if(NOT ${WITH_${_feature_upper}})
  15. set(_feature_default "OFF")
  16. message(STATUS "Skipping ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
  17. else()
  18. set(_feature_default "ON")
  19. message(STATUS "Finding ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
  20. message(STATUS " Disable feature ${_feature} using \"-DWITH_${_feature_upper}=OFF\"")
  21. find_package(${_feature})
  22. endif()
  23. elseif(${_type} STREQUAL "OPTIONAL")
  24. if(${WITH_${_feature_upper}})
  25. set(_feature_default "ON")
  26. message(STATUS "Finding ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
  27. find_package(${_feature} REQUIRED)
  28. else()
  29. set(_feature_default "OFF")
  30. message(STATUS "Skipping ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
  31. message(STATUS " Enable feature ${_feature} using \"-DWITH_${_feature_upper}=ON\"")
  32. endif()
  33. else()
  34. set(_feature_default "ON")
  35. message(STATUS "Finding ${_type_lower} feature ${_feature} for ${_purpose} (${_description})")
  36. find_package(${_feature})
  37. endif()
  38. if(NOT ${${_feature_upper}_FOUND})
  39. if(${_feature_default})
  40. message(WARNING " feature ${_feature} was requested but could not be found! ${_feature_default} / ${${_feature_upper}_FOUND}")
  41. endif()
  42. set(_feature_default "OFF")
  43. endif()
  44. option(WITH_${_feature_upper} "Enable feature ${_feature} for ${_purpose}" ${_feature_default})
  45. set_package_properties(${_feature} PROPERTIES
  46. TYPE ${_type}
  47. PURPOSE "${_purpose}"
  48. DESCRIPTION "${_description}")
  49. endif()
  50. endmacro(find_feature)