cmake: Make test code use proper C main functions. Fixes #5021.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1561ca2..9fab172 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -293,7 +293,7 @@ if(CYGWIN)
# We build SDL on cygwin without the UNIX emulation layer
target_include_directories(sdl-build-options INTERFACE "/usr/include/mingw")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mno-cygwin")
- check_c_source_compiles("int main(int argc, char **argv) {}"
+ check_c_source_compiles("int main(int argc, char **argv) { return 0; }"
HAVE_GCC_NO_CYGWIN)
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
if(HAVE_GCC_NO_CYGWIN)
@@ -545,7 +545,7 @@ if(USE_GCC OR USE_CLANG)
#if !defined(__GNUC__) || __GNUC__ < 3
#error Dependency tracking requires GCC 3.0 or newer
#endif
- int main(int argc, char **argv) { }" HAVE_DEPENDENCY_TRACKING)
+ int main(int argc, char **argv) { return 0; }" HAVE_DEPENDENCY_TRACKING)
endif()
if(SDL_GCC_ATOMICS)
@@ -556,17 +556,19 @@ if(USE_GCC OR USE_CLANG)
__sync_lock_test_and_set(&x, y);
__sync_fetch_and_add(&a, 1);
__sync_bool_compare_and_swap(&a, 5, 10);
- __sync_bool_compare_and_swap(&x, y, z); }" HAVE_GCC_ATOMICS)
+ __sync_bool_compare_and_swap(&x, y, z);
+ return 0; }" HAVE_GCC_ATOMICS)
if(NOT HAVE_GCC_ATOMICS)
check_c_source_compiles("int main(int argc, char **argv) {
int a;
__sync_lock_test_and_set(&a, 1);
- __sync_lock_release(&a); }" HAVE_GCC_SYNC_LOCK_TEST_AND_SET)
+ __sync_lock_release(&a);
+ return 0; }" HAVE_GCC_SYNC_LOCK_TEST_AND_SET)
endif()
endif()
set(CMAKE_REQUIRED_FLAGS "-mpreferred-stack-boundary=2")
- check_c_source_compiles("int x = 0; int main(int argc, char **argv) {}"
+ check_c_source_compiles("int x = 0; int main(int argc, char **argv) { return 0; }"
HAVE_GCC_PREFERRED_STACK_BOUNDARY)
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
@@ -575,7 +577,7 @@ if(USE_GCC OR USE_CLANG)
#if !defined(__GNUC__) || __GNUC__ < 4
#error SDL only uses visibility attributes in GCC 4 or newer
#endif
- int main(int argc, char **argv) {}" HAVE_GCC_FVISIBILITY)
+ int main(int argc, char **argv) { return 0; }" HAVE_GCC_FVISIBILITY)
if(HAVE_GCC_FVISIBILITY)
list(APPEND EXTRA_CFLAGS "-fvisibility=hidden")
endif()
@@ -631,7 +633,7 @@ if(SDL_ASSEMBLY)
#ifndef __MMX__
#error Assembler CPP flag not enabled
#endif
- int main(int argc, char **argv) { }" HAVE_MMX)
+ int main(int argc, char **argv) { return 0; }" HAVE_MMX)
if(HAVE_MMX)
list(APPEND EXTRA_CFLAGS "-mmmx")
endif()
@@ -648,6 +650,7 @@ if(SDL_ASSEMBLY)
int main(int argc, char **argv) {
void *p = 0;
_m_prefetch(p);
+ return 0;
}" HAVE_3DNOW)
if(HAVE_3DNOW)
list(APPEND EXTRA_CFLAGS "-m3dnow")
@@ -671,7 +674,7 @@ if(SDL_ASSEMBLY)
#ifndef __SSE__
#error Assembler CPP flag not enabled
#endif
- int main(int argc, char **argv) { }" HAVE_SSE)
+ int main(int argc, char **argv) { return 0; }" HAVE_SSE)
if(HAVE_SSE)
list(APPEND EXTRA_CFLAGS "-msse")
endif()
@@ -694,7 +697,7 @@ if(SDL_ASSEMBLY)
#ifndef __SSE2__
#error Assembler CPP flag not enabled
#endif
- int main(int argc, char **argv) { }" HAVE_SSE2)
+ int main(int argc, char **argv) { return 0; }" HAVE_SSE2)
if(HAVE_SSE2)
list(APPEND EXTRA_CFLAGS "-msse2")
endif()
@@ -717,7 +720,7 @@ if(SDL_ASSEMBLY)
#ifndef __SSE3__
#error Assembler CPP flag not enabled
#endif
- int main(int argc, char **argv) { }" HAVE_SSE3)
+ int main(int argc, char **argv) { return 0; }" HAVE_SSE3)
if(HAVE_SSE3)
list(APPEND EXTRA_CFLAGS "-msse3")
endif()
@@ -746,12 +749,12 @@ if(SDL_ASSEMBLY)
vector unsigned int vzero() {
return vec_splat_u32(0);
}
- int main(int argc, char **argv) { }" HAVE_ALTIVEC_H_HDR)
+ int main(int argc, char **argv) { return 0; }" HAVE_ALTIVEC_H_HDR)
check_c_source_compiles("
vector unsigned int vzero() {
return vec_splat_u32(0);
}
- int main(int argc, char **argv) { }" HAVE_ALTIVEC)
+ int main(int argc, char **argv) { return 0; }" HAVE_ALTIVEC)
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
if(HAVE_ALTIVEC OR HAVE_ALTIVEC_H_HDR)
set(HAVE_ALTIVEC TRUE) # if only HAVE_ALTIVEC_H_HDR is set
@@ -878,7 +881,7 @@ if(SDL_LIBC)
# TODO: refine the mprotect check
check_c_source_compiles("#include <sys/types.h>
#include <sys/mman.h>
- int main() { }" HAVE_MPROTECT)
+ int main() { return 0; }" HAVE_MPROTECT)
foreach(_FN
strtod malloc calloc realloc free getenv setenv putenv unsetenv
qsort abs bcopy memset memcpy memmove memcmp strlen strlcpy strlcat
@@ -1156,9 +1159,7 @@ if(ANDROID)
#if defined(__ARM_ARCH) && __ARM_ARCH < 7
#error Vulkan doesn't work on this configuration
#endif
- int main(void) {
- return 0;
- }
+ int main(int argc, char **argv) { return 0; }
" VULKAN_PASSED_ANDROID_CHECKS)
if(VULKAN_PASSED_ANDROID_CHECKS)
set(SDL_VIDEO_VULKAN 1)
@@ -1294,7 +1295,7 @@ elseif(UNIX AND NOT APPLE AND NOT ANDROID AND NOT RISCOS AND NOT HAIKU)
#ifndef EVIOCGNAME
#error EVIOCGNAME() ioctl not available
#endif
- int main(int argc, char** argv) {}" HAVE_INPUT_EVENTS)
+ int main(int argc, char** argv) { return 0; }" HAVE_INPUT_EVENTS)
if(LINUX)
check_c_source_compiles("
@@ -1306,6 +1307,7 @@ elseif(UNIX AND NOT APPLE AND NOT ANDROID AND NOT RISCOS AND NOT HAIKU)
struct kbentry kbe;
kbe.kb_table = KG_CTRL;
ioctl(0, KDGKBENT, &kbe);
+ return 0;
}" HAVE_INPUT_KD)
elseif(FREEBSD)
check_c_source_compiles("
@@ -1316,6 +1318,7 @@ elseif(UNIX AND NOT APPLE AND NOT ANDROID AND NOT RISCOS AND NOT HAIKU)
{
accentmap_t accTable;
ioctl(0, KDENABIO, 1);
+ return 0;
}" HAVE_INPUT_KBIO)
endif()
@@ -1515,7 +1518,7 @@ elseif(WINDOWS)
check_c_source_compiles("
#include <windows.h>
- int main(int argc, char **argv) { }" HAVE_WIN32_CC)
+ int main(int argc, char **argv) { return 0; }" HAVE_WIN32_CC)
file(GLOB CORE_SOURCES ${SDL2_SOURCE_DIR}/src/core/windows/*.c)
set(SOURCE_FILES ${SOURCE_FILES} ${CORE_SOURCES})
@@ -1580,22 +1583,22 @@ elseif(WINDOWS)
check_c_source_compiles("
#include <windows.h>
#include <xinput.h>
- int main(int argc, char **argv) { }" HAVE_XINPUT_H)
+ int main(int argc, char **argv) { return 0; }" HAVE_XINPUT_H)
check_c_source_compiles("
#include <windows.h>
#include <xinput.h>
XINPUT_GAMEPAD_EX x1;
- int main(int argc, char **argv) { }" HAVE_XINPUT_GAMEPAD_EX)
+ int main(int argc, char **argv) { return 0; }" HAVE_XINPUT_GAMEPAD_EX)
check_c_source_compiles("
#include <windows.h>
#include <xinput.h>
XINPUT_STATE_EX s1;
- int main(int argc, char **argv) { }" HAVE_XINPUT_STATE_EX)
+ int main(int argc, char **argv) { return 0; }" HAVE_XINPUT_STATE_EX)
check_c_source_compiles("
#define COBJMACROS
#include <windows.gaming.input.h>
__x_ABI_CWindows_CGaming_CInput_CIGamepadStatics2 *s2;
- int main(int argc, char **argv) { }" HAVE_WINDOWS_GAMING_INPUT_H)
+ int main(int argc, char **argv) { return 0; }" HAVE_WINDOWS_GAMING_INPUT_H)
endif()
# headers needed elsewhere
@@ -1897,13 +1900,13 @@ elseif(APPLE)
#if TARGET_CPU_X86
#error GameController framework doesn't work on this configuration
#endif
- int main() {}" HAVE_FRAMEWORK_GAMECONTROLLER)
+ int main() { return 0; }" HAVE_FRAMEWORK_GAMECONTROLLER)
check_objc_source_compiles("
#include <AvailabilityMacros.h>
#include <TargetConditionals.h>
#import <Foundation/Foundation.h>
#import <CoreHaptics/CoreHaptics.h>
- int main() {}" HAVE_FRAMEWORK_COREHAPTICS)
+ int main() { return 0; }" HAVE_FRAMEWORK_COREHAPTICS)
if(HAVE_FRAMEWORK_GAMECONTROLLER AND HAVE_FRAMEWORK_COREHAPTICS)
# Only enable MFI if we also have CoreHaptics to ensure rumble works
set(SDL_JOYSTICK_MFI 1)
@@ -2020,7 +2023,7 @@ elseif(APPLE)
#if (!TARGET_CPU_X86_64 && !TARGET_CPU_ARM64)
#error Metal doesn't work on this configuration
#endif
- int main(void) {}" HAVE_FRAMEWORK_METAL)
+ int main(int argc, char **argv) { return 0; }" HAVE_FRAMEWORK_METAL)
if(HAVE_FRAMEWORK_METAL)
set(SDL_FRAMEWORK_METAL 1)
set(SDL_FRAMEWORK_QUARTZCORE 1)
diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake
index 697274c..7385761 100644
--- a/cmake/sdlchecks.cmake
+++ b/cmake/sdlchecks.cmake
@@ -48,6 +48,7 @@ macro(CheckDLOPEN)
int main(int argc, char **argv) {
void *handle = dlopen(\"\", RTLD_NOW);
const char *loaderror = (char *) dlerror();
+ return 0;
}" HAVE_DLOPEN)
set(CMAKE_REQUIRED_LIBRARIES)
endif()
@@ -57,8 +58,7 @@ macro(CheckO_CLOEXEC)
check_c_source_compiles("
#include <fcntl.h>
int flag = O_CLOEXEC;
- int main(void) {
- }" HAVE_O_CLOEXEC)
+ int main(int argc, char **argv) { return 0; }" HAVE_O_CLOEXEC)
endmacro()
# Requires:
@@ -68,12 +68,12 @@ macro(CheckOSS)
set(OSS_HEADER_FILE "sys/soundcard.h")
check_c_source_compiles("
#include <sys/soundcard.h>
- int main() { int arg = SNDCTL_DSP_SETFRAGMENT; }" OSS_FOUND)
+ int main(int argc, char **argv) { int arg = SNDCTL_DSP_SETFRAGMENT; return 0; }" OSS_FOUND)
if(NOT OSS_FOUND)
set(OSS_HEADER_FILE "soundcard.h")
check_c_source_compiles("
#include <soundcard.h>
- int main() { int arg = SNDCTL_DSP_SETFRAGMENT; }" OSS_FOUND)
+ int main(int argc, char **argv) { int arg = SNDCTL_DSP_SETFRAGMENT; return 0; }" OSS_FOUND)
endif()
if(OSS_FOUND)
@@ -481,7 +481,8 @@ macro(CheckX11)
XGenericEventCookie *cookie = &event.xcookie;
XNextEvent(display, &event);
XGetEventData(display, cookie);
- XFreeEventData(display, cookie); }" HAVE_XGENERICEVENT)
+ XFreeEventData(display, cookie);
+ return 0; }" HAVE_XGENERICEVENT)
if(HAVE_XGENERICEVENT)
set(SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1)
endif()
@@ -533,7 +534,7 @@ macro(CheckX11)
{
return (Status)0;
}
- int main(int argc, char **argv) {}" HAVE_XINPUT2_MULTITOUCH)
+ int main(int argc, char **argv) { return 0; }" HAVE_XINPUT2_MULTITOUCH)
if(HAVE_XINPUT2_MULTITOUCH)
set(SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1)
endif()
@@ -547,7 +548,7 @@ macro(CheckX11)
#include <X11/extensions/XInput2.h>
#include <X11/extensions/Xfixes.h>
BarrierEventID b;
- int main(void) { }" HAVE_XFIXES_H)
+ int main(int argc, char **argv) { return 0; }" HAVE_XFIXES_H)
endif()
if(SDL_X11_XFIXES AND HAVE_XFIXES_H AND HAVE_XINPUT2_H)
if(HAVE_X11_SHARED AND XFIXES_LIB)
@@ -777,12 +778,12 @@ macro(CheckVivante)
if(SDL_VIVANTE)
check_c_source_compiles("
#include <gc_vdk.h>
- int main(int argc, char** argv) {}" HAVE_VIVANTE_VDK)
+ int main(int argc, char** argv) { return 0; }" HAVE_VIVANTE_VDK)
check_c_source_compiles("
#define LINUX
#define EGL_API_FB
#include <EGL/eglvivante.h>
- int main(int argc, char** argv) {}" HAVE_VIVANTE_EGL_FB)
+ int main(int argc, char** argv) { return 0; }" HAVE_VIVANTE_EGL_FB)
if(HAVE_VIVANTE_VDK OR HAVE_VIVANTE_EGL_FB)
set(HAVE_VIVANTE TRUE)
set(HAVE_SDL_VIDEO TRUE)
@@ -807,7 +808,7 @@ macro(CheckGLX)
if(SDL_OPENGL)
check_c_source_compiles("
#include <GL/glx.h>
- int main(int argc, char** argv) {}" HAVE_OPENGL_GLX)
+ int main(int argc, char** argv) { return 0; }" HAVE_OPENGL_GLX)
if(HAVE_OPENGL_GLX)
set(SDL_VIDEO_OPENGL_GLX 1)
endif()
@@ -826,7 +827,7 @@ macro(CheckEGL)
#define EGL_NO_X11
#include <EGL/egl.h>
#include <EGL/eglext.h>
- int main (int argc, char** argv) {}" HAVE_OPENGL_EGL)
+ int main (int argc, char** argv) { return 0; }" HAVE_OPENGL_EGL)
if(HAVE_OPENGL_EGL)
set(SDL_VIDEO_OPENGL_EGL 1)
endif()
@@ -840,7 +841,7 @@ macro(CheckOpenGL)
check_c_source_compiles("
#include <GL/gl.h>
#include <GL/glext.h>
- int main(int argc, char** argv) {}" HAVE_OPENGL)
+ int main(int argc, char** argv) { return 0; }" HAVE_OPENGL)
if(HAVE_OPENGL)
set(SDL_VIDEO_OPENGL 1)
set(SDL_VIDEO_RENDER_OGL 1)
@@ -855,7 +856,7 @@ macro(CheckOpenGLES)
check_c_source_compiles("
#include <GLES/gl.h>
#include <GLES/glext.h>
- int main (int argc, char** argv) {}" HAVE_OPENGLES_V1)
+ int main (int argc, char** argv) { return 0; }" HAVE_OPENGLES_V1)
if(HAVE_OPENGLES_V1)
set(HAVE_OPENGLES TRUE)
set(SDL_VIDEO_OPENGL_ES 1)
@@ -864,7 +865,7 @@ macro(CheckOpenGLES)
check_c_source_compiles("
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
- int main (int argc, char** argv) {}" HAVE_OPENGLES_V2)
+ int main (int argc, char** argv) { return 0; }" HAVE_OPENGLES_V2)
if(HAVE_OPENGLES_V2)
set(HAVE_OPENGLES TRUE)
set(SDL_VIDEO_OPENGL_ES2 1)