Skip to content

Commit

Permalink
SDL2 port
Browse files Browse the repository at this point in the history
  • Loading branch information
tesch1 authored and mgerhardy committed Jul 26, 2016
1 parent c95d61d commit 2bdef57
Show file tree
Hide file tree
Showing 24 changed files with 2,949 additions and 162 deletions.
129 changes: 120 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
project(TurboBadger)
project(TurboBadger CXX)
cmake_minimum_required(VERSION 2.8)

option(TB_BUILD_DEMO "Build the Demo application. Depends on glfw." ON)
option(TB_BUILD_DEMO_GLFW "Build the Demo application. Depends on glfw." ON)
option(TB_BUILD_DEMO_SDL "Build the Demo application. Depends on SDL." OFF)
option(TB_DEMO_IN_SRC "Build the demo application to the source directory" ON)
option(TB_DEBUG_POSTFIX "Add _d postfix for debug builds" OFF)
option(TB_GENERATE_CONFIG "Generate the tb_config.h file from provided parameters in cmake. Default Off" OFF)
Expand All @@ -13,20 +14,101 @@ option(TB_FONT_RENDERER_STB "Enable to support truetype fonts using stb_truetype
option(TB_IMAGE_LOADER_STB "Enable to support image loading using stb_image.c" OFF)
option(TB_RENDERER_BATCHER "Enable to get TBRendererBatcher" ON)
option(TB_RENDERER_GL "Enable renderer using OpenGL. This renderer depends on TB_RENDERER_BATCHER." ON)
option(TB_RENDERER_GLES_1 "Enable renderer using OpenGL ES. This renderer depends on TB_RENDERER_GL." OFF)
option(TB_RENDERER_GLES_1 "Enable renderer using OpenGL ES1. This renderer depends on TB_RENDERER_GL." OFF)
option(TB_RENDERER_GLES_2 "Enable renderer using OpenGL ES2. This renderer depends on TB_RENDERER_GL." OFF)
option(TB_RENDERER_GL3 "Enable renderer using OpenGL 3.2. This renderer depends on TB_RENDERER_GL." OFF)
option(TB_IMAGE "Enable support for TBImage, TBImageManager, TBImageWidget." ON)

# Runtime/subsystem configurations
# Needs further work
#option(TB_FILE_POSIX "" ON)
#option(TB_SYSTEM "" OFF)
#option(TB_TARGET "" OFF)
include(CMakeDependentOption)

# could try to auto-detect these
cmake_dependent_option(TB_SYSTEM_LINUX "Set System to Linux" OFF
"NOT TB_SYSTEM_WINDOWS;NOT TB_SYSTEM_ANDROID;NOT TB_SYSTEM_MACOSX" OFF)
cmake_dependent_option(TB_SYSTEM_ANDROID "Set System to Android" OFF
"NOT TB_SYSTEM_LINUX;NOT TB_SYSTEM_WINDOWS;NOT TB_SYSTEM_MACOSX" OFF)
cmake_dependent_option(TB_SYSTEM_WINDOWS "Set System to Windows" OFF
"NOT TB_SYSTEM_LINUX;NOT TB_SYSTEM_ANDROID;NOT TB_SYSTEM_MACOSX" OFF)
cmake_dependent_option(TB_SYSTEM_MACOSX "Set System to MacOSX" OFF
"NOT TB_SYSTEM_LINUX;NOT TB_SYSTEM_ANDROID;NOT TB_SYSTEM_WINDOWS" OFF)

cmake_dependent_option(TB_CLIPBOARD_DUMMY "Clipboard Dummy" OFF
"NOT TB_CLIPBOARD_GLFW; NOT TB_CLIPBOARD_WINDOWS; NOT TB_CLIPBOARD_SDL" OFF)
cmake_dependent_option(TB_CLIPBOARD_GLFW "Clipboard GLFW" OFF
"NOT TB_CLIPBOARD_DUMMY; NOT TB_CLIPBOARD_WINDOWS; NOT TB_CLIPBOARD_SDL" OFF)
cmake_dependent_option(TB_CLIPBOARD_WINDOWS "Clipboard WINDOWS" OFF
"NOT TB_CLIPBOARD_GLFW; NOT TB_CLIPBOARD_DUMMY; NOT TB_CLIPBOARD_SDL" OFF)
cmake_dependent_option(TB_CLIPBOARD_SDL "Clipboard SDL" OFF
"NOT TB_CLIPBOARD_GLFW; NOT TB_CLIPBOARD_WINDOWS; NOT TB_CLIPBOARD_DUMMY" OFF)

# Runtime/subsystem configurations
if(TB_BUILD_DEMO_GLFW)
set(TB_CLIPBOARD_GLFW ON)
set(TB_IMAGE_LOADER_STB ON)
if(TB_BUILD_DEMO_SDL)
message(FATAL_ERROR "Can not specify both TB_BUILD_DEMO_GLFW and TB_BUILD_DEMO_SDL")
endif(TB_BUILD_DEMO_SDL)
elseif(TB_BUILD_DEMO_SDL)
set(TB_CLIPBOARD_SDL ON)
set(TB_SYSTEM_SDL ON)
set(TB_IMAGE_LOADER_STB ON)
endif(TB_BUILD_DEMO_GLFW)

# System defaults
if(TB_SYSTEM_ANDROID)
set(TB_SYSTEM_CONFIG "#define TB_SYSTEM_ANDROID")
set(TB_CLIPBOARD_CONFIG "#define TB_CLIPBOARD_DUMMY")
endif()
if(TB_SYSTEM_LINUX)
set(TB_FILE_CONFIG "#define TB_FILE_POSIX")
set(TB_SYSTEM_CONFIG "#define TB_SYSTEM_LINUX")
set(TB_TARGET_CONFIG "#define TB_TARGET_LINUX")
set(TB_CLIPBOARD_CONFIG "#define TB_CLIPBOARD_GLFW")
endif()
if(TB_SYSTEM_MACOSX)
set(TB_FILE_CONFIG "#define TB_FILE_POSIX")
set(TB_SYSTEM_CONFIG "#define TB_SYSTEM_LINUX")
set(TB_TARGET_CONFIG "#define TB_TARGET_MACOSX")
set(TB_CLIPBOARD_CONFIG "#define TB_CLIPBOARD_GLFW")
endif()
if(TB_SYSTEM_WINDOWS)
set(TB_FILE_CONFIG "#define TB_FILE_POSIX")
set(TB_SYSTEM_CONFIG "#define TB_SYSTEM_WINDOWS")
set(TB_TARGET_CONFIG "#define TB_TARGET_WINDOWS")
endif()
if(TB_SYSTEM_SDL)
set(TB_FILE_CONFIG "#define TB_FILE_POSIX")
set(TB_SYSTEM_CONFIG "#define TB_SYSTEM_SDL")
set(TB_TARGET_CONFIG "#define TB_TARGET_CUSTOM")
set(TB_CLIPBOARD_CONFIG "#define TB_CLIPBOARD_SDL")
endif()

# Clipboard
if(TB_CLIPBOARD_DUMMY)
set(TB_CLIPBOARD_CONFIG "#define TB_CLIPBOARD_DUMMY")
endif()
if(TB_CLIPBOARD_GLFW)
set(TB_CLIPBOARD_CONFIG "#define TB_CLIPBOARD_GLFW")
endif()
if(TB_CLIPBOARD_WINDOWS)
set(TB_CLIPBOARD_CONFIG "#define TB_CLIPBOARD_WINDOWS")
endif()
if(TB_CLIPBOARD_SDL)
set(TB_CLIPBOARD_CONFIG "#define TB_CLIPBOARD_SDL")
endif()

if(TB_FILE_POSIX)
set(TB_FILE_CONFIG "#define TB_FILE_POSIX")
endif()
if(TB_FILE_SDL)
set(TB_FILE_CONFIG "#define TB_FILE_SDL")
endif()
if(TB_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX _d)
endif()

if(TB_FONT_RENDERER_TBBF)
set(TB_FONT_RENDERER_TBBF_CONFIG "#define TB_FONT_RENDERER_TBBF")
endif()
Expand All @@ -49,12 +131,19 @@ endif()
if(TB_RENDERER_GLES_1)
set(TB_RENDERER_GLES_1_CONFIG "#define TB_RENDERER_GLES_1")
endif()
if(TB_RENDERER_GLES_2)
set(TB_RENDERER_GLES_2_CONFIG "#define TB_RENDERER_GLES_2")
endif()
if(TB_RENDERER_GL3)
set(TB_RENDERER_GL3_CONFIG "#define TB_RENDERER_GL3")
endif()
if(TB_IMAGE)
set(TB_IMAGE_CONFIG "#define TB_IMAGE")
endif()

configure_file(tb_config.h.in src/tb/config.h)

configure_file(tb_config.h.in src/tb/tb_config.h)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/src/tb)

