Skip to content

Commit

Permalink
Initial implementation of "modern" CMake system.
Browse files Browse the repository at this point in the history
- the option of configuring tb_config.h via the Cmake options, optionally setting some
- Fixed TB overriding target paths and made it optional for demo. Building in source dir is bad.
- Provides proper install targets
  • Loading branch information
Walter Pearce committed Jan 11, 2016
1 parent 084a3f3 commit e6e9bd6
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 4 deletions.
63 changes: 62 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,60 @@ project(TurboBadger)
cmake_minimum_required(VERSION 2.8)

option(TB_BUILD_DEMO "Build the Demo application. Depends on glfw." ON)
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)

if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# Configure file options
option(TB_FONT_RENDERER_TBBF "Enable to support TBBF fonts (Turbo Badger Bitmap Fonts)" ON)
option(TB_FONT_RENDERER_FREETYPE "Enable FreeType TB Font. Requires FreeType" OFF)
option(TB_FONT_RENDERER_STB "Enable to support truetype fonts using stb_truetype.h WARNING VERY UNSAFE" OFF)
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_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)


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()
if(TB_FONT_RENDERER_FREETYPE)
set(TB_FONT_RENDERER_FREETYPE_CONFIG "#define TB_FONT_RENDERER_FREETYPE")
find_package(FreeType REQUIRED)
endif()
if(TB_FONT_RENDERER_STB)
set(TB_FONT_RENDERER_STB_CONFIG "#define TB_FONT_RENDERER_STB")
endif()
if(TB_IMAGE_LOADER_STB)
set(TB_IMAGE_LOADER_STB_CONFIG "#define TB_FONT_RENDERER_STB")
endif()
if(TB_RENDERER_BATCHER)
set(TB_RENDERER_BATCHER_CONFIG "#define TB_RENDERER_BATCHER")
endif()
if(TB_RENDERER_GL)
set(TB_RENDERER_GL_CONFIG "#define TB_RENDERER_GL")
endif()
if(TB_RENDERER_GLES_1)
set(TB_RENDERER_GLES_1_CONFIG "#define TB_RENDERER_GLES_1")
endif()
if(TB_IMAGE)
set(TB_IMAGE_CONFIG "#define TB_IMAGE")
endif()

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

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 @@ -30,3 +82,12 @@ add_subdirectory(src/tb)
if(TB_BUILD_DEMO)
add_subdirectory(Demo)
endif(TB_BUILD_DEMO)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/tb
DESTINATION include
PATTERN "*.cpp" EXCLUDE
PATTERN "*.mm" EXCLUDE
PATTERN "*.txt" EXCLUDE
PATTERN "test files" EXCLUDE
PATTERN "*.h"
)
12 changes: 9 additions & 3 deletions Demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Use project source dir for demo output. We have to set
# the release and debug specific defines too, for MSVC.
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR})
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR})
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR})
if(TB_DEMO_IN_SRC)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR})
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR})
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR})
endif()

if(CMAKE_SYSTEM MATCHES "Windows")
add_definitions(-DGLFW_EXPOSE_NATIVE_WIN32)
Expand Down Expand Up @@ -35,3 +37,7 @@ endif(CMAKE_COMPILER_IS_MINGW)

