Do you care to post it or check it in?
Here’s where I was; I had quite a way to go, but I was trying to be
pedantic about converting the entire configure script, instead of going
for bulk and then refining. I can’t say if this was a good strategy or not.
Attached.
–ryan.
-------------- next part --------------
Simple DirectMedia Layer
Copyright © 1997-2012 Sam Lantinga #
This software is provided ‘as-is’, without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
project(SDL C)
cmake_minimum_required(VERSION 2.8.0)
Please update these when making new releases.
set(SDL_MAJOR_VERSION 1)
set(SDL_MINOR_VERSION 3)
set(SDL_MICRO_VERSION 0)
Some utility stuff to make the rest of the code cleaner…
Useful standard CMake macros…
include(CheckIncludeFile)
include(CheckLibraryExists)
include(CheckCSourceCompiles)
include(CheckCCompilerFlag)
include(CheckFunctionExists)
include(CheckStructHasMember)
include(CheckTypeSize)
include(TestBigEndian)
I hate that they define “WIN32” … we’re about to move to Win64…I hope!
if (WIN32 AND NOT WINDOWS)
set(WINDOWS TRUE)
elseif(APPLE AND NOT MACOSX) # Bleh, let’s do it for “APPLE” too.
set(MACOSX TRUE)
elseif(UNIX AND (CMAKE_SYSTEM_NAME STREQUAL “Linux”))
set(LINUX TRUE)
elseif(UNIX AND (CMAKE_SYSTEM_NAME STREQUAL “OpenBSD”))
set(OPENBSD TRUE)
elseif(UNIX AND (CMAKE_SYSTEM_NAME STREQUAL “NetBSD”))
set(NETBSD TRUE)
elseif(UNIX AND (CMAKE_SYSTEM_NAME STREQUAL “FreeBSD”))
set(FREEBSD TRUE)
endif()
Print a key/bool-value pair.
macro(message_bool_option _NAME _VALUE)
if(${_VALUE})
message(STATUS " ${_NAME}: ON")
else()
message(STATUS " ${_NAME}: OFF")
endif()
endmacro()
Print a key/string-value pair.
macro(message_string_option _NAME _VALUE)
message(STATUS " ${_NAME}: ‘${${_VALUE}}’")
endmacro()
This is like the built-in OPTION(), but takes a string instead of a bool.
macro(option_string _NAME _DESC _DEFLT)
set(${_NAME} “${_DEFLT}” CACHE STRING “${_DESC}”)
endmacro()
This checks if a given #define is defined at all (and not what it is set to).
macro(sdl_check_define_exists _CDEF _VALUE _HEADERS _KNOWNYES)
if (${_KNOWNYES}) # don’t launch a compiler if we don’t have to.
set(${_VALUE} TRUE)
else()
set(CMAKE_REQUIRED_INCLUDES “${_HEADERS}”)
check_c_source_compiles("
#ifdef ${_CDEF}
int main(int argc, char **argv) { int yup = 1; return 0; }
#else
#error No such preprocessor define.
#endif
" ${_VALUE}
)
set(CMAKE_REQUIRED_INCLUDES)
endif()
endmacro()
macro(sdl_check_library_exists _LIB _FN _LOC _VALUE _KNOWNYES)
if (${_KNOWNYES}) # don’t launch a compiler if we don’t have to.
set(${_VALUE} TRUE)
else()
check_library_exists("${_LIB}" “${_FN}” “${_LOC}” “${_VALUE}”)
endif()
endmacro()
macro(sdl_check_include_file _HEADER _VALUE _KNOWNYES)
if (${_KNOWNYES}) # don’t launch a compiler if we don’t have to.
set(${_VALUE} TRUE)
else()
check_include_file("${_HEADER}" “${_VALUE}”)
endif()
endmacro()
Check for stuff SDL cares about…
#set(SDL_DEBUG_BUILD ((NOT CMAKE_BUILD_TYPE) OR (CMAKE_BUILD_TYPE STREQUAL “Debug”)))
Check some lowlevel stuff first.
!!! FIXME: check for these things?
#AC_C_CONST
#AC_C_INLINE
#AC_C_VOLATILE
check_type_size(“void *” SIZEOF_VOIDP)
Now let’s look at configurable options…
See whether we are allowed to use the system C library.
option(SDL_LIBC “Use the system C library” TRUE)
if (SDL_LIBC)
SET(HAVE_LIBC 1)
# Check for C library headers
sdl_check_include_file("sys/types.h" HAVE_SYS_TYPES_H MACOSX)
sdl_check_include_file("stdio.h" HAVE_STDIO_H MACOSX)
sdl_check_include_file("stdlib.h" HAVE_STDLIB_H MACOSX)
sdl_check_include_file("stddef.h" HAVE_STDDEF_H MACOSX)
sdl_check_include_file("stdarg.h" HAVE_STDARG_H MACOSX)
sdl_check_include_file("malloc.h" HAVE_MALLOC_H LINUX)
sdl_check_include_file("memory.h" HAVE_MEMORY_H MACOSX)
sdl_check_include_file("string.h" HAVE_STRING_H MACOSX)
sdl_check_include_file("strings.h" HAVE_STRINGS_H MACOSX)
sdl_check_include_file("inttypes.h" HAVE_INTTYPES_H MACOSX)
sdl_check_include_file("stdint.h" HAVE_STDINT_H MACOSX)
sdl_check_include_file("ctype.h" HAVE_CTYPE_H MACOSX)
sdl_check_include_file("math.h" HAVE_MATH_H MACOSX)
sdl_check_include_file("iconv.h" HAVE_ICONV_H MACOSX)
sdl_check_include_file("signal.h" HAVE_SIGNAL_H MACOSX)
sdl_check_include_file("alloca.h" HAVE_ALLOCA_H MACOSX)
sdl_check_define_exists("M_PI" HAVE_M_PI "math.h" MACOSX)
set(HAVE_ALLOCA 1) # !!! FIXME
sdl_check_library_exists("m" "pow" "" HAVE_LIBM LINUX)
if (HAVE_LIBM)
set(SDL_EXTRA_LIBS "${SDL_EXTRA_LIBS};m")
set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};m")
endif()
sdl_check_library_exists("iconv" "iconv_open" "" HAVE_LIBICONV FALSE)
if (HAVE_LIBICONV)
set(SDL_EXTRA_LIBS "${SDL_EXTRA_LIBS};iconv")
set(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES};iconv")
endif()
foreach( _FN
memcmp strtod mprotect malloc calloc realloc free getenv setenv
putenv unsetenv qsort abs bcopy memset memcpy memmove strlen
strlcpy strlcat strdup _strrev _strupr _strlwr strchr strrchr
strstr itoa _ltoa _uitoa _ultoa strtol strtoul _i64toa _ui64toa
strtoll strtoull atoi atof strcmp strncmp _stricmp strcasecmp
_strnicmp strncasecmp sscanf snprintf vsnprintf sigaction setjmp
nanosleep sysconf sysctlbyname atan atan2 ceil copysign cos cosf
fabs floor log pow scalbn sin sinf sqrt iconv )
string(TOUPPER ${_FN} _UPPER)
set(_HAVEVAR "HAVE_${_UPPER}") # "_i64toa" becomes "HAVE__I64TOA"
check_function_exists("${_FN}" ${_HAVEVAR})
endforeach()
set(CMAKE_REQUIRED_LIBRARIES) # lose any "-lm", etc for further tests.
check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION)
endif()
See whether we want assertions for debugging/sanity checking SDL itself.
option_string(SDL_ASSERTIONS “Enable internal sanity checks (auto/disabled/release/enabled/paranoid)” “auto”)
if (SDL_ASSERTIONS STREQUAL “auto”)
# Use optimization settings to determine assertion level
elseif (SDL_ASSERTIONS STREQUAL “disabled”)
set(SDL_DEFAULT_ASSERT_LEVEL 0)
elseif (SDL_ASSERTIONS STREQUAL “release”)
set(SDL_DEFAULT_ASSERT_LEVEL 1)
elseif (SDL_ASSERTIONS STREQUAL “enabled”)
set(SDL_DEFAULT_ASSERT_LEVEL 2)
elseif (SDL_ASSERTIONS STREQUAL “paranoid”)
set(SDL_DEFAULT_ASSERT_LEVEL 3)
else()
message(FATAL_ERROR “unknown assertion level. stop.”)
endif()
!!! FIXME: do this even if atomics are disabled?
See whether we can use gcc atomic operations on this architecture.
option(GCC_ATOMICS “Use gcc builtin atomics” ${CMAKE_COMPILER_IS_GNUCC})
if (GCC_ATOMICS)
check_c_source_compiles(“
int main(int argc, char **argv) {
int a;
void *x, *y, *z;
__sync_lock_test_and_set(&a, 4);
__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);
return 0;
}
” HAVE_GCC_ATOMICS
)
if (NOT HAVE_GCC_ATOMICS)
# See if we have the minimum operation needed for 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);
return 0;
}
" HAVE_GCC_SYNC_LOCK_TEST_AND_SET
)
endif()
endif()
Text for CPU-specific instruction sets…
option(SDL_ASSEMBLY_ROUTINES “Enable assembly routines” TRUE)
!!! FIXME: big pile of sse/mmx/altivec/etc checks should be here.
These are the core SDL sources. We’ll add files to this variable.
set(SOURCES
src/SDL.c
src/SDL_assert.c
src/SDL_compat.c
src/SDL_error.c
src/SDL_fatal.c
src/SDL_hints.c
src/SDL_log.c
src/atomic/SDL_atomic.c
src/atomic/SDL_spinlock.c
src/audio/SDL_audio.c
src/audio/SDL_audiocvt.c
src/audio/SDL_audiodev.c
src/audio/SDL_audiotypecvt.c
src/audio/SDL_mixer.c
src/audio/SDL_wave.c
src/audio/sun/SDL_sunaudio.c
src/audio/winmm/SDL_winmm.c
src/audio/xaudio2/SDL_xaudio2.c
src/cpuinfo/SDL_cpuinfo.c
src/events/SDL_clipboardevents.c
src/events/SDL_dropevents.c
src/events/SDL_events.c
src/events/SDL_gesture.c
src/events/SDL_keyboard.c
src/events/SDL_mouse.c
src/events/SDL_quit.c
src/events/SDL_touch.c
src/events/SDL_windowevents.c
src/file/SDL_rwops.c
src/haptic/SDL_haptic.c
src/joystick/SDL_joystick.c
src/power/SDL_power.c
src/render/direct3d/SDL_render_d3d.c
src/render/nds/SDL_ndsrender.c
src/render/opengl/SDL_render_gl.c
src/render/opengl/SDL_shaders_gl.c
src/render/opengles/SDL_render_gles.c
src/render/opengles2/SDL_render_gles2.c
src/render/opengles2/SDL_shaders_gles2.c
src/render/SDL_render.c
src/render/SDL_yuv_mmx.c
src/render/SDL_yuv_sw.c
src/render/software/SDL_blendfillrect.c
src/render/software/SDL_blendline.c
src/render/software/SDL_blendpoint.c
src/render/software/SDL_drawline.c
src/render/software/SDL_drawpoint.c
src/render/software/SDL_render_sw.c
src/stdlib/SDL_getenv.c
src/stdlib/SDL_iconv.c
src/stdlib/SDL_malloc.c
src/stdlib/SDL_qsort.c
src/stdlib/SDL_stdlib.c
src/stdlib/SDL_string.c
src/thread/SDL_thread.c
src/timer/SDL_timer.c
src/video/SDL_blit.c
src/video/SDL_blit_0.c
src/video/SDL_blit_1.c
src/video/SDL_blit_A.c
src/video/SDL_blit_auto.c
src/video/SDL_blit_copy.c
src/video/SDL_blit_N.c
src/video/SDL_blit_slow.c
src/video/SDL_bmp.c
src/video/SDL_clipboard.c
src/video/SDL_fillrect.c
src/video/SDL_pixels.c
src/video/SDL_rect.c
src/video/SDL_RLEaccel.c
src/video/SDL_shape.c
src/video/SDL_stretch.c
src/video/SDL_surface.c
src/video/SDL_video.c
)
Check for toplevel SDL subsystems.
macro(sdl_subsystem _NAME)
string(TOUPPER “${_NAME}” _UPPER)
set(VARNAME "SDL${_UPPER}")
option(${_VARNAME} “Enable the ${_NAME} subsystem” TRUE)
if (${$_VARNAME}})
SET(${_VARNAME}_DISABLED 1)
endif()
endmacro()
sdl_subystem(atomic)
sdl_subystem(audio)
sdl_subystem(video)
sdl_subystem(render)
sdl_subystem(events)
sdl_subystem(joystick)
sdl_subystem(haptic)
sdl_subystem(power)
sdl_subystem(threads)
sdl_subystem(timers)
sdl_subystem(file)
sdl_subystem(loadso)
sdl_subystem(cpuinfo)
See if the OSS audio interface is supported
macro(CheckOSS)
if (SDL_AUDIO)
option(SDL_OSS “support the OSS audio API” TRUE)
if (SDL_OSS)
sdl_check_include_file(“sys/soundcard.h” HAVE_SYS_SOUNDCARD_H FALSE)
if (NOT HAVE_SYS_SOUNDCARD_H)
sdl_check_include_file(“soundcard.h” HAVE_SOUNDCARD_H FALSE)
if (NOT HAVE_SOUNDCARD_H)
set(SDL_OSS FALSE)
endif()
endif()
if (SDL_OSS)
set(SDL_AUDIO_DRIVER_OSS 1)
set(SOURCES $SOURCES "src/audio/dsp/SDL_dspaudio.c")
set(HAVE_AUDIO TRUE)
# We may need to link with ossaudio emulation library
if (OPENBSD OR NETBSD)
set(SDL_EXTRA_LIBS "${SDL_EXTRA_LIBS};ossaudio")
endif()
endif()
endif()
endif()
endmacro()
See if the ALSA audio interface is supported
macro(CheckALSA)
if (SDL_AUDIO)
option(SDL_ALSA “support the ALSA audio API” TRUE)
if (SDL_ALSA)
include(FindALSA)
if (NOT ALSA_FOUND)
set(SDL_ALSA FALSE)
else()
set(SDL_AUDIO_DRIVER_ALSA 1)
set(SOURCES $SOURCES “src/audio/alsa/SDL_alsaaudio.c”)
set(HAVE_AUDIO TRUE)
include_directories("${ALSA_INCLUDE_DIR}")
option(SDL_ALSA_SHARED "dynamically load ALSA audio support" TRUE)
if (SDL_ALSA_SHARED)
# !!! FIXME: write me.
set(SDL_EXTRA_LIBS "${SDL_EXTRA_LIBS};${ALSA_LIBRARY}")
else()
set(SDL_EXTRA_LIBS "${SDL_EXTRA_LIBS};${ALSA_LIBRARY}")
endif()
endif()
endif()
endif()
endmacro()
Find the ESD includes and libraries
macro(CheckESD)
if (SDL_AUDIO)
option(SDL_ESD “support the Enlightened Sound Daemon” TRUE)
if (SDL_ESD)
# !!! FIXME: make this a macro.
sdl_check_include_file(“esd.h” HAVE_ESD_H FALSE)
if (NOT HAVE_ESD_H)
set(SDL_ESD FALSE)
else()
sdl_check_library_exists(“esd” “esd_open_sound” “” HAVE_LIBESD FALSE)
if (NOT HAVE_LIBESD)
set(SDL_ESD FALSE)
else()
set(SDL_AUDIO_DRIVER_ESD 1)
set(SOURCES $SOURCES “src/audio/esd/SDL_esdaudio.c”)
set(HAVE_AUDIO TRUE)
#include_directories("${ESD_INCLUDE_DIR}")
option(SDL_ESD_SHARED "dynamically load ESD audio support" TRUE)
if (SDL_ESD_SHARED)
# !!! FIXME: write me.
set(SDL_EXTRA_LIBS "${SDL_EXTRA_LIBS};esd")
else()
set(SDL_EXTRA_LIBS "${SDL_EXTRA_LIBS};esd")
endif()
endif()
endif()
endif()
endif()
endmacro()
set(SDL_VERSION “${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}”)
include_directories(".")
include_directories(“include”)
if (CYGWIN)
add_definitions("-I/usr/include/mingw -mno-cygwin")
add_ldflags("-mno-cygwin")
endif()
add_library(SDL SHARED ${SOURCES})
end of CMakeLists.txt …
#enable_language(CXX)
set(ignoreme
src/audio/alsa/SDL_alsa_audio.c
src/audio/android/SDL_androidaudio.c
src/audio/arts/SDL_artsaudio.c
src/audio/bsd/SDL_bsdaudio.c
src/audio/coreaudio/SDL_coreaudio.c
src/audio/directsound/SDL_directsound.c
src/audio/disk/SDL_diskaudio.c
src/audio/dsp/SDL_dspaudio.c
src/audio/dummy/SDL_dummyaudio.c
src/audio/esd/SDL_esdaudio.c
src/audio/fusionsound/SDL_fsaudio.c
src/audio/nas/SDL_nasaudio.c
src/audio/nds/SDL_ndsaudio.c
src/audio/paudio/SDL_paudio.c
src/audio/pulseaudio/SDL_pulseaudio.c
src/audio/qsa/SDL_qsa_audio.c
src/core/windows/SDL_windows.c
src/events/nds/SDL_ndsgesture.c
src/haptic/darwin/SDL_syshaptic.c
src/haptic/dummy/SDL_syshaptic.c
src/haptic/linux/SDL_syshaptic.c
src/haptic/nds/SDL_syshaptic.c
src/haptic/windows/SDL_syshaptic.c
src/joystick/android/SDL_sysjoystick.c
src/joystick/bsd/SDL_sysjoystick.c
src/joystick/darwin/SDL_sysjoystick.c
src/joystick/dummy/SDL_sysjoystick.c
src/joystick/linux/SDL_sysjoystick.c
src/joystick/nds/SDL_sysjoystick.c
src/joystick/windows/SDL_dxjoystick.c
src/joystick/windows/SDL_mmjoystick.c
src/libm/e_atan2.c
src/libm/e_log.c
src/libm/e_pow.c
src/libm/e_rem_pio2.c
src/libm/e_sqrt.c
src/libm/k_cos.c
src/libm/k_rem_pio2.c
src/libm/k_sin.c
src/libm/s_atan.c
src/libm/s_copysign.c
src/libm/s_cos.c
src/libm/s_fabs.c
src/libm/s_floor.c
src/libm/s_scalbn.c
src/libm/s_sin.c
src/loadso/beos/SDL_sysloadso.c
src/loadso/dlopen/SDL_sysloadso.c
src/loadso/dummy/SDL_sysloadso.c
src/loadso/windows/SDL_sysloadso.c
src/main/dummy/SDL_dummy_main.c
src/main/windows/SDL_windows_main.c
src/power/beos/SDL_syspower.c
src/power/linux/SDL_syspower.c
src/power/macosx/SDL_syspower.c
src/power/nds/SDL_syspower.c
src/power/windows/SDL_syspower.c
src/thread/beos/SDL_syssem.c
src/thread/beos/SDL_systhread.c
src/thread/generic/SDL_syscond.c
src/thread/generic/SDL_sysmutex.c
src/thread/generic/SDL_syssem.c
src/thread/generic/SDL_systhread.c
src/thread/nds/SDL_syscond.c
src/thread/nds/SDL_sysmutex.c
src/thread/nds/SDL_syssem.c
src/thread/nds/SDL_systhread.c
src/thread/pthread/SDL_syscond.c
src/thread/pthread/SDL_sysmutex.c
src/thread/pthread/SDL_syssem.c
src/thread/pthread/SDL_systhread.c
src/thread/windows/SDL_sysmutex.c
src/thread/windows/SDL_syssem.c
src/thread/windows/SDL_systhread.c
src/thread/windows/win_ce_semaphore.c
src/timer/beos/SDL_systimer.c
src/timer/dummy/SDL_systimer.c
src/timer/nds/SDL_systimer.c
src/timer/unix/SDL_systimer.c
src/timer/wince/SDL_systimer.c
src/timer/windows/SDL_systimer.c
src/video/android/SDL_androidevents.c
src/video/android/SDL_androidgl.c
src/video/android/SDL_androidkeyboard.c
src/video/android/SDL_androidtouch.c
src/video/android/SDL_androidvideo.c
src/video/android/SDL_androidwindow.c
src/video/directfb/SDL_DirectFB_dyn.c
src/video/directfb/SDL_DirectFB_events.c
src/video/directfb/SDL_DirectFB_modes.c
src/video/directfb/SDL_DirectFB_mouse.c
src/video/directfb/SDL_DirectFB_opengl.c
src/video/directfb/SDL_DirectFB_render.c
src/video/directfb/SDL_DirectFB_shape.c
src/video/directfb/SDL_DirectFB_video.c
src/video/directfb/SDL_DirectFB_window.c
src/video/directfb/SDL_DirectFB_WM.c
src/video/dummy/SDL_nullevents.c
src/video/dummy/SDL_nullframebuffer.c
src/video/dummy/SDL_nullvideo.c
src/video/nds/SDL_ndsevents.c
src/video/nds/SDL_ndsvideo.c
src/video/nds/SDL_ndswindow.c
src/video/pandora/SDL_pandora.c
src/video/pandora/SDL_pandora_events.c
src/video/uikit/jumphack.c
src/video/windows/SDL_windowsclipboard.c
src/video/windows/SDL_windowsevents.c
src/video/windows/SDL_windowsframebuffer.c
src/video/windows/SDL_windowskeyboard.c
src/video/windows/SDL_windowsmodes.c
src/video/windows/SDL_windowsmouse.c
src/video/windows/SDL_windowsopengl.c
src/video/windows/SDL_windowsshape.c
src/video/windows/SDL_windowsvideo.c
src/video/windows/SDL_windowswindow.c
src/video/x11/imKStoUCS.c
src/video/x11/SDL_x11clipboard.c
src/video/x11/SDL_x11dyn.c
src/video/x11/SDL_x11events.c
src/video/x11/SDL_x11framebuffer.c
src/video/x11/SDL_x11keyboard.c
src/video/x11/SDL_x11modes.c
src/video/x11/SDL_x11mouse.c
src/video/x11/SDL_x11opengl.c
src/video/x11/SDL_x11opengles.c
src/video/x11/SDL_x11shape.c
src/video/x11/SDL_x11touch.c
src/video/x11/SDL_x11video.c
src/video/x11/SDL_x11window.c
)