if(${CMAKE_CXX_COMPILER_ID} MATCHES "GNU" OR ${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x -fno-exceptions -fno-rtti -Wall -Wextra -Wno-unused-parameter")
endif()
Expand All @@ -74,14 +163,30 @@ if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
endif(MSVC)

if(TB_SYSTEM_SDL)
include(FindPkgConfig)
pkg_search_module(SDL2 REQUIRED sdl2)
set(SDL2_INCLUDE_DIRS "${SDL2_INCLUDE_DIRS}")
include_directories(${SDL2_INCLUDE_DIRS})
link_directories(${SDL2_LIBRARY_DIRS})
endif(TB_SYSTEM_SDL)

if(EMSCRIPTEN)
set(CMAKE_EXECUTABLE_SUFFIX ".html")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -Oz") # optional
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_SDL=2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s NO_EXIT_RUNTIME=1")
endif(EMSCRIPTEN)

# Add TurboBadgerLib project
include_directories("${PROJECT_SOURCE_DIR}/src/tb")
add_subdirectory(src/tb)

# Add Demo project
if(TB_BUILD_DEMO)
if(TB_BUILD_DEMO_GLFW OR TB_BUILD_DEMO_SDL)
add_subdirectory(Demo)
endif(TB_BUILD_DEMO)
endif(TB_BUILD_DEMO_GLFW OR TB_BUILD_DEMO_SDL)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/tb
DESTINATION include
Expand All @@ -91,3 +196,9 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/tb
PATTERN "test files" EXCLUDE
PATTERN "*.h"
)

# Generate Doxygen documentation
add_custom_target (doc
COMMAND doxygen doc/Doxyfile
# COMMAND open doc/html/index.html
)
117 changes: 111 additions & 6 deletions Demo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if(TB_DEMO_IN_SRC)
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR})
endif()