add_executable(TurboBadgerDemo WIN32 ${LOCAL_SRCS})
target_link_libraries(TurboBadgerDemo TurboBadgerLib ${EXTRA_LIBS} glfw ${GLFW_LIBRARIES})
install(TARGETS TurboBadgerDemo
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
6 changes: 6 additions & 0 deletions src/tb/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ aux_source_directory(tests LOCAL_SRCS)
aux_source_directory(utf8 LOCAL_SRCS)

add_library(TurboBadgerLib ${LOCAL_SRCS})

install(TARGETS TurboBadgerLib
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

121 changes: 121 additions & 0 deletions tb_config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// ================================================================================
// == This file is a part of Turbo Badger. (C) 2011-2014, Emil Segerås ==
// == See tb_core.h for more information. ==
// ================================================================================
//
// This file contains defines for the default configuration of Turbo Badger.
// You may change these here, but to make upgrades easier it's better to create a
// copy of this file in a include path that is searched before Turbo Badger during
// build (F.ex the solution directory for Visual Studio).

#ifndef TB_CONFIG_H
#define TB_CONFIG_H

/** Enable for some handy runtime debugging, enabled by modifying
the various settings in g_tb_debug. A settings window can be
shown by calling ShowDebugInfoSettingsWindow. */
#ifndef NDEBUG
#define TB_RUNTIME_DEBUG_INFO
#endif

#ifndef NDEBUG
/** Enable compilation of unit tests. */
#define TB_UNIT_TESTING
#endif

/** Enable if the focus state should automatically be set on edit fields even
when using the pointer. It is normally set only while moving focus by keyboard. */
//#define TB_ALWAYS_SHOW_EDIT_FOCUS

/** Enable to use premultiplied alpha. Warning: This is not handled everywhere in
the default backends, so consider it an experimental and unfinished feature! */
//#define TB_PREMULTIPLIED_ALPHA

/** Enable to support TBBF fonts (Turbo Badger Bitmap Fonts) */
${TB_FONT_RENDERER_TBBF_CONFIG}

/** Enable to support truetype fonts using freetype. */
${TB_FONT_RENDERER_FREETYPE_CONFIG}

/** Enable to support truetype fonts using stb_truetype.h (http://nothings.org/).
It's a *very unsafe* font library. Use only with fonts distributed with your
app, that you know work! Freetype generates much prettier glyphs (using
hinting) but is a lot larger. This implementation is kept here as alternative
as long as it compiles. */
${TB_FONT_RENDERER_STB_CONFIG}

/** Enable to support image loading using stb_image.c (http://nothings.org/).
It's a *very unsafe* image library. Use only with images distributed with
your app, that you know work! */
${TB_IMAGE_LOADER_STB_CONFIG}

/** Enable to get TBRendererBatcher, an helper class for renderers that
implements batching of draw operations. Subclasses of TBRendererBatcher
can be done super easily, and still do batching. */
${TB_RENDERER_BATCHER_CONFIG}

/** Enable renderer using OpenGL. This renderer depends on TB_RENDERER_BATCHER.
It is using GL version 1.1, */
${TB_RENDERER_GL_CONFIG}

/** Enable renderer using OpenGL ES. This renderer depends on TB_RENDERER_GL.
It is using GL ES version 1. */
${TB_RENDERER_GLES_1_CONFIG}

/** The width of the font glyph cache. Must be a power of two. */
#define TB_GLYPH_CACHE_WIDTH 512

/** The height of the font glyph cache. Must be a power of two. */
#define TB_GLYPH_CACHE_HEIGHT 512

// == Optional features ===========================================================

/** Enable support for TBImage, TBImageManager, TBImageWidget. */
${TB_IMAGE_CONFIG}

// == Additional configuration of platform implementations ========================

/** Define for posix implementation of TBFile. */
//#define TB_FILE_POSIX

/** Defines for implementations of TBClipboard. */
//#define TB_CLIPBOARD_DUMMY // Cross platform. Not integrating with the OS.
//#define TB_CLIPBOARD_GLFW // Cross platform using glfw API.
//#define TB_CLIPBOARD_WINDOWS

/** Defines for implementations of TBSystem. */
//#define TB_SYSTEM_LINUX
//#define TB_SYSTEM_WINDOWS
//#define TB_SYSTEM_ANDROID

/** Defines for additional platform specific issues. */
//#define TB_TARGET_WINDOWS
//#define TB_TARGET_MACOSX
//#define TB_TARGET_LINUX

// == Setting some defaults for platform implementations ==========================
// Updated to only define a platform if a target is defined
// This allows us to build for different targets than the host compiling OS
#if !defined(TB_TARGET_WINDOWS) && !defined(TB_TARGET_LINUX) && !defined(TB_TARGET_MACOSX)
#if defined(ANDROID) || defined(__ANDROID__)
#define TB_SYSTEM_ANDROID
#define TB_CLIPBOARD_DUMMY
#elif defined(__linux) || defined(__linux__)
#define TB_FILE_POSIX
#define TB_TARGET_LINUX
#define TB_SYSTEM_LINUX
#define TB_CLIPBOARD_GLFW
#elif MACOSX
#define TB_FILE_POSIX
#define TB_TARGET_MACOSX
#define TB_SYSTEM_LINUX
#define TB_CLIPBOARD_GLFW
#elif defined(_WIN32) || defined(__WIN32__) || defined(__WINDOWS__)
#define TB_FILE_POSIX
#define TB_TARGET_WINDOWS
#define TB_CLIPBOARD_WINDOWS
#define TB_SYSTEM_WINDOWS
#endif
#endif

#endif // TB_CONFIG_H

0 comments on commit e6e9bd6

Please sign in to comment.