]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Add CMakeLists.txt TimePath/cmake
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 19 Mar 2016 04:17:21 +0000 (15:17 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 18 Feb 2018 02:07:56 +0000 (13:07 +1100)
CMakeLists.txt [new file with mode: 0644]
cmake/FindSDL2.cmake [new file with mode: 0644]

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6b9f339
--- /dev/null
@@ -0,0 +1,239 @@
+cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
+project(darkplaces C)
+
+set(DP_CLIENT 1)
+set(DP_SERVER 1)
+
+set(DP_IOS 0)
+
+set(DP_MENU 1)
+set(DP_CD 1)
+set(DP_VIDEO_CAPTURE 1)
+
+set(USE_ZLIB 1)
+set(USE_JPEG 1)
+
+set(SOURCE_COMMON
+        builddate.c
+        bih.c bih.h
+        crypto.c crypto.h
+        cl_collision.c cl_collision.h
+        cl_demo.c
+        cl_dyntexture.c cl_dyntexture.h
+        cl_input.c
+        cl_main.c
+        cl_parse.c
+        cl_particles.c
+        cl_screen.c cl_screen.h
+        cl_video.c cl_video.h
+        clvm_cmds.c clvm_cmds.h
+        cmd.c cmd.h
+        collision.c collision.h
+        common.c common.h
+        console.c console.h
+        csprogs.c csprogs.h
+        curves.c curves.h
+        cvar.c cvar.h
+        dpsoftrast.c dpsoftrast.h
+        dpvsimpledecode.c dpvsimpledecode.h
+        filematch.c
+        fractalnoise.c
+        fs.c fs.h
+        ft2.c ft2.h ft2_defs.h ft2_fontdefs.h
+        utf8lib.c utf8lib.h
+        gl_backend.c gl_backend.h
+        gl_draw.c lhfont.h
+        gl_rmain.c
+        gl_rsurf.c
+        gl_textures.c
+        hmac.c hmac.h
+        host.c
+        host_cmd.c
+        image.c image.h
+        image_png.c image_png.h
+        jpeg.c jpeg.h
+        keys.c keys.h
+        lhnet.c lhnet.h
+        libcurl.c libcurl.h
+        mathlib.c mathlib.h
+        matrixlib.c matrixlib.h
+        mdfour.c mdfour.h
+        meshqueue.c meshqueue.h
+        mod_skeletal_animatevertices_sse.c mod_skeletal_animatevertices_sse.h
+        mod_skeletal_animatevertices_generic.c mod_skeletal_animatevertices_generic.h
+        model_alias.c model_alias.h
+        model_brush.c model_brush.h
+        model_shared.c model_shared.h
+        model_sprite.c model_sprite.h
+        netconn.c netconn.h
+        palette.c palette.h
+        polygon.c polygon.h
+        portals.c portals.h
+        protocol.c protocol.h
+        prvm_cmds.c prvm_cmds.h
+        prvm_edict.c
+        prvm_exec.c
+        r_explosion.c
+        r_lerpanim.c r_lerpanim.h
+        r_lightning.c
+        r_modules.c r_modules.h
+        r_shadow.c r_shadow.h
+        r_sky.c
+        r_sprites.c
+        sbar.c sbar.h
+        sv_demo.c sv_demo.h
+        sv_main.c
+        sv_move.c
+        sv_phys.c
+        sv_user.c
+        svbsp.c svbsp.h
+        svvm_cmds.c
+        sys_shared.c
+        vid_shared.c vid.h
+        view.c
+        wad.c wad.h
+        world.c world.h
+        zone.c zone.h
+        )
+set(SOURCE_CLIENT)
+set(SOURCE_SERVER)
+
+set(DP_DEFS)
+set(DP_DEFS_CLIENT)
+set(DP_DEFS_SERVER)
+
+if (DP_MENU)
+    list(APPEND DP_DEFS -DCONFIG_MENU)
+    list(APPEND SOURCE_COMMON
+            menu.c menu.h
+            mprogdefs.h
+            mvm_cmds.c
+            )
+endif ()
+
+if (DP_CD)
+    list(APPEND DP_DEFS_CLIENT -DCONFIG_CD)
+    list(APPEND SOURCE_CLIENT cd_shared.c cdaudio.h)
+    list(APPEND SOURCE_CLIENT cd_sdl.c)
+endif ()
+
+if (DP_VIDEO_CAPTURE)
+    list(APPEND DP_DEFS_CLIENT -DCONFIG_VIDEO_CAPTURE)
+    list(APPEND SOURCE_CLIENT
+            cap_avi.c cap_avi.h
+            cap_ogg.c cap_ogg.h
+            )
+endif ()
+
+if (WIN32)
+    list(APPEND SOURCE_COMMON conproc.c conproc.h)
+endif ()
+
+if (DP_IOS)
+    list(APPEND DP_DEFS -D__IPHONEOS__)
+    set(CMAKE_OSX_SYSROOT iphoneos)
+    set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)")
+    set(MACOSX_BUNDLE_GUI_IDENTIFIER "org.xonotic\${PRODUCT_NAME:identifier}")
+endif ()
+
+list(APPEND SOURCE_CLIENT vid_sdl.c)
+list(APPEND SOURCE_SERVER vid_null.c)
+
+list(APPEND SOURCE_CLIENT
+        snd_main.c snd_main.h
+        snd_mem.c
+        snd_mix.c
+        snd_ogg.c snd_ogg.h
+        snd_wav.c snd_wav.h
+        )
+list(APPEND SOURCE_CLIENT snd_sdl.c)
+list(APPEND SOURCE_SERVER snd_null.c)
+
+list(APPEND SOURCE_COMMON sys.h)
+list(APPEND SOURCE_CLIENT sys_sdl.c)
+if (WIN32)
+    list(APPEND SOURCE_SERVER sys_win.c)
+else ()
+    list(APPEND SOURCE_SERVER sys_linux.c)
+endif ()
+
+list(APPEND SOURCE_COMMON thread.h)
+list(APPEND SOURCE_CLIENT thread_sdl.c)
+list(APPEND SOURCE_SERVER thread_null.c)
+
+if (DP_SERVER)
+    add_executable(darkplaces-dedicated WIN32 MACOSX_BUNDLE ${SOURCE_SERVER} ${SOURCE_COMMON})
+endif ()
+if (DP_CLIENT)
+    add_executable(darkplaces WIN32 MACOSX_BUNDLE ${SOURCE_CLIENT} ${SOURCE_COMMON})
+endif ()
+
+if (DP_SERVER)
+    target_compile_definitions(darkplaces-dedicated PRIVATE ${DP_DEFS} ${DP_DEFS_SERVER})
+endif ()
+if (DP_CLIENT)
+    target_compile_definitions(darkplaces PRIVATE ${DP_DEFS} ${DP_DEFS_CLIENT})
+endif ()
+
+set(LIBS_COMMON ${CMAKE_DL_LIBS})
+if (TARGET d0_blind_id)
+    list(APPEND LIBS_COMMON d0_blind_id)
+    # list(APPEND DP_DEFS -DLINK_TO_CRYPTO)
+endif ()
+if (UNIX)
+    list(APPEND LIBS_COMMON m)
+endif ()
+if (WIN32)
+    list(APPEND LIBS_COMMON ws2_32 winmm)
+endif ()
+if (APPLE)
+    list(APPEND LIBS_COMMON "-framework IOKit")
+endif ()
+
+function(target_requires_zlib target)
+    if (NOT USE_ZLIB)
+        return()
+    endif ()
+    find_package(ZLIB REQUIRED)
+    target_include_directories(${target} PRIVATE ${ZLIB_INCLUDE_DIRS})
+    target_link_libraries(${target} PRIVATE ${ZLIB_LIBRARIES})
+    target_compile_definitions(${target} PRIVATE -DLINK_TO_ZLIB)
+endfunction()
+
+function(target_requires_jpeg target)
+    if (NOT USE_JPEG)
+        return()
+    endif ()
+    find_package(JPEG REQUIRED)
+    if (NOT JPEG_INCLUDE_DIRS)
+        set(JPEG_INCLUDE_DIRS ${JPEG_INCLUDE_DIR})
+    endif ()
+    target_include_directories(${target} PRIVATE ${JPEG_INCLUDE_DIRS})
+    target_link_libraries(${target} PRIVATE ${JPEG_LIBRARIES})
+    target_compile_definitions(${target} PRIVATE -DLINK_TO_LIBJPEG)
+endfunction()
+
+if (DP_SERVER)
+    target_link_libraries(darkplaces-dedicated PRIVATE ${LIBS_COMMON})
+    target_requires_zlib(darkplaces-dedicated)
+endif ()
+
+if (DP_CLIENT)
+    target_link_libraries(darkplaces PRIVATE ${LIBS_COMMON})
+    target_requires_zlib(darkplaces)
+
+    find_package(SDL2 REQUIRED)
+    if (NOT SDL2_INCLUDE_DIRS)
+        set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR})
+    endif ()
+    if (NOT SDL2_LIBRARIES)
+        set(SDL2_LIBRARIES ${SDL2_LIBRARY})
+    endif ()
+    target_include_directories(darkplaces PRIVATE ${SDL2_INCLUDE_DIRS})
+    target_link_libraries(darkplaces PRIVATE ${SDL2_LIBRARIES})
+
+    if (NOT DP_IOS)
+        target_requires_jpeg(darkplaces)
+    endif ()
+endif ()
diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake
new file mode 100644 (file)
index 0000000..4b52704
--- /dev/null
@@ -0,0 +1,180 @@
+# Locate SDL2 library
+# This module defines
+# SDL2_LIBRARY, the name of the library to link against
+# SDL2_FOUND, if false, do not try to link to SDL2
+# SDL2_INCLUDE_DIR, where to find SDL.h
+#
+# This module responds to the the flag:
+# SDL2_BUILDING_LIBRARY
+# If this is defined, then no SDL2_main will be linked in because
+# only applications need main().
+# Otherwise, it is assumed you are building an application and this
+# module will attempt to locate and set the the proper link flags
+# as part of the returned SDL2_LIBRARY variable.
+#
+# Don't forget to include SDL2main.h and SDL2main.m your project for the
+# OS X framework based version. (Other versions link to -lSDL2main which
+# this module will try to find on your behalf.) Also for OS X, this
+# module will automatically add the -framework Cocoa on your behalf.
+#
+#
+# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration
+# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library
+# (SDL2.dll, libsdl2.so, SDL2.framework, etc).
+# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again.
+# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value
+# as appropriate. These values are used to generate the final SDL2_LIBRARY
+# variable, but when these values are unset, SDL2_LIBRARY does not get created.
+#
+#
+# $SDL2DIR is an environment variable that would
+# correspond to the ./configure --prefix=$SDL2DIR
+# used in building SDL2.
+# l.e.galup  9-20-02
+#
+# Modified by Eric Wing.
+# Added code to assist with automated building by using environmental variables
+# and providing a more controlled/consistent search behavior.
+# Added new modifications to recognize OS X frameworks and
+# additional Unix paths (FreeBSD, etc).
+# Also corrected the header search path to follow "proper" SDL2 guidelines.
+# Added a search for SDL2main which is needed by some platforms.
+# Added a search for threads which is needed by some platforms.
+# Added needed compile switches for MinGW.
+#
+# On OSX, this will prefer the Framework version (if found) over others.
+# People will have to manually change the cache values of
+# SDL2_LIBRARY to override this selection or set the CMake environment
+# CMAKE_INCLUDE_PATH to modify the search paths.
+#
+# Note that the header path has changed from SDL2/SDL.h to just SDL.h
+# This needed to change because "proper" SDL2 convention
+# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
+# reasons because not all systems place things in SDL2/ (see FreeBSD).
+#
+# Ported by Johnny Patterson. This is a literal port for SDL2 of the FindSDL.cmake
+# module with the minor edit of changing "SDL" to "SDL2" where necessary. This
+# was not created for redistribution, and exists temporarily pending official
+# SDL2 CMake modules.
+
+#=============================================================================
+# Copyright 2003-2009 Kitware, Inc.
+#
+# Distributed under the OSI-approved BSD License (the "License");
+# see accompanying file Copyright.txt for details.
+#
+# This software is distributed WITHOUT ANY WARRANTY; without even the
+# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the License for more information.
+#=============================================================================
+# (To distribute this file outside of CMake, substitute the full
+#  License text for the above reference.)
+
+FIND_PATH(SDL2_INCLUDE_DIR SDL.h
+        HINTS
+        $ENV{SDL2DIR}
+        PATH_SUFFIXES include/SDL2 include
+        PATHS
+        ~/Library/Frameworks
+        /Library/Frameworks
+        /usr/local/include/SDL2
+        /usr/include/SDL2
+        /sw # Fink
+        /opt/local # DarwinPorts
+        /opt/csw # Blastwave
+        /opt
+        )
+#MESSAGE("SDL2_INCLUDE_DIR is ${SDL2_INCLUDE_DIR}")
+
+FIND_LIBRARY(SDL2_LIBRARY_TEMP
+        NAMES SDL2
+        HINTS
+        $ENV{SDL2DIR}
+        PATH_SUFFIXES lib64 lib
+        PATHS
+        /sw
+        /opt/local
+        /opt/csw
+        /opt
+        )
+
+#MESSAGE("SDL2_LIBRARY_TEMP is ${SDL2_LIBRARY_TEMP}")
+
+IF(NOT SDL2_BUILDING_LIBRARY)
+    IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
+        # Non-OS X framework versions expect you to also dynamically link to
+        # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms
+        # seem to provide SDL2main for compatibility even though they don't
+        # necessarily need it.
+        FIND_LIBRARY(SDL2MAIN_LIBRARY
+                NAMES SDL2main
+                HINTS
+                $ENV{SDL2DIR}
+                PATH_SUFFIXES lib64 lib
+                PATHS
+                /sw
+                /opt/local
+                /opt/csw
+                /opt
+                )
+    ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
+ENDIF(NOT SDL2_BUILDING_LIBRARY)
+
+# SDL2 may require threads on your system.
+# The Apple build may not need an explicit flag because one of the
+# frameworks may already provide it.
+# But for non-OSX systems, I will use the CMake Threads package.
+IF(NOT APPLE)
+    FIND_PACKAGE(Threads)
+ENDIF(NOT APPLE)
+
+# MinGW needs an additional library, mwindows
+# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows
+# (Actually on second look, I think it only needs one of the m* libraries.)
+IF(MINGW)
+    SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
+ENDIF(MINGW)
+
+SET(SDL2_FOUND "NO")
+IF(SDL2_LIBRARY_TEMP)
+    # For SDL2main
+    IF(NOT SDL2_BUILDING_LIBRARY)
+        IF(SDL2MAIN_LIBRARY)
+            SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP})
+        ENDIF(SDL2MAIN_LIBRARY)
+    ENDIF(NOT SDL2_BUILDING_LIBRARY)
+
+    # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa.
+    # CMake doesn't display the -framework Cocoa string in the UI even
+    # though it actually is there if I modify a pre-used variable.
+    # I think it has something to do with the CACHE STRING.
+    # So I use a temporary variable until the end so I can set the
+    # "real" variable in one-shot.
+    IF(APPLE)
+        SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa")
+    ENDIF(APPLE)
+
+    # For threads, as mentioned Apple doesn't need this.
+    # In fact, there seems to be a problem if I used the Threads package
+    # and try using this line, so I'm just skipping it entirely for OS X.
+    IF(NOT APPLE)
+        SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT})
+    ENDIF(NOT APPLE)
+
+    # For MinGW library
+    IF(MINGW)
+        SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
+    ENDIF(MINGW)
+
+    # Set the final string here so the GUI reflects the final state.
+    SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
+    # Set the temp variable to INTERNAL so it is not seen in the CMake GUI
+    SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
+
+    SET(SDL2_FOUND "YES")
+ENDIF(SDL2_LIBRARY_TEMP)
+
+INCLUDE(FindPackageHandleStandardArgs)
+
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2
+        REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)