1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2 file Copyright.txt or https://cmake.org/licensing#kwsys for details. */ 3 /* 4 Macros to define main() in a cross-platform way. 5 6 Usage: 7 8 int KWSYS_PLATFORM_TEST_C_MAIN() 9 { 10 return 0; 11 } 12 13 int KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv) 14 { 15 (void)argc; (void)argv; 16 return 0; 17 } 18 */ 19 #if defined(__CLASSIC_C__) 20 # define KWSYS_PLATFORM_TEST_C_MAIN() main() 21 # define KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv) \ 22 main(argc, argv) int argc; \ 23 char* argv[]; 24 #else 25 # define KWSYS_PLATFORM_TEST_C_MAIN() main(void) 26 # define KWSYS_PLATFORM_TEST_C_MAIN_ARGS(argc, argv) \ 27 main(int argc, char* argv[]) 28 #endif 29 30 #ifdef TEST_KWSYS_C_HAS_PTRDIFF_T 31 # include <stddef.h> f(ptrdiff_t n)32int f(ptrdiff_t n) 33 { 34 return n > 0; 35 } KWSYS_PLATFORM_TEST_C_MAIN()36int KWSYS_PLATFORM_TEST_C_MAIN() 37 { 38 char* p = 0; 39 ptrdiff_t d = p - p; 40 (void)d; 41 return f(p - p); 42 } 43 #endif 44 45 #ifdef TEST_KWSYS_C_HAS_SSIZE_T 46 # include <unistd.h> f(ssize_t n)47int f(ssize_t n) 48 { 49 return (int)n; 50 } KWSYS_PLATFORM_TEST_C_MAIN()51int KWSYS_PLATFORM_TEST_C_MAIN() 52 { 53 ssize_t n = 0; 54 return f(n); 55 } 56 #endif 57 58 #ifdef TEST_KWSYS_C_HAS_CLOCK_GETTIME_MONOTONIC 59 # if defined(__APPLE__) 60 # include <AvailabilityMacros.h> 61 # if MAC_OS_X_VERSION_MIN_REQUIRED < 101200 62 # error "clock_gettime not available on macOS < 10.12" 63 # endif 64 # endif 65 # include <time.h> KWSYS_PLATFORM_TEST_C_MAIN()66int KWSYS_PLATFORM_TEST_C_MAIN() 67 { 68 struct timespec ts; 69 return clock_gettime(CLOCK_MONOTONIC, &ts); 70 } 71 #endif 72