cmake_modules/CheckTypeSize.cmake
author alfadur <mail@none>
Sat, 11 Jan 2020 00:44:25 +0300
changeset 15540 479911540e17
parent 11658 f87ed83568c8
permissions -rw-r--r--
backout a798e6441a36
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11658
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
     1
#.rst:
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
     2
# CheckTypeSize
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
     3
# -------------
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
     4
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
     5
# Check sizeof a type
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
     6
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
     7
# ::
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
     8
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
     9
#   CHECK_TYPE_SIZE(TYPE VARIABLE [BUILTIN_TYPES_ONLY]
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    10
#                                 [LANGUAGE <language>])
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    11
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    12
# Check if the type exists and determine its size.  On return,
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    13
# "HAVE_${VARIABLE}" holds the existence of the type, and "${VARIABLE}"
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    14
# holds one of the following:
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    15
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    16
# ::
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    17
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    18
#    <size> = type has non-zero size <size>
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    19
#    "0"    = type has arch-dependent size (see below)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    20
#    ""     = type does not exist
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    21
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    22
# Both ``HAVE_${VARIABLE}`` and ``${VARIABLE}`` will be created as internal
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    23
# cache variables.
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    24
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    25
# Furthermore, the variable "${VARIABLE}_CODE" holds C preprocessor code
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    26
# to define the macro "${VARIABLE}" to the size of the type, or leave
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    27
# the macro undefined if the type does not exist.
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    28
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    29
# The variable "${VARIABLE}" may be "0" when CMAKE_OSX_ARCHITECTURES has
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    30
# multiple architectures for building OS X universal binaries.  This
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    31
# indicates that the type size varies across architectures.  In this
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    32
# case "${VARIABLE}_CODE" contains C preprocessor tests mapping from
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    33
# each architecture macro to the corresponding type size.  The list of
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    34
# architecture macros is stored in "${VARIABLE}_KEYS", and the value for
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    35
# each key is stored in "${VARIABLE}-${KEY}".
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    36
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    37
# If the BUILTIN_TYPES_ONLY option is not given, the macro checks for
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    38
# headers <sys/types.h>, <stdint.h>, and <stddef.h>, and saves results
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    39
# in HAVE_SYS_TYPES_H, HAVE_STDINT_H, and HAVE_STDDEF_H.  The type size
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    40
# check automatically includes the available headers, thus supporting
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    41
# checks of types defined in the headers.
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    42
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    43
# If LANGUAGE is set, the specified compiler will be used to perform the
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    44
# check. Acceptable values are C and CXX
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    45
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    46
# Despite the name of the macro you may use it to check the size of more
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    47
# complex expressions, too.  To check e.g.  for the size of a struct
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    48
# member you can do something like this:
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    49
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    50
# ::
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    51
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    52
#   check_type_size("((struct something*)0)->member" SIZEOF_MEMBER)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    53
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    54
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    55
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    56
# The following variables may be set before calling this macro to modify
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    57
# the way the check is run:
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    58
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    59
# ::
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    60
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    61
#   CMAKE_REQUIRED_FLAGS = string of compile command line flags
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    62
#   CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    63
#   CMAKE_REQUIRED_INCLUDES = list of include directories
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    64
#   CMAKE_REQUIRED_LIBRARIES = list of libraries to link
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    65
#   CMAKE_REQUIRED_QUIET = execute quietly without messages
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    66
#   CMAKE_EXTRA_INCLUDE_FILES = list of extra headers to include
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    67
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    68
#=============================================================================
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    69
# Copyright 2002-2009 Kitware, Inc.
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    70
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    71
# Distributed under the OSI-approved BSD License (the "License");
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    72
# see accompanying file Copyright.txt for details.
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    73
#
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    74
# This software is distributed WITHOUT ANY WARRANTY; without even the
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    75
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    76
# See the License for more information.
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    77
#=============================================================================
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    78
# (To distribute this file outside of CMake, substitute the full
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    79
#  License text for the above reference.)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    80
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    81
include(CheckIncludeFile)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    82
include(CheckIncludeFileCXX)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    83
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    84
cmake_policy(PUSH)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    85
cmake_policy(VERSION 3.0)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    86
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    87
get_filename_component(__check_type_size_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    88
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    89
#-----------------------------------------------------------------------------
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    90
# Helper function.  DO NOT CALL DIRECTLY.
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    91
function(__check_type_size_impl type var map builtin language)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    92
  if(NOT CMAKE_REQUIRED_QUIET)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    93
    message(STATUS "Check size of ${type}")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    94
  endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    95
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    96
  # Include header files.
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    97
  set(headers)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    98
  if(builtin)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
    99
    if(HAVE_SYS_TYPES_H)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   100
      set(headers "${headers}#include <sys/types.h>\n")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   101
    endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   102
    if(HAVE_STDINT_H)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   103
      set(headers "${headers}#include <stdint.h>\n")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   104
    endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   105
    if(HAVE_STDDEF_H)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   106
      set(headers "${headers}#include <stddef.h>\n")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   107
    endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   108
  endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   109
  foreach(h ${CMAKE_EXTRA_INCLUDE_FILES})
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   110
    set(headers "${headers}#include \"${h}\"\n")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   111
  endforeach()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   112
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   113
  # Perform the check.
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   114
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   115
  if("${language}" STREQUAL "C")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   116
    set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.c)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   117
  elseif("${language}" STREQUAL "CXX")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   118
    set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.cpp)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   119
  else()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   120
    message(FATAL_ERROR "Unknown language:\n  ${language}\nSupported languages: C, CXX.\n")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   121
  endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   122
  set(bin ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${var}.bin)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   123
  configure_file(${__check_type_size_dir}/CheckTypeSize.c.in ${src} @ONLY)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   124
  try_run(${var}_run_result HAVE_${var} ${CMAKE_BINARY_DIR} ${src}
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   125
    COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   126
    LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   127
    CMAKE_FLAGS
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   128
      "-DCOMPILE_DEFINITIONS:STRING=${CMAKE_REQUIRED_FLAGS}"
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   129
      "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}"
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   130
    RUN_OUTPUT_VARIABLE ${var}_run_output
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   131
    COMPILE_OUTPUT_VARIABLE output
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   132
    )
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   133
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   134
  if(${HAVE_${var}} AND NOT "${${var}_run_result}" STREQUAL "FAILED_TO_RUN")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   135
    set(${var} ${${var}_run_result})
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   136
    if(NOT CMAKE_REQUIRED_QUIET)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   137
      message(STATUS "Check size of ${type} - done")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   138
    endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   139
    file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   140
      "Determining size of ${type} passed with the following output:\n${output}\n\n")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   141
    set(${var} "${${var}}" CACHE INTERNAL "CHECK_TYPE_SIZE: sizeof(${type})")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   142
  else()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   143
    # The check failed to compile.
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   144
    if(NOT CMAKE_REQUIRED_QUIET)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   145
      message(STATUS "Check size of ${type} - failed")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   146
    endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   147
    file(READ ${src} content)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   148
    file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   149
      "Determining size of ${type} failed with the following output:\n${output}\n${src}:\n${content}\n\n")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   150
    set(${var} "" CACHE INTERNAL "CHECK_TYPE_SIZE: ${type} unknown")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   151
    file(REMOVE ${map})
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   152
  endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   153
endfunction()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   154
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   155
#-----------------------------------------------------------------------------
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   156
macro(CHECK_TYPE_SIZE TYPE VARIABLE)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   157
  # parse arguments
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   158
  unset(doing)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   159
  foreach(arg ${ARGN})
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   160
    if("x${arg}" STREQUAL "xBUILTIN_TYPES_ONLY")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   161
      set(_CHECK_TYPE_SIZE_${arg} 1)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   162
      unset(doing)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   163
    elseif("x${arg}" STREQUAL "xLANGUAGE") # change to MATCHES for more keys
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   164
      set(doing "${arg}")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   165
      set(_CHECK_TYPE_SIZE_${doing} "")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   166
    elseif("x${doing}" STREQUAL "xLANGUAGE")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   167
      set(_CHECK_TYPE_SIZE_${doing} "${arg}")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   168
      unset(doing)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   169
    else()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   170
      message(FATAL_ERROR "Unknown argument:\n  ${arg}\n")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   171
    endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   172
  endforeach()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   173
  if("x${doing}" MATCHES "^x(LANGUAGE)$")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   174
    message(FATAL_ERROR "Missing argument:\n  ${doing} arguments requires a value\n")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   175
  endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   176
  if(DEFINED _CHECK_TYPE_SIZE_LANGUAGE)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   177
    if(NOT "x${_CHECK_TYPE_SIZE_LANGUAGE}" MATCHES "^x(C|CXX)$")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   178
      message(FATAL_ERROR "Unknown language:\n  ${_CHECK_TYPE_SIZE_LANGUAGE}.\nSupported languages: C, CXX.\n")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   179
    endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   180
    set(_language ${_CHECK_TYPE_SIZE_LANGUAGE})
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   181
  else()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   182
    set(_language C)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   183
  endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   184
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   185
  # Optionally check for standard headers.
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   186
  if(_CHECK_TYPE_SIZE_BUILTIN_TYPES_ONLY)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   187
    set(_builtin 0)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   188
  else()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   189
    set(_builtin 1)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   190
    if("${_language}" STREQUAL "C")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   191
      check_include_file(sys/types.h HAVE_SYS_TYPES_H)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   192
      check_include_file(stdint.h HAVE_STDINT_H)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   193
      check_include_file(stddef.h HAVE_STDDEF_H)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   194
    elseif("${_language}" STREQUAL "CXX")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   195
      check_include_file_cxx(sys/types.h HAVE_SYS_TYPES_H)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   196
      check_include_file_cxx(stdint.h HAVE_STDINT_H)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   197
      check_include_file_cxx(stddef.h HAVE_STDDEF_H)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   198
    endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   199
  endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   200
  unset(_CHECK_TYPE_SIZE_BUILTIN_TYPES_ONLY)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   201
  unset(_CHECK_TYPE_SIZE_LANGUAGE)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   202
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   203
  # Compute or load the size or size map.
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   204
  set(${VARIABLE}_KEYS)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   205
  set(_map_file ${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CheckTypeSize/${VARIABLE}.cmake)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   206
  if(NOT DEFINED HAVE_${VARIABLE})
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   207
    __check_type_size_impl(${TYPE} ${VARIABLE} ${_map_file} ${_builtin} ${_language})
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   208
  endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   209
  include(${_map_file} OPTIONAL)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   210
  set(_map_file)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   211
  set(_builtin)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   212
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   213
  # Create preprocessor code.
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   214
  if(${VARIABLE}_KEYS)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   215
    set(${VARIABLE}_CODE)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   216
    set(_if if)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   217
    foreach(key ${${VARIABLE}_KEYS})
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   218
      set(${VARIABLE}_CODE "${${VARIABLE}_CODE}#${_if} defined(${key})\n# define ${VARIABLE} ${${VARIABLE}-${key}}\n")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   219
      set(_if elif)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   220
    endforeach()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   221
    set(${VARIABLE}_CODE "${${VARIABLE}_CODE}#else\n# error ${VARIABLE} unknown\n#endif")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   222
    set(_if)
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   223
  elseif(${VARIABLE})
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   224
    set(${VARIABLE}_CODE "#define ${VARIABLE} ${${VARIABLE}}")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   225
  else()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   226
    set(${VARIABLE}_CODE "/* #undef ${VARIABLE} */")
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   227
  endif()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   228
endmacro()
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   229
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   230
#-----------------------------------------------------------------------------
f87ed83568c8 Import the Emscripted toolchain configuration
koda
parents:
diff changeset
   231
cmake_policy(POP)