if(TB_BUILD_DEMO_GLFW)
if(CMAKE_SYSTEM MATCHES "Windows")
add_definitions(-DGLFW_EXPOSE_NATIVE_WIN32)
add_definitions(-DGLFW_EXPOSE_NATIVE_WGL)
Expand All @@ -21,13 +22,27 @@ set(GLFW_INSTALL OFF)
# Add sources
set(LOCAL_SRCS "")
aux_source_directory(./demo01 LOCAL_SRCS)
aux_source_directory(./platform LOCAL_SRCS)
set(LOCAL_SRCS ${LOCAL_SRCS}
./platform/port_glfw.cpp
./platform/glfw_extra_linux.cpp
./platform/Application.cpp)
include_directories(".")

# Add glfw project
target_include_directories(TurboBadgerLib PUBLIC "thirdparty/glfw/include")
include_directories("thirdparty/glfw/include")
add_subdirectory(thirdparty/glfw)
# Add glfw and gl libs on MacOSX
if(APPLE)
find_library(GLFW_LIBRARIES glfw )
find_library(OPENGL_LIBRARY OpenGL )
set(EXTRA_LIBS ${EXTRA_LIBS} ${OPENGL_LIBRARY} ${GLFW_LIBRARIES})
find_path(GLFW_INCLUDE_DIRS GLFW/glfw3.h)
include_directories(${GLFW_INCLUDE_DIRS})
endif(APPLE)

if(NOT GLFW_LIBRARIES)
target_include_directories(TurboBadgerLib PUBLIC "thirdparty/glfw/include")
include_directories("thirdparty/glfw/include")
add_subdirectory(thirdparty/glfw)
set(EXTRA_LIBS ${EXTRA_LIBS} glfw)
endif(NOT GLFW_LIBRARIES)

# Platform specific
if(CMAKE_COMPILER_IS_MINGW)
Expand All @@ -36,8 +51,98 @@ if(CMAKE_COMPILER_IS_MINGW)
endif(CMAKE_COMPILER_IS_MINGW)

add_executable(TurboBadgerDemo WIN32 ${LOCAL_SRCS})
target_link_libraries(TurboBadgerDemo TurboBadgerLib ${EXTRA_LIBS} glfw ${GLFW_LIBRARIES})
target_link_libraries(TurboBadgerDemo TurboBadgerLib ${EXTRA_LIBS})
install(TARGETS TurboBadgerDemo
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

endif(TB_BUILD_DEMO_GLFW)

if(TB_BUILD_DEMO_SDL)

set(LOCAL_SRCS "")
aux_source_directory(./demo01 LOCAL_SRCS)
set(LOCAL_SRCS ${LOCAL_SRCS}
./platform/port_sdl.cpp
./platform/Application.cpp)
include_directories(".")

if(EMSCRIPTEN)
set(CMAKE_EXECUTABLE_SUFFIX ".html")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Os -Oz") # optional
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s USE_SDL=2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s NO_EXIT_RUNTIME=1")
# default skin resources
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --preload-file /tmp/resources@/resources")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --preload-file /tmp/demo01@Demo/demo01")
# test files
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --preload-file ../src/tb/tests/test_tb_parser.tb.txt@/")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --preload-file ../src/tb/tests/test_tb_parser_included.tb.txt@/")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --preload-file ../src/tb/tests/test_tb_parser_definitions.tb.txt@/")
elseif(APPLE)
find_package(OpenGL REQUIRED)
find_library(SDL2_LIBRARIES SDL2)
find_path(SDL2_INCLUDE_DIRS SDL.h)
set(EXTRA_LIBS ${EXTRA_LIBS} ${OPENGL_LIBRARY} ${SDL2_LIBRARIES} )
else(EMSCRIPTEN)
set(_SEARCH_PATHS
~/Library/Frameworks
/Library/Frameworks
/usr/local
/usr
/sw # Fink
/opt/local # DarwinPorts
/opt/csw # Blastwave
/opt
$ENV{HOME}/local/include
)

find_library(OPENGL_LIBRARY GL PATHS "/usr/lib64/nvidia" )

find_package(PkgConfig QUIET)
if (PKG_CONFIG_FOUND)
pkg_check_modules(SDL2 "")
endif()
find_path(SDL_INCLUDE_DIRS
NAMES SDL.h
HINTS ENV SDL2DIR
PATH_SUFFIXES include include/SDL2 SDL2
PATHS
${SDL2_INCLUDE_DIRS}
${_SEARCH_PATHS}
)
find_library(SDL_LIBRARIES
NAMES sdl2 SDL2 ${SDL2_LIBRARIES}
HINTS ENV SDL2DIR "$ENV{HOME}/local/lib"
PATH_SUFFIXES lib64 lib
PATHS
${SDL2_LIBRARY_DIRS}
${_SEARCH_PATHS}
)
include_directories(${SDL_INCLUDE_DIRS})
set(EXTRA_LIBS ${EXTRA_LIBS} ${OPENGL_LIBRARY} ${SDL_LIBRARIES} )
endif(EMSCRIPTEN)

# Platform specific
if(CMAKE_COMPILER_IS_MINGW)
# Avoid dll dependencies by linking statically.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++ -static")
endif(CMAKE_COMPILER_IS_MINGW)

add_executable(TurboBadgerDemoSDL WIN32 ${LOCAL_SRCS})
target_link_libraries(TurboBadgerDemoSDL TurboBadgerLib ${EXTRA_LIBS})
install(TARGETS TurboBadgerDemoSDL
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

if(EMSCRIPTEN)
add_custom_command(TARGET TurboBadgerDemoSDL
PRE_LINK
# COMMAND rm -r /tmp/resources /tmp/demo01
COMMAND rsync -av --exclude='*.psd' ../resources /tmp/resources
COMMAND rsync -av --include='*/' --include='*.txt' --include='*.png' --exclude='*' demo01 /tmp/demo01 )
endif(EMSCRIPTEN)

endif(TB_BUILD_DEMO_SDL)
Loading

0 comments on commit 2bdef57

Please sign in to comment.