CMakeLists.txt
changeset 9278 8900afb78a19
parent 9277 f0bd40782fc7
child 9279 e1d1b6479a14
equal deleted inserted replaced
9277:f0bd40782fc7 9278:8900afb78a19
   115   set(UNIX_OR_MAC_SYS ON)
   115   set(UNIX_OR_MAC_SYS ON)
   116 else()
   116 else()
   117   set(UNIX_OR_MAC_SYS OFF)
   117   set(UNIX_OR_MAC_SYS OFF)
   118 endif()
   118 endif()
   119 
   119 
       
   120 if (UNIX_OR_MAC_SYS AND NOT EMSCRIPTEN) # JavaScript does not yet have threading support, so disable pthreads when building for Emscripten.
       
   121   set(PTHREADS_ENABLED_BY_DEFAULT ON)
       
   122 else()
       
   123   set(PTHREADS_ENABLED_BY_DEFAULT OFF)
       
   124 endif()
       
   125 
   120 # Default option knobs
   126 # Default option knobs
   121 if(APPLE OR ARCH_64)
   127 if(APPLE OR ARCH_64)
   122   set(OPT_DEF_SSEMATH ON)
   128   set(OPT_DEF_SSEMATH ON)
   123 endif()
   129 endif()
   124 if(UNIX OR MINGW OR MSYS)
   130 if(UNIX OR MINGW OR MSYS)
   168 # Those are used for pkg-config and friends, so that the SDL2.pc, sdl2-config,
   174 # Those are used for pkg-config and friends, so that the SDL2.pc, sdl2-config,
   169 # etc. are created correctly.
   175 # etc. are created correctly.
   170 set(SDL_LIBS "-lSDL2")
   176 set(SDL_LIBS "-lSDL2")
   171 set(SDL_CFLAGS "")
   177 set(SDL_CFLAGS "")
   172 
   178 
       
   179 # Emscripten toolchain has a nonempty default value for this, and the checks 
       
   180 # in this file need to change that, so remember the original value, and 
       
   181 # restore back to that afterwards. For check_function_exists() to work in
       
   182 # Emscripten, this value must be at its default value.
       
   183 set(ORIG_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
       
   184 
   173 if(CYGWIN)
   185 if(CYGWIN)
   174   # We build SDL on cygwin without the UNIX emulation layer
   186   # We build SDL on cygwin without the UNIX emulation layer
   175   include_directories("-I/usr/include/mingw")
   187   include_directories("-I/usr/include/mingw")
   176   set(CMAKE_REQUIRED_FLAGS "-mno-cygwin")
   188   set(CMAKE_REQUIRED_FLAGS "-mno-cygwin")
   177   check_c_source_compiles("int main(int argc, char **argv) {}"
   189   check_c_source_compiles("int main(int argc, char **argv) {}"
   178     HAVE_GCC_NO_CYGWIN)
   190     HAVE_GCC_NO_CYGWIN)
   179   set(CMAKE_REQUIRED_FLAGS)
   191   set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   180   if(HAVE_GCC_NO_CYGWIN)
   192   if(HAVE_GCC_NO_CYGWIN)
   181     list(APPEND EXTRA_LDFLAGS "-mno-cygwin")
   193     list(APPEND EXTRA_LDFLAGS "-mno-cygwin")
   182     list(APPEND SDL_LIBS "-mno-cygwin")
   194     list(APPEND SDL_LIBS "-mno-cygwin")
   183   endif()
   195   endif()
   184   set(SDL_CFLAGS "${SDL_CFLAGS} -I/usr/include/mingw")
   196   set(SDL_CFLAGS "${SDL_CFLAGS} -I/usr/include/mingw")
   185 endif()
   197 endif()
   186 
   198 
   187 add_definitions(-DUSING_GENERATED_CONFIG_H)
   199 add_definitions(-DUSING_GENERATED_CONFIG_H)
   188 # General includes
   200 # General includes
   189 include_directories(${SDL2_BINARY_DIR}/include ${SDL2_SOURCE_DIR}/include)
   201 include_directories(${SDL2_BINARY_DIR}/include ${SDL2_SOURCE_DIR}/include)
       
   202 
       
   203 if(EMSCRIPTEN)
       
   204   # Set up default values for the currently supported set of subsystems:
       
   205   # Emscripten/Javascript does not have assembly support, a dynamic library 
       
   206   # loading architecture, low-level CPU inspection or multithreading.
       
   207   set(OPT_DEF_ASM FALSE)
       
   208   set(SDL_SHARED_ENABLED_BY_DEFAULT OFF)
       
   209   set(SDL_ATOMIC_ENABLED_BY_DEFAULT OFF)
       
   210   set(SDL_THREADS_ENABLED_BY_DEFAULT OFF)
       
   211   set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF)
       
   212   set(SDL_CPUINFO_ENABLED_BY_DEFAULT OFF)
       
   213   set(DLOPEN_ENABLED_BY_DEFAULT OFF)
       
   214 else()
       
   215   set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
       
   216   set(SDL_ATOMIC_ENABLED_BY_DEFAULT ON)
       
   217   set(SDL_THREADS_ENABLED_BY_DEFAULT ON)
       
   218   set(SDL_LOADSO_ENABLED_BY_DEFAULT ON)
       
   219   set(SDL_CPUINFO_ENABLED_BY_DEFAULT ON)
       
   220   set(DLOPEN_ENABLED_BY_DEFAULT ON)
       
   221 endif()
   190 
   222 
   191 set(SDL_SUBSYSTEMS
   223 set(SDL_SUBSYSTEMS
   192     Atomic Audio Video Render Events Joystick Haptic Power Threads Timers
   224     Atomic Audio Video Render Events Joystick Haptic Power Threads Timers
   193     File Loadso CPUinfo Filesystem)
   225     File Loadso CPUinfo Filesystem)
   194 foreach(_SUB ${SDL_SUBSYSTEMS})
   226 foreach(_SUB ${SDL_SUBSYSTEMS})
   195   string(TOUPPER ${_SUB} _OPT)
   227   string(TOUPPER ${_SUB} _OPT)
   196   option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ON)
   228   if (NOT DEFINED SDL_${_OPT}_ENABLED_BY_DEFAULT)
       
   229     set(SDL_${_OPT}_ENABLED_BY_DEFAULT ON)
       
   230   endif()
       
   231   option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ${SDL_${_OPT}_ENABLED_BY_DEFAULT})
   197 endforeach()
   232 endforeach()
   198 
   233 
   199 option_string(ASSERTIONS "Enable internal sanity checks (auto/disabled/release/enabled/paranoid)" "auto")
   234 option_string(ASSERTIONS "Enable internal sanity checks (auto/disabled/release/enabled/paranoid)" "auto")
   200 #set_option(DEPENDENCY_TRACKING "Use gcc -MMD -MT dependency tracking" ON)
   235 #set_option(DEPENDENCY_TRACKING "Use gcc -MMD -MT dependency tracking" ON)
   201 set_option(LIBC                "Use the system C library" ${OPT_DEF_LIBC})
   236 set_option(LIBC                "Use the system C library" ${OPT_DEF_LIBC})
   214 set_option(FUSIONSOUND         "Use FusionSound audio driver" OFF)
   249 set_option(FUSIONSOUND         "Use FusionSound audio driver" OFF)
   215 dep_option(FUSIONSOUND_SHARED  "Dynamically load fusionsound audio support" ON "FUSIONSOUND_SHARED" OFF)
   250 dep_option(FUSIONSOUND_SHARED  "Dynamically load fusionsound audio support" ON "FUSIONSOUND_SHARED" OFF)
   216 set_option(VIDEO_DUMMY         "Use dummy video driver" ON)
   251 set_option(VIDEO_DUMMY         "Use dummy video driver" ON)
   217 set_option(VIDEO_OPENGL        "Include OpenGL support" ON)
   252 set_option(VIDEO_OPENGL        "Include OpenGL support" ON)
   218 set_option(VIDEO_OPENGLES      "Include OpenGL ES support" ON)
   253 set_option(VIDEO_OPENGLES      "Include OpenGL ES support" ON)
   219 set_option(PTHREADS            "Use POSIX threads for multi-threading" ${UNIX_OR_MAC_SYS})
   254 set_option(PTHREADS            "Use POSIX threads for multi-threading" ${PTHREADS_ENABLED_BY_DEFAULT})
   220 dep_option(PTHREADS_SEM        "Use pthread semaphores" ON "PTHREADS" OFF)
   255 dep_option(PTHREADS_SEM        "Use pthread semaphores" ON "PTHREADS" OFF)
   221 set_option(SDL_DLOPEN          "Use dlopen for shared object loading" ON)
   256 set_option(SDL_DLOPEN          "Use dlopen for shared object loading" ${DLOPEN_ENABLED_BY_DEFAULT})
   222 set_option(OSS                 "Support the OSS audio API" ${UNIX_SYS})
   257 set_option(OSS                 "Support the OSS audio API" ${UNIX_SYS})
   223 set_option(ALSA                "Support the ALSA audio API" ${UNIX_SYS})
   258 set_option(ALSA                "Support the ALSA audio API" ${UNIX_SYS})
   224 dep_option(ALSA_SHARED         "Dynamically load ALSA audio support" ON "ALSA" OFF)
   259 dep_option(ALSA_SHARED         "Dynamically load ALSA audio support" ON "ALSA" OFF)
   225 set_option(ESD                 "Support the Enlightened Sound Daemon" ${UNIX_SYS})
   260 set_option(ESD                 "Support the Enlightened Sound Daemon" ${UNIX_SYS})
   226 dep_option(ESD_SHARED          "Dynamically load ESD audio support" ON "ESD" OFF)
   261 dep_option(ESD_SHARED          "Dynamically load ESD audio support" ON "ESD" OFF)
   249 set_option(RENDER_D3D          "Enable the Direct3D render driver" ${WINDOWS})
   284 set_option(RENDER_D3D          "Enable the Direct3D render driver" ${WINDOWS})
   250 set_option(VIDEO_VIVANTE       "Use Vivante EGL video driver" ${UNIX_SYS})
   285 set_option(VIDEO_VIVANTE       "Use Vivante EGL video driver" ${UNIX_SYS})
   251 
   286 
   252 # TODO: We should (should we?) respect cmake's ${BUILD_SHARED_LIBS} flag here
   287 # TODO: We should (should we?) respect cmake's ${BUILD_SHARED_LIBS} flag here
   253 # The options below are for compatibility to configure's default behaviour.
   288 # The options below are for compatibility to configure's default behaviour.
   254 set(SDL_SHARED ON CACHE BOOL "Build a shared version of the library")
   289 set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared version of the library")
   255 set(SDL_STATIC ON CACHE BOOL "Build a static version of the library")
   290 set(SDL_STATIC ON CACHE BOOL "Build a static version of the library")
   256 
   291 
   257 # General source files
   292 # General source files
   258 file(GLOB SOURCE_FILES
   293 file(GLOB SOURCE_FILES
   259   ${SDL2_SOURCE_DIR}/src/*.c
   294   ${SDL2_SOURCE_DIR}/src/*.c
   315   endif()
   350   endif()
   316 
   351 
   317   set(CMAKE_REQUIRED_FLAGS "-mpreferred-stack-boundary=2")
   352   set(CMAKE_REQUIRED_FLAGS "-mpreferred-stack-boundary=2")
   318   check_c_source_compiles("int x = 0; int main(int argc, char **argv) {}"
   353   check_c_source_compiles("int x = 0; int main(int argc, char **argv) {}"
   319     HAVE_GCC_PREFERRED_STACK_BOUNDARY)
   354     HAVE_GCC_PREFERRED_STACK_BOUNDARY)
   320   set(CMAKE_REQUIRED_FLAGS)
   355   set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   321 
   356 
   322   set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden -Werror")
   357   set(CMAKE_REQUIRED_FLAGS "-fvisibility=hidden -Werror")
   323   check_c_source_compiles("
   358   check_c_source_compiles("
   324       #if !defined(__GNUC__) || __GNUC__ < 4
   359       #if !defined(__GNUC__) || __GNUC__ < 4
   325       #error SDL only uses visibility attributes in GCC 4 or newer
   360       #error SDL only uses visibility attributes in GCC 4 or newer
   326       #endif
   361       #endif
   327       int main(int argc, char **argv) {}" HAVE_GCC_FVISIBILITY)
   362       int main(int argc, char **argv) {}" HAVE_GCC_FVISIBILITY)
   328   if(HAVE_GCC_FVISIBILITY)
   363   if(HAVE_GCC_FVISIBILITY)
   329     list(APPEND EXTRA_CFLAGS "-fvisibility=hidden")
   364     list(APPEND EXTRA_CFLAGS "-fvisibility=hidden")
   330   endif()
   365   endif()
   331   set(CMAKE_REQUIRED_FLAGS)
   366   set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   332 
   367 
   333   check_c_compiler_flag(-Wall HAVE_GCC_WALL)
   368   check_c_compiler_flag(-Wall HAVE_GCC_WALL)
   334   if(HAVE_GCC_WALL)
   369   if(HAVE_GCC_WALL)
   335     list(APPEND EXTRA_CFLAGS "-Wall")
   370     list(APPEND EXTRA_CFLAGS "-Wall")
   336     if(HAIKU)
   371     if(HAIKU)
   374           #endif
   409           #endif
   375           int main(int argc, char **argv) { }" HAVE_MMX)
   410           int main(int argc, char **argv) { }" HAVE_MMX)
   376       if(HAVE_MMX)
   411       if(HAVE_MMX)
   377         list(APPEND EXTRA_CFLAGS "-mmmx")
   412         list(APPEND EXTRA_CFLAGS "-mmmx")
   378       endif()
   413       endif()
   379       set(CMAKE_REQUIRED_FLAGS)
   414       set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   380     endif()
   415     endif()
   381 
   416 
   382     if(3DNOW)
   417     if(3DNOW)
   383       set(CMAKE_REQUIRED_FLAGS "-m3dnow")
   418       set(CMAKE_REQUIRED_FLAGS "-m3dnow")
   384       check_c_source_compiles("
   419       check_c_source_compiles("
   391             _m_prefetch(p);
   426             _m_prefetch(p);
   392           }" HAVE_3DNOW)
   427           }" HAVE_3DNOW)
   393       if(HAVE_3DNOW)
   428       if(HAVE_3DNOW)
   394         list(APPEND EXTRA_CFLAGS "-m3dnow")
   429         list(APPEND EXTRA_CFLAGS "-m3dnow")
   395       endif()
   430       endif()
   396       set(CMAKE_REQUIRED_FLAGS)
   431       set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   397     endif()
   432     endif()
   398 
   433 
   399     if(SSE)
   434     if(SSE)
   400       set(CMAKE_REQUIRED_FLAGS "-msse")
   435       set(CMAKE_REQUIRED_FLAGS "-msse")
   401       check_c_source_compiles("
   436       check_c_source_compiles("
   414           #endif
   449           #endif
   415           int main(int argc, char **argv) { }" HAVE_SSE)
   450           int main(int argc, char **argv) { }" HAVE_SSE)
   416       if(HAVE_SSE)
   451       if(HAVE_SSE)
   417         list(APPEND EXTRA_CFLAGS "-msse")
   452         list(APPEND EXTRA_CFLAGS "-msse")
   418       endif()
   453       endif()
   419       set(CMAKE_REQUIRED_FLAGS)
   454       set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   420     endif()
   455     endif()
   421 
   456 
   422     if(SSE2)
   457     if(SSE2)
   423       set(CMAKE_REQUIRED_FLAGS "-msse2")
   458       set(CMAKE_REQUIRED_FLAGS "-msse2")
   424       check_c_source_compiles("
   459       check_c_source_compiles("
   437           #endif
   472           #endif
   438           int main(int argc, char **argv) { }" HAVE_SSE2)
   473           int main(int argc, char **argv) { }" HAVE_SSE2)
   439       if(HAVE_SSE2)
   474       if(HAVE_SSE2)
   440         list(APPEND EXTRA_CFLAGS "-msse2")
   475         list(APPEND EXTRA_CFLAGS "-msse2")
   441       endif()
   476       endif()
   442       set(CMAKE_REQUIRED_FLAGS)
   477       set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   443     endif()
   478     endif()
   444 
   479 
   445     if(SSEMATH)
   480     if(SSEMATH)
   446       if(SSE OR SSE2)
   481       if(SSE OR SSE2)
   447         if(USE_GCC)
   482         if(USE_GCC)
   462       check_c_source_compiles("
   497       check_c_source_compiles("
   463           vector unsigned int vzero() {
   498           vector unsigned int vzero() {
   464               return vec_splat_u32(0);
   499               return vec_splat_u32(0);
   465           }
   500           }
   466           int main(int argc, char **argv) { }" HAVE_ALTIVEC)
   501           int main(int argc, char **argv) { }" HAVE_ALTIVEC)
   467       set(CMAKE_REQUIRED_FLAGS)
   502       set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   468       if(HAVE_ALTIVEC OR HAVE_ALTIVEC_H_HDR)
   503       if(HAVE_ALTIVEC OR HAVE_ALTIVEC_H_HDR)
   469         set(HAVE_ALTIVEC TRUE) # if only HAVE_ALTIVEC_H_HDR is set
   504         set(HAVE_ALTIVEC TRUE) # if only HAVE_ALTIVEC_H_HDR is set
   470         list(APPEND EXTRA_CFLAGS "-maltivec")
   505         list(APPEND EXTRA_CFLAGS "-maltivec")
   471         set(SDL_ALTIVEC_BLITTERS 1)
   506         set(SDL_ALTIVEC_BLITTERS 1)
   472         if(HAVE_ALTIVEC_H_HDR)
   507         if(HAVE_ALTIVEC_H_HDR)
   640     set(HAVE_SDL_VIDEO TRUE)
   675     set(HAVE_SDL_VIDEO TRUE)
   641   endif()
   676   endif()
   642 endif()
   677 endif()
   643 
   678 
   644 # Platform-specific options and settings
   679 # Platform-specific options and settings
   645 if(UNIX AND NOT APPLE)
   680 if(EMSCRIPTEN)
       
   681   # Hide noisy warnings that intend to aid mostly during initial stages of porting a new
       
   682   # project. Uncomment at will for verbose cross-compiling -I/../ path info.
       
   683   add_definitions(-Wno-warn-absolute-paths)
       
   684   if(SDL_AUDIO)
       
   685     set(SDL_AUDIO_DRIVER_EMSCRIPTEN 1)
       
   686     file(GLOB EM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/emscripten/*.c)
       
   687     set(SOURCE_FILES ${SOURCE_FILES} ${EM_AUDIO_SOURCES})
       
   688     set(HAVE_SDL_AUDIO TRUE)
       
   689   endif()
       
   690   if(SDL_FILESYSTEM)
       
   691     set(SDL_FILESYSTEM_EMSCRIPTEN 1)
       
   692     file(GLOB EM_FILESYSTEM_SOURCES ${SDL2_SOURCE_DIR}/src/filesystem/emscripten/*.c)
       
   693     set(SOURCE_FILES ${SOURCE_FILES} ${EM_FILESYSTEM_SOURCES})
       
   694     set(HAVE_SDL_FILESYSTEM TRUE)
       
   695   endif()
       
   696   if(SDL_JOYSTICK)
       
   697     set(SDL_JOYSTICK_EMSCRIPTEN 1)
       
   698     file(GLOB EM_JOYSTICK_SOURCES ${SDL2_SOURCE_DIR}/src/joystick/emscripten/*.c)
       
   699     set(SOURCE_FILES ${SOURCE_FILES} ${EM_JOYSTICK_SOURCES})
       
   700     set(HAVE_SDL_JOYSTICK TRUE)
       
   701   endif()
       
   702   if(SDL_POWER)
       
   703     set(SDL_POWER_EMSCRIPTEN 1)
       
   704     file(GLOB EM_POWER_SOURCES ${SDL2_SOURCE_DIR}/src/power/emscripten/*.c)
       
   705     set(SOURCE_FILES ${SOURCE_FILES} ${EM_POWER_SOURCES})
       
   706     set(HAVE_SDL_POWER TRUE)
       
   707   endif()
       
   708   if(SDL_VIDEO)
       
   709     set(SDL_VIDEO_DRIVER_EMSCRIPTEN 1)
       
   710     file(GLOB EM_VIDEO_SOURCES ${SDL2_SOURCE_DIR}/src/video/emscripten/*.c)
       
   711     set(SOURCE_FILES ${SOURCE_FILES} ${EM_VIDEO_SOURCES})
       
   712     set(HAVE_SDL_VIDEO TRUE)
       
   713 
       
   714     #enable gles
       
   715     if(VIDEO_OPENGLES)
       
   716       set(SDL_VIDEO_OPENGL_EGL 1)
       
   717       set(HAVE_VIDEO_OPENGLES TRUE)
       
   718       set(SDL_VIDEO_OPENGL_ES2 1)
       
   719       set(SDL_VIDEO_RENDER_OGL_ES2 1)
       
   720     endif()
       
   721   endif()
       
   722 elseif(UNIX AND NOT APPLE)
   646   if(SDL_AUDIO)
   723   if(SDL_AUDIO)
   647     if(SYSV5 OR SOLARIS OR HPUX)
   724     if(SYSV5 OR SOLARIS OR HPUX)
   648         set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
   725         set(SDL_AUDIO_DRIVER_SUNAUDIO 1)
   649         file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
   726         file(GLOB SUN_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/sun/*.c)
   650         set(SOURCE_FILES ${SOURCE_FILES} ${SUN_AUDIO_SOURCES})
   727         set(SOURCE_FILES ${SOURCE_FILES} ${SUN_AUDIO_SOURCES})
   827       set(HAVE_DIRECTX TRUE)
   904       set(HAVE_DIRECTX TRUE)
   828       # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks
   905       # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks
   829       link_directories($ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH})
   906       link_directories($ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH})
   830       include_directories($ENV{DXSDK_DIR}\\Include)
   907       include_directories($ENV{DXSDK_DIR}\\Include)
   831     endif()
   908     endif()
   832     set(CMAKE_REQUIRED_FLAGS)
   909     set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
   833   endif()
   910   endif()
   834 
   911 
   835   if(SDL_AUDIO)
   912   if(SDL_AUDIO)
   836     set(SDL_AUDIO_DRIVER_WINMM 1)
   913     set(SDL_AUDIO_DRIVER_WINMM 1)
   837     file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c)
   914     file(GLOB WINMM_AUDIO_SOURCES ${SDL2_SOURCE_DIR}/src/audio/winmm/*.c)