macros.cmake 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #
  23. # Copyright (c) 2008-2017 the Urho3D project.
  24. #
  25. # Permission is hereby granted, free of charge, to any person obtaining a copy
  26. # of this software and associated documentation files (the "Software"), to deal
  27. # in the Software without restriction, including without limitation the rights
  28. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  29. # copies of the Software, and to permit persons to whom the Software is
  30. # furnished to do so, subject to the following conditions:
  31. #
  32. # The above copyright notice and this permission notice shall be included in
  33. # all copies or substantial portions of the Software.
  34. #
  35. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  36. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  37. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  38. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  39. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  40. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  41. # THE SOFTWARE.
  42. #
  43. macro(SET_OPTION _NAME _DESC)
  44. list(APPEND ALLOPTIONS ${_NAME})
  45. if(${ARGC} EQUAL 3)
  46. set(_DEFLT ${ARGV2})
  47. else()
  48. set(_DEFLT OFF)
  49. endif()
  50. option(${_NAME} ${_DESC} ${_DEFLT})
  51. endmacro()
  52. macro(DEP_OPTION _NAME _DESC _DEFLT _DEPTEST _FAILDFLT)
  53. list(APPEND ALLOPTIONS ${_NAME})
  54. cmake_dependent_option(${_NAME} ${_DESC} ${_DEFLT} ${_DEPTEST} ${_FAILDFLT})
  55. endmacro()
  56. macro(OPTION_STRING _NAME _DESC _VALUE)
  57. list(APPEND ALLOPTIONS ${_NAME})
  58. set(${_NAME} ${_VALUE} CACHE STRING "${_DESC}")
  59. set(HAVE_${_NAME} ${_VALUE})
  60. ENDMACRO()
  61. # Message Output
  62. macro(MESSAGE_WARN _TEXT)
  63. message(STATUS "*** WARNING: ${_TEXT}")
  64. endmacro()
  65. macro(MESSAGE_ERROR _TEXT)
  66. message(FATAL_ERROR "*** ERROR: ${_TEXT}")
  67. endmacro()
  68. macro(MESSAGE_BOOL_OPTION _NAME _VALUE)
  69. # Urho3D - accept extra paddding argument
  70. if (NOT ${ARGN} STREQUAL \t)
  71. set(_PAD ${ARGN})
  72. else ()
  73. set(_PAD \t)
  74. endif ()
  75. if(${_VALUE})
  76. message(STATUS " ${_NAME}:${_PAD}ON")
  77. else()
  78. message(STATUS " ${_NAME}:${_PAD}OFF")
  79. endif()
  80. endmacro()
  81. macro(MESSAGE_TESTED_OPTION _NAME)
  82. set(_REQVALUE ${${_NAME}})
  83. set(_PAD " ")
  84. if(${ARGC} EQUAL 2)
  85. set(_PAD ${ARGV1})
  86. endif()
  87. if(NOT HAVE_${_NAME})
  88. set(HAVE_${_NAME} OFF)
  89. elseif("${HAVE_${_NAME}}" MATCHES "1|TRUE|YES|Y")
  90. set(HAVE_${_NAME} ON)
  91. endif()
  92. message(STATUS " ${_NAME}${_PAD}(Wanted: ${_REQVALUE}): ${HAVE_${_NAME}}")
  93. endmacro()
  94. macro(LISTTOSTR _LIST _OUTPUT)
  95. if(${ARGC} EQUAL 3)
  96. # prefix for each element
  97. set(_LPREFIX ${ARGV2})
  98. else()
  99. set(_LPREFIX "")
  100. endif()
  101. # Do not use string(REPLACE ";" " ") here to avoid messing up list
  102. # entries
  103. foreach(_ITEM ${${_LIST}})
  104. set(${_OUTPUT} "${_LPREFIX}${_ITEM} ${${_OUTPUT}}")
  105. endforeach()
  106. endmacro()
  107. macro(CHECK_OBJC_SOURCE_COMPILES SOURCE VAR)
  108. set(PREV_REQUIRED_DEFS "${CMAKE_REQUIRED_DEFINITIONS}")
  109. set(CMAKE_REQUIRED_DEFINITIONS "-x objective-c ${PREV_REQUIRED_DEFS}")
  110. CHECK_C_SOURCE_COMPILES(${SOURCE} ${VAR})
  111. set(CMAKE_REQUIRED_DEFINITIONS "${PREV_REQUIRED_DEFS}")
  112. endmacro()