kwsysPlatformTestsC.c 2.24 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing#kwsys for details.  */
3 4 5 6
/*
  Macros to define main() in a cross-platform way.

  Usage:
7 8 9 10 11 12 13 14 15 16 17 18 19

    int KWSYS_PLATFORM_TEST_C_MAIN()
    {
      return 0;
    }

    int KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv)
    {
      (void)argc; (void)argv;
      return 0;
    }
*/
#if defined(__CLASSIC_C__)
20 21 22 23
#define KWSYS_PLATFORM_TEST_C_MAIN() main()
#define KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv)                           \
  main(argc, argv) int argc;                                                  \
  char* argv[];
24
#else
25 26
#define KWSYS_PLATFORM_TEST_C_MAIN() main(void)
#define KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv)                           \
27 28
  main(int argc, char* argv[])
#endif
29 30 31

#ifdef TEST_KWSYS_C_HAS_PTRDIFF_T
#include <stddef.h>
32 33 34 35
int f(ptrdiff_t n)
{
  return n > 0;
}
36 37 38 39 40 41 42 43 44 45 46
int KWSYS_PLATFORM_TEST_C_MAIN()
{
  char* p = 0;
  ptrdiff_t d = p - p;
  (void)d;
  return f(p - p);
}
#endif

#ifdef TEST_KWSYS_C_HAS_SSIZE_T
#include <unistd.h>
47 48 49 50
int f(ssize_t n)
{
  return (int)n;
}
51 52 53 54 55 56
int KWSYS_PLATFORM_TEST_C_MAIN()
{
  ssize_t n = 0;
  return f(n);
}
#endif
57

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
#ifdef TEST_KWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC
#if defined(__APPLE__)
#include <AvailabilityMacros.h>
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101200
#error "clock_gettime not available on macOS < 10.12"
#endif
#endif
#include <time.h>
int KWSYS_PLATFORM_TEST_C_MAIN()
{
  struct timespec ts;
  return clock_gettime(CLOCK_MONOTONIC, &ts);
}
#endif

73 74 75
#ifdef TEST_KWSYS_C_TYPE_MACROS
char* info_macros =
#if defined(__SIZEOF_SHORT__)
76
  "INFO:macro[__SIZEOF_SHORT__]\n"
77 78
#endif
#if defined(__SIZEOF_INT__)
79
  "INFO:macro[__SIZEOF_INT__]\n"
80 81
#endif
#if defined(__SIZEOF_LONG__)
82
  "INFO:macro[__SIZEOF_LONG__]\n"
83 84
#endif
#if defined(__SIZEOF_LONG_LONG__)
85
  "INFO:macro[__SIZEOF_LONG_LONG__]\n"
86 87
#endif
#if defined(__SHORT_MAX__)
88
  "INFO:macro[__SHORT_MAX__]\n"
89 90
#endif
#if defined(__INT_MAX__)
91
  "INFO:macro[__INT_MAX__]\n"
92 93
#endif
#if defined(__LONG_MAX__)
94
  "INFO:macro[__LONG_MAX__]\n"
95 96
#endif
#if defined(__LONG_LONG_MAX__)
97
  "INFO:macro[__LONG_LONG_MAX__]\n"
98 99 100 101 102 103 104 105 106 107 108
#endif
  "";

int KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv)
{
  int require = 0;
  require += info_macros[argc];
  (void)argv;
  return require;
}
#endif