macros.cmake 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #
  2. # Simple DirectMedia Layer
  3. # Copyright (C) 1997-2016 Sam Lantinga <[email protected]>
  4. #
  5. # This software is provided 'as-is', without any express or implied
  6. # warranty. In no event will the authors be held liable for any damages
  7. # arising from the use of this software.
  8. #
  9. # Permission is granted to anyone to use this software for any purpose,
  10. # including commercial applications, and to alter it and redistribute it
  11. # freely, subject to the following restrictions:
  12. #
  13. # 1. The origin of this software must not be misrepresented; you must not
  14. # claim that you wrote the original software. If you use this software
  15. # in a product, an acknowledgment in the product documentation would be
  16. # appreciated but is not required.
  17. # 2. Altered source versions must be plainly marked as such, and must not be
  18. # misrepresented as being the original software.
  19. # 3. This notice may not be removed or altered from any source distribution.
  20. #
  21. # Modified by Yao Wei Tjong for Urho3D, the modified portion is licensed under below license
  22. # Copyright (c) 2008-2023 the Urho3D project
  23. # License: MIT
  24. macro(SET_OPTION _NAME _DESC)
  25. list(APPEND ALLOPTIONS ${_NAME})
  26. if(${ARGC} EQUAL 3)
  27. set(_DEFLT ${ARGV2})
  28. else()
  29. set(_DEFLT OFF)
  30. endif()
  31. option(${_NAME} ${_DESC} ${_DEFLT})
  32. endmacro()
  33. macro(DEP_OPTION _NAME _DESC _DEFLT _DEPTEST _FAILDFLT)
  34. list(APPEND ALLOPTIONS ${_NAME})
  35. cmake_dependent_option(${_NAME} ${_DESC} ${_DEFLT} ${_DEPTEST} ${_FAILDFLT})
  36. endmacro()
  37. macro(OPTION_STRING _NAME _DESC _VALUE)
  38. list(APPEND ALLOPTIONS ${_NAME})
  39. set(${_NAME} ${_VALUE} CACHE STRING "${_DESC}")
  40. set(HAVE_${_NAME} ${_VALUE})
  41. ENDMACRO()
  42. # Message Output
  43. macro(MESSAGE_WARN _TEXT)
  44. message(STATUS "*** WARNING: ${_TEXT}")
  45. endmacro()
  46. macro(MESSAGE_ERROR _TEXT)
  47. message(FATAL_ERROR "*** ERROR: ${_TEXT}")
  48. endmacro()
  49. macro(MESSAGE_BOOL_OPTION _NAME _VALUE)
  50. # Urho3D - accept extra paddding argument
  51. if (NOT ${ARGN} STREQUAL \t)
  52. set(_PAD ${ARGN})
  53. else ()
  54. set(_PAD \t)
  55. endif ()
  56. if(${_VALUE})
  57. message(STATUS " ${_NAME}:${_PAD}ON")
  58. else()
  59. message(STATUS " ${_NAME}:${_PAD}OFF")
  60. endif()
  61. endmacro()
  62. macro(MESSAGE_TESTED_OPTION _NAME)
  63. set(_REQVALUE ${${_NAME}})
  64. set(_PAD " ")
  65. if(${ARGC} EQUAL 2)
  66. set(_PAD ${ARGV1})
  67. endif()
  68. if(NOT HAVE_${_NAME})
  69. set(HAVE_${_NAME} OFF)
  70. elseif("${HAVE_${_NAME}}" MATCHES "1|TRUE|YES|Y")
  71. set(HAVE_${_NAME} ON)
  72. endif()
  73. message(STATUS " ${_NAME}${_PAD}(Wanted: ${_REQVALUE}): ${HAVE_${_NAME}}")
  74. endmacro()
  75. macro(LISTTOSTR _LIST _OUTPUT)
  76. if(${ARGC} EQUAL 3)
  77. # prefix for each element
  78. set(_LPREFIX ${ARGV2})
  79. else()
  80. set(_LPREFIX "")
  81. endif()
  82. # Do not use string(REPLACE ";" " ") here to avoid messing up list
  83. # entries
  84. foreach(_ITEM ${${_LIST}})
  85. set(${_OUTPUT} "${_LPREFIX}${_ITEM} ${${_OUTPUT}}")
  86. endforeach()
  87. endmacro()
  88. macro(CHECK_OBJC_SOURCE_COMPILES SOURCE VAR)
  89. set(PREV_REQUIRED_DEFS "${CMAKE_REQUIRED_DEFINITIONS}")
  90. set(CMAKE_REQUIRED_DEFINITIONS "-x objective-c ${PREV_REQUIRED_DEFS}")
  91. CHECK_C_SOURCE_COMPILES(${SOURCE} ${VAR})
  92. set(CMAKE_REQUIRED_DEFINITIONS "${PREV_REQUIRED_DEFS}")
  93. endmacro()