cmake/macros.cmake
author Sam Lantinga <slouken@libsdl.org>
Sat, 12 Jan 2019 12:18:44 -0800
changeset 12534 682d9b5ecbed
parent 9465 bf1da29c9509
permissions -rw-r--r--
Initial Android OpenSL ES implementation, contributed by ANTA
gabomdq@6674
     1
macro(SET_OPTION _NAME _DESC)
gabomdq@6674
     2
  list(APPEND ALLOPTIONS ${_NAME})
gabomdq@6674
     3
  if(${ARGC} EQUAL 3)
gabomdq@6674
     4
    set(_DEFLT ${ARGV2})
gabomdq@6674
     5
  else()
gabomdq@6674
     6
    set(_DEFLT OFF)
gabomdq@6674
     7
  endif()
gabomdq@6674
     8
  option(${_NAME} ${_DESC} ${_DEFLT})
gabomdq@6674
     9
endmacro()
gabomdq@6674
    10
gabomdq@6674
    11
macro(DEP_OPTION _NAME _DESC _DEFLT _DEPTEST _FAILDFLT)
gabomdq@6674
    12
  list(APPEND ALLOPTIONS ${_NAME})
gabomdq@6674
    13
  cmake_dependent_option(${_NAME} ${_DESC} ${_DEFLT} ${_DEPTEST} ${_FAILDFLT})
gabomdq@6674
    14
endmacro()
gabomdq@6674
    15
gabomdq@6674
    16
macro(OPTION_STRING _NAME _DESC _VALUE)
gabomdq@6674
    17
  list(APPEND ALLOPTIONS ${_NAME})
gabomdq@6674
    18
  set(${_NAME} ${_VALUE} CACHE STRING "${_DESC}")
gabomdq@6674
    19
  set(HAVE_${_NAME} ${_VALUE})
gabomdq@6674
    20
ENDMACRO()
gabomdq@6674
    21
gabomdq@6674
    22
# Message Output
gabomdq@6674
    23
macro(MESSAGE_WARN _TEXT)
gabomdq@6674
    24
  message(STATUS "*** WARNING: ${_TEXT}")
gabomdq@6674
    25
endmacro()
gabomdq@6674
    26
gabomdq@6674
    27
macro(MESSAGE_ERROR _TEXT)
gabomdq@6674
    28
  message(FATAL_ERROR "*** ERROR: ${_TEXT}")
gabomdq@6674
    29
endmacro()
gabomdq@6674
    30
gabomdq@6674
    31
macro(MESSAGE_BOOL_OPTION _NAME _VALUE)
gabomdq@6674
    32
  if(${_VALUE})
gabomdq@6674
    33
    message(STATUS "  ${_NAME}:\tON")
gabomdq@6674
    34
  else()
gabomdq@6674
    35
    message(STATUS "  ${_NAME}:\tOFF")
gabomdq@6674
    36
  endif()
gabomdq@6674
    37
endmacro()
gabomdq@6674
    38
gabomdq@6674
    39
macro(MESSAGE_TESTED_OPTION _NAME)
gabomdq@6674
    40
  set(_REQVALUE ${${_NAME}})
gabomdq@6674
    41
  set(_PAD " ")
gabomdq@6674
    42
  if(${ARGC} EQUAL 2)
gabomdq@6674
    43
    set(_PAD ${ARGV1})
gabomdq@6674
    44
  endif()
gabomdq@6674
    45
  if(NOT HAVE_${_NAME})
gabomdq@6674
    46
    set(HAVE_${_NAME} OFF)
gabomdq@6674
    47
  elseif("${HAVE_${_NAME}}" MATCHES "1|TRUE|YES|Y")
gabomdq@6674
    48
    set(HAVE_${_NAME} ON)
gabomdq@6674
    49
  endif()
gabomdq@6674
    50
  message(STATUS "  ${_NAME}${_PAD}(Wanted: ${_REQVALUE}): ${HAVE_${_NAME}}")
gabomdq@6674
    51
endmacro()
gabomdq@6674
    52
gabomdq@6674
    53
macro(LISTTOSTR _LIST _OUTPUT)
gabomdq@6674
    54
  if(${ARGC} EQUAL 3)
gabomdq@6674
    55
    # prefix for each element
gabomdq@6674
    56
    set(_LPREFIX ${ARGV2})
gabomdq@6674
    57
  else()
gabomdq@6674
    58
    set(_LPREFIX "")
gabomdq@6674
    59
  endif()
gabomdq@6674
    60
  # Do not use string(REPLACE ";" " ") here to avoid messing up list
gabomdq@6674
    61
  # entries
gabomdq@6674
    62
  foreach(_ITEM ${${_LIST}})
gabomdq@6674
    63
    set(${_OUTPUT} "${_LPREFIX}${_ITEM} ${${_OUTPUT}}")
gabomdq@6674
    64
  endforeach()
gabomdq@6674
    65
endmacro()
slouken@7182
    66
slouken@7182
    67
macro(CHECK_OBJC_SOURCE_COMPILES SOURCE VAR)
slouken@7182
    68
  set(PREV_REQUIRED_DEFS "${CMAKE_REQUIRED_DEFINITIONS}")
icculus@9465
    69
  set(CMAKE_REQUIRED_DEFINITIONS "-x objective-c ${PREV_REQUIRED_DEFS}")
slouken@7182
    70
  CHECK_C_SOURCE_COMPILES(${SOURCE} ${VAR})
slouken@7182
    71
  set(CMAKE_REQUIRED_DEFINITIONS "${PREV_REQUIRED_DEFS}")
slouken@7182
    72
endmacro()
slouken@7182
    73