CMakeLists.txt
changeset 9278 8900afb78a19
parent 9277 f0bd40782fc7
child 9279 e1d1b6479a14
     1.1 --- a/CMakeLists.txt	Sat Dec 13 02:33:52 2014 -0500
     1.2 +++ b/CMakeLists.txt	Thu Dec 18 00:19:52 2014 -0500
     1.3 @@ -117,6 +117,12 @@
     1.4    set(UNIX_OR_MAC_SYS OFF)
     1.5  endif()
     1.6  
     1.7 +if (UNIX_OR_MAC_SYS AND NOT EMSCRIPTEN) # JavaScript does not yet have threading support, so disable pthreads when building for Emscripten.
     1.8 +  set(PTHREADS_ENABLED_BY_DEFAULT ON)
     1.9 +else()
    1.10 +  set(PTHREADS_ENABLED_BY_DEFAULT OFF)
    1.11 +endif()
    1.12 +
    1.13  # Default option knobs
    1.14  if(APPLE OR ARCH_64)
    1.15    set(OPT_DEF_SSEMATH ON)
    1.16 @@ -170,13 +176,19 @@
    1.17  set(SDL_LIBS "-lSDL2")
    1.18  set(SDL_CFLAGS "")
    1.19  
    1.20 +# Emscripten toolchain has a nonempty default value for this, and the checks 
    1.21 +# in this file need to change that, so remember the original value, and 
    1.22 +# restore back to that afterwards. For check_function_exists() to work in
    1.23 +# Emscripten, this value must be at its default value.
    1.24 +set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
    1.25 +
    1.26  if(CYGWIN)
    1.27    # We build SDL on cygwin without the UNIX emulation layer
    1.28    include_directories("-I/usr/include/mingw")
    1.29    set(CMAKE_REQUIRED_FLAGS "-mno-cygwin")
    1.30    check_c_source_compiles("int main(int argc, char **argv) {}"
    1.31      HAVE_GCC_NO_CYGWIN)
    1.32 -  set(CMAKE_REQUIRED_FLAGS)
    1.33 +  set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
    1.34    if(HAVE_GCC_NO_CYGWIN)
    1.35      list(APPEND EXTRA_LDFLAGS "-mno-cygwin")
    1.36      list(APPEND SDL_LIBS "-mno-cygwin")
    1.37 @@ -188,12 +200,35 @@
    1.38  # General includes
    1.39  include_directories(${SDL2_BINARY_DIR}/include ${SDL2_SOURCE_DIR}/include)
    1.40  
    1.41 +if(EMSCRIPTEN)
    1.42 +  # Set up default values for the currently supported set of subsystems:
    1.43 +  # Emscripten/Javascript does not have assembly support, a dynamic library 
    1.44 +  # loading architecture, low-level CPU inspection or multithreading.
    1.45 +  set(OPT_DEF_ASM FALSE)
    1.46 +  set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
    1.47 +  set(SDL_ATOMIC_ENABLED_BY_DEFAULT OFF)
    1.48 +  set(SDL_THREADS_ENABLED_BY_DEFAULT OFF)
    1.49 +  set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF)
    1.50 +  set(SDL_CPUINFO_ENABLED_BY_DEFAULT OFF)
    1.51 +  set(DLOPEN_ENABLED_BY_DEFAULT OFF)
    1.52 +else()
    1.53 +  set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
    1.54 +  set(SDL_ATOMIC_ENABLED_BY_DEFAULT ON)
    1.55 +  set(SDL_THREADS_ENABLED_BY_DEFAULT ON)
    1.56 +  set(SDL_LOADSO_ENABLED_BY_DEFAULT ON)
    1.57 +  set(SDL_CPUINFO_ENABLED_BY_DEFAULT ON)
    1.58 +  set(DLOPEN_ENABLED_BY_DEFAULT ON)
    1.59 +endif()
    1.60 +
    1.61  set(SDL_SUBSYSTEMS
    1.62      Atomic Audio Video Render Events Joystick Haptic Power Threads Timers
    1.63      File Loadso CPUinfo Filesystem)
    1.64  foreach(_SUB ${SDL_SUBSYSTEMS})
    1.65    string(TOUPPER ${_SUB} _OPT)
    1.66 -  option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ON)
    1.67 +  if (NOT DEFINED SDL_${_OPT}_ENABLED_BY_DEFAULT)
    1.68 +    set(SDL_${_OPT}_ENABLED_BY_DEFAULT ON)
    1.69 +  endif()
    1.70 +  option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ${SDL_${_OPT}_ENABLED_BY_DEFAULT})
    1.71  endforeach()
    1.72  
    1.73  option_string(ASSERTIONS "Enable internal sanity checks (auto/disabled/release/enabled/paranoid)" "auto")
    1.74 @@ -216,9 +251,9 @@
    1.75  set_option(VIDEO_DUMMY         "Use dummy video driver" ON)
    1.76  set_option(VIDEO_OPENGL        "Include OpenGL support" ON)
    1.77  set_option(VIDEO_OPENGLES      "Include OpenGL ES support" ON)
    1.78 -set_option(PTHREADS            "Use POSIX threads for multi-threading" ${UNIX_OR_MAC_SYS})
    1.79 +set_option(PTHREADS            "Use POSIX threads for multi-threading" ${PTHREADS_ENABLED_BY_DEFAULT})
    1.80  dep_option(PTHREADS_SEM        "Use pthread semaphores" ON "PTHREADS" OFF)
    1.81 -set_option(SDL_DLOPEN          "Use dlopen for shared object loading" ON)
    1.82 +set_option(SDL_DLOPEN          "Use dlopen for shared object loading" ${DLOPEN_ENABLED_BY_DEFAULT})
    1.83  set_option(OSS                 "Support the OSS audio API" ${UNIX_SYS})
    1.84  set_option(ALSA                "Support the ALSA audio API" ${UNIX_SYS})
    1.85  dep_option(ALSA_SHARED         "Dynamically load ALSA audio support" ON "ALSA" OFF)
    1.86 @@ -251,7 +286,7 @@
    1.87  
    1.88  # TODO: We should (should we?) respect cmake's ${BUILD_SHARED_LIBS} flag here
    1.89  # The options below are for compatibility to configure's default behaviour.
    1.90 -set(SDL_SHARED ON CACHE BOOL "Build a shared version of the library")
    1.91 +set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared version of the library")
    1.92  set(SDL_STATIC ON CACHE BOOL "Build a static version of the library")
    1.93  
    1.94  # General source files
    1.95 @@ -317,7 +352,7 @@
    1.96    set(CMAKE_REQUIRED_FLAGS "-mpreferred-stack-boundary=2")
    1.97    check_c_source_compiles("int x = 0; int main(int argc, char **argv) {}"
    1.98      HAVE_GCC_PREFERRED_STACK_BOUNDARY)
    1.99 -  set(CMAKE_REQUIRED_FLAGS)
   1.100 +  set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   1.101  
   1.102    set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden -Werror")
   1.103    check_c_source_compiles("
   1.104 @@ -328,7 +363,7 @@
   1.105    if(HAVE_GCC_FVISIBILITY)
   1.106      list(APPEND EXTRA_CFLAGS "-fvisibility=hidden")
   1.107    endif()
   1.108 -  set(CMAKE_REQUIRED_FLAGS)
   1.109 +  set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   1.110  
   1.111    check_c_compiler_flag(-Wall HAVE_GCC_WALL)
   1.112    if(HAVE_GCC_WALL)
   1.113 @@ -376,7 +411,7 @@
   1.114        if(HAVE_MMX)
   1.115          list(APPEND EXTRA_CFLAGS "-mmmx")
   1.116        endif()
   1.117 -      set(CMAKE_REQUIRED_FLAGS)
   1.118 +      set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   1.119      endif()
   1.120  
   1.121      if(3DNOW)
   1.122 @@ -393,7 +428,7 @@
   1.123        if(HAVE_3DNOW)
   1.124          list(APPEND EXTRA_CFLAGS "-m3dnow")
   1.125        endif()
   1.126 -      set(CMAKE_REQUIRED_FLAGS)
   1.127 +      set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   1.128      endif()
   1.129  
   1.130      if(SSE)
   1.131 @@ -416,7 +451,7 @@
   1.132        if(HAVE_SSE)
   1.133          list(APPEND EXTRA_CFLAGS "-msse")
   1.134        endif()
   1.135 -      set(CMAKE_REQUIRED_FLAGS)
   1.136 +      set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   1.137      endif()
   1.138  
   1.139      if(SSE2)
   1.140 @@ -439,7 +474,7 @@
   1.141        if(HAVE_SSE2)
   1.142          list(APPEND EXTRA_CFLAGS "-msse2")
   1.143        endif()
   1.144 -      set(CMAKE_REQUIRED_FLAGS)
   1.145 +      set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   1.146      endif()
   1.147  
   1.148      if(SSEMATH)
   1.149 @@ -464,7 +499,7 @@
   1.150                return vec_splat_u32(0);
   1.151            }
   1.152            int main(int argc, char **argv) { }" HAVE_ALTIVEC)
   1.153 -      set(CMAKE_REQUIRED_FLAGS)
   1.154 +      set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   1.155        if(HAVE_ALTIVEC OR HAVE_ALTIVEC_H_HDR)
   1.156          set(HAVE_ALTIVEC TRUE) # if only HAVE_ALTIVEC_H_HDR is set
   1.157          list(APPEND EXTRA_CFLAGS "-maltivec")
   1.158 @@ -642,7 +677,49 @@
   1.159  endif()
   1.160  
   1.161  # Platform-specific options and settings
   1.162 -if(UNIX AND NOT APPLE)
   1.163 +if(EMSCRIPTEN)
   1.164 +  # Hide noisy warnings that intend to aid mostly during initial stages of porting a new
   1.165 +  # project. Uncomment at will for verbose cross-compiling -I/../ path info.
   1.166 +  add_definitions(-Wno-warn-absolute-paths)
   1.167 +  if(SDL_AUDIO)
   1.168 +    set(SDL_AUDIO_DRIVER_EMSCRIPTEN 1)
   1.169 +    file(GLOB EM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/emscripten/*.c)
   1.170 +    set(SOURCE_FILES ${SOURCE_FILES} ${EM_AUDIO_SOURCES})
   1.171 +    set(HAVE_SDL_AUDIO TRUE)
   1.172 +  endif()
   1.173 +  if(SDL_FILESYSTEM)
   1.174 +    set(SDL_FILESYSTEM_EMSCRIPTEN 1)
   1.175 +    file(GLOB EM_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/emscripten/*.c)
   1.176 +    set(SOURCE_FILES ${SOURCE_FILES} ${EM_FILESYSTEM_SOURCES})
   1.177 +    set(HAVE_SDL_FILESYSTEM TRUE)
   1.178 +  endif()
   1.179 +  if(SDL_JOYSTICK)
   1.180 +    set(SDL_JOYSTICK_EMSCRIPTEN 1)
   1.181 +    file(GLOB EM_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/emscripten/*.c)
   1.182 +    set(SOURCE_FILES ${SOURCE_FILES} ${EM_JOYSTICK_SOURCES})
   1.183 +    set(HAVE_SDL_JOYSTICK TRUE)
   1.184 +  endif()
   1.185 +  if(SDL_POWER)
   1.186 +    set(SDL_POWER_EMSCRIPTEN 1)
   1.187 +    file(GLOB EM_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/emscripten/*.c)
   1.188 +    set(SOURCE_FILES ${SOURCE_FILES} ${EM_POWER_SOURCES})
   1.189 +    set(HAVE_SDL_POWER TRUE)
   1.190 +  endif()
   1.191 +  if(SDL_VIDEO)
   1.192 +    set(SDL_VIDEO_DRIVER_EMSCRIPTEN 1)
   1.193 +    file(GLOB EM_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/emscripten/*.c)
   1.194 +    set(SOURCE_FILES ${SOURCE_FILES} ${EM_VIDEO_SOURCES})
   1.195 +    set(HAVE_SDL_VIDEO TRUE)
   1.196 +
   1.197 +    #enable gles
   1.198 +    if(VIDEO_OPENGLES)
   1.199 +      set(SDL_VIDEO_OPENGL_EGL 1)
   1.200 +      set(HAVE_VIDEO_OPENGLES TRUE)
   1.201 +      set(SDL_VIDEO_OPENGL_ES2 1)
   1.202 +      set(SDL_VIDEO_RENDER_OGL_ES2 1)
   1.203 +    endif()
   1.204 +  endif()
   1.205 +elseif(UNIX AND NOT APPLE)
   1.206    if(SDL_AUDIO)
   1.207      if(SYSV5 OR SOLARIS OR HPUX)
   1.208          set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
   1.209 @@ -829,7 +906,7 @@
   1.210        link_directories($ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH})
   1.211        include_directories($ENV{DXSDK_DIR}\\Include)
   1.212      endif()
   1.213 -    set(CMAKE_REQUIRED_FLAGS)
   1.214 +    set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   1.215    endif()
   1.216  
   1.217    if(SDL_AUDIO)