Skip to content

Commit

Permalink
Make the framework subdir a separate build unit under cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyH committed Apr 7, 2016
1 parent a70cf1e commit bff5904
Show file tree
Hide file tree
Showing 27 changed files with 262 additions and 257 deletions.
11 changes: 3 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ PROJECT(OpenApoc CXX C)
# check cmake version
CMAKE_MINIMUM_REQUIRED(VERSION 3.1)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/framework/cmake/")

include(framework)
add_subdirectory(library)
add_subdirectory(framework)
add_subdirectory(tools)

# check compiler
INCLUDE(CheckCXXCompilerFlag)
Expand Down Expand Up @@ -55,8 +54,6 @@ AUX_SOURCE_DIRECTORY(game/tileview sources)
AUX_SOURCE_DIRECTORY(game/resources sources)
AUX_SOURCE_DIRECTORY(game/ufopaedia sources)
AUX_SOURCE_DIRECTORY(game/debugtools sources)
AUX_SOURCE_DIRECTORY(shaders sources)
AUX_SOURCE_DIRECTORY(transitions sources)
AUX_SOURCE_DIRECTORY(forms sources)


Expand All @@ -66,10 +63,8 @@ SET(REQUIRED_TINYXML_LIBRARIES tinyxml2)
ADD_EXECUTABLE(${CMAKE_PROJECT_NAME} framework/main.cpp ${sources}
${FRAMEWORK_SOURCES})

target_link_libraries(${CMAKE_PROJECT_NAME} ${Boost_LIBRARIES})
target_link_libraries(${CMAKE_PROJECT_NAME} OpenApoc_Library)
target_include_directories(${CMAKE_PROJECT_NAME} SYSTEM PUBLIC ${Boost_INCLUDE_DIRS})
# Assume all targets using cmake have pthreads
target_link_libraries(${CMAKE_PROJECT_NAME} OpenApoc_Framework)
target_compile_definitions(${CMAKE_PROJECT_NAME} PUBLIC PTHREADS_AVAILABLE)

set_property(TARGET OpenApoc PROPERTY CXX_STANDARD 11)
Expand Down
4 changes: 2 additions & 2 deletions forms/checkbox.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "library/sp.h"

#include "forms/checkbox.h"
#include "framework/framework.h"
#include "library/sp.h"
#include <tinyxml2.h>

namespace OpenApoc
{
Expand Down
4 changes: 2 additions & 2 deletions forms/control.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "library/sp.h"

#include "forms/control.h"
#include "forms/forms.h"
#include "framework/framework.h"
#include "library/sp.h"
#include <tinyxml2.h>

namespace OpenApoc
{
Expand Down
10 changes: 6 additions & 4 deletions forms/control.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@

#pragma once
#include "library/sp.h"

#include "forms/forms_enums.h"
#include "framework/font.h"
#include "framework/logger.h"
#include "library/colour.h"

#include "library/sp.h"
#include <functional>
#include <list>
#include <map>

namespace tinyxml2
{
class XMLElement;
} // namespace tinyxml2

namespace OpenApoc
{

Expand Down
1 change: 1 addition & 0 deletions forms/form.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "form.h"
#include <tinyxml2.h>

namespace OpenApoc
{
Expand Down
1 change: 1 addition & 0 deletions forms/graphic.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "forms/graphic.h"
#include "framework/framework.h"
#include "library/sp.h"
#include <tinyxml2.h>

namespace OpenApoc
{
Expand Down
4 changes: 2 additions & 2 deletions forms/graphicbutton.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "library/sp.h"

#include "forms/graphicbutton.h"
#include "forms/scrollbar.h"
#include "framework/framework.h"
#include "library/sp.h"
#include <tinyxml2.h>

namespace OpenApoc
{
Expand Down
4 changes: 2 additions & 2 deletions forms/label.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "library/sp.h"

#include "forms/label.h"
#include "framework/framework.h"
#include "game/resources/gamecore.h"
#include "library/sp.h"
#include <tinyxml2.h>

namespace OpenApoc
{
Expand Down
2 changes: 1 addition & 1 deletion forms/list.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

#include "forms/list.h"
#include "forms/scrollbar.h"
#include "framework/event.h"
#include "framework/framework.h"
#include <tinyxml2.h>

namespace OpenApoc
{
Expand Down
2 changes: 1 addition & 1 deletion forms/scrollbar.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#include "forms/scrollbar.h"
#include "framework/framework.h"
#include "framework/includes.h"
#include <tinyxml2.h>

namespace OpenApoc
{
Expand Down
6 changes: 3 additions & 3 deletions forms/textbutton.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "library/sp.h"

#include "forms/label.h"
#include "forms/textbutton.h"
#include "forms/label.h"
#include "framework/framework.h"
#include "game/resources/gamecore.h"
#include "library/sp.h"
#include <tinyxml2.h>

namespace OpenApoc
{
Expand Down
4 changes: 2 additions & 2 deletions forms/textedit.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "library/sp.h"

#include "forms/textedit.h"
#include "framework/framework.h"
#include "game/resources/gamecore.h"
#include "library/sp.h"
#include <tinyxml2.h>

namespace OpenApoc
{
Expand Down
205 changes: 205 additions & 0 deletions framework/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# project name, and type
PROJECT(OpenApoc CXX C)

# check cmake version
CMAKE_MINIMUM_REQUIRED(VERSION 3.1)

option(BACKTRACE_ON_ERROR "Print backtrace on logging an error (Requires libunwind on linux, no extra dependencies on windows)" ON)
option(DIALOG_ON_ERROR "Pop up a dialog box showing errors" ON)


set (FRAMEWORK_SOURCE_FILES
configfile.cpp
data.cpp
event.cpp
font.cpp
framework.cpp
image.cpp
logger.cpp
palette.cpp
physfs_fs.cpp
renderer.cpp
serialize.cpp
sound.cpp
stagestack.cpp
trace.cpp
ignorecase.c)

source_group(framework\\sources FILES ${FRAMEWORK_SOURCE_FILES})
list(APPEND ALL_SOURCE_FILES ${FRAMEWORK_SOURCE_FILES})

set (FRAMEWORK_HEADER_FILES
configfile.h
data.h
event.h
font.h
framework.h
fs.h
ignorecase.h
image.h
imageloader_interface.h
includes.h
logger.h
musicloader_interface.h
palette.h
renderer.h
renderer_interface.h
resource.h
sampleloader_interface.h
serialize.h
sound.h
sound_interface.h
stage.h
stagestack.h
trace.h
ThreadPool/ThreadPool.h)

source_group(framework\\headers FILES ${FRAMEWORK_HEADER_FILES})
list(APPEND ALL_HEADER_FILES ${FRAMEWORK_HEADER_FILES})

set (IMAGELOADER_SOURCE_FILES
imageloader/lodepng.cpp
imageloader/lodepng_image.cpp
imageloader/pcx.cpp)

source_group(framework\\imageloader\\sources FILES
${IMAGELOADER_SOURCE_FILES})
list(APPEND ALL_SOURCE_FILES ${IMAGELOADER_SOURCE_FILES})

set (IMAGELOADER_HEADER_FILES
imageloader/lodepng.h)

source_group(framework\\imageloader\\headers FILES
${IMAGELOADER_HEADER_FILES})
list(APPEND ALL_HEADER_FILES ${IMAGELOADER_HEADER_FILES})

set (SOUND_SOURCE_FILES
sound/null_backend.cpp
sound/sdlraw_backend.cpp)

source_group(framework\\sound\\sources FILES
${SOUND_SOURCE_FILES})
list(APPEND ALL_SOURCE_FILES ${SOUND_SOURCE_FILES})

set (SOUND_HEADER_FILES)

source_group(framework\\sound\\headers FILES
${SOUND_HEADER_FILES})
list(APPEND ALL_HEADER_FILES ${SOUND_HEADER_FILES})

set (RENDERER_SOURCE_FILES
render/gl20/ogl_2_0_renderer.cpp
render/gl30/ogl_3_0_renderer.cpp)

source_group(framework\\renderer\\sources FILES
${RENDERER_SOURCE_FILES})
list(APPEND ALL_SOURCE_FILES ${RENDERER_SOURCE_FILES})

set (RENDERER_HEADER_FILES
render/gl20/gl_2_0.hpp
render/gl20/gl_2_0.inl
render/gl30/gl_3_0.hpp
render/gl30/gl_3_0.inl
)

source_group(framework\\renderer\\headers FILES
${RENDERER_HEADER_FILES})
list(APPEND ALL_HEADER_FILES ${RENDERER_HEADER_FILES})

add_library(OpenApoc_Framework STATIC
${FRAMEWORK_SOURCE_FILES} ${FRAMEWORK_HEADER_FILES}
${IMAGELOADER_SOURCE_FILES} ${IMAGELOADER_HEADER_FILES}
${SOUND_SOURCE_FILES} ${SOUND_HEADER_FILES}
${RENDERER_SOURCE_FILES} ${RENDERER_HEADER_FILES})

set_property(TARGET OpenApoc_Framework PROPERTY CXX_STANDARD 11)
set_property(TARGET OpenApoc_Framework PROPERTY CXX_STANDARD_REQUIRED ON)
target_compile_definitions(OpenApoc_Framework PUBLIC PTHREADS_AVAILABLE)

target_compile_definitions(OpenApoc_Framework PUBLIC
"-DRENDERERS=\"GL_3_0:GL_2_0\"")

# We use boost::locale for utf conversions and boost::filesystem for
# serialization
find_package(Boost REQUIRED COMPONENTS locale filesystem system)
target_link_libraries(OpenApoc_Framework PUBLIC ${Boost_LIBRARIES})
target_include_directories(OpenApoc_Framework PUBLIC ${Boost_INCLUDE_DIRS})


#Require the glm matrix/vector maths library
FIND_PATH(GLM_INCLUDE_DIR glm/glm.hpp)
MARK_AS_ADVANCED(GLM_INCLUDE_DIR)
if (NOT GLM_INCLUDE_DIR)
message(FATAL_ERROR "GLM headers not found")
endif()

target_include_directories(OpenApoc_Framework PUBLIC ${GLM_INCLIDE_DIR})

find_package(PkgConfig)

#Require SDL2 for input/graphics/sound/pretty much everything
pkg_check_modules(PC_SDL2 REQUIRED sdl2>=2.0)
if (NOT PC_SDL2_FOUND)
message(FATAL_ERROR "sdl2 not found")
endif()
foreach (SDL2_LIB ${PC_SDL2_LIBRARIES})
message("Searching for ${SDL2_LIB} in ${PC_SDL2_LIBRARY_DIRS}")
find_library(SDL2_LIBRARY_PATH-${SDL2_LIB} ${SDL2_LIB} HINTS ${PC_SDL2_LIBRARY_DIRS})
if (NOT SDL2_LIBRARY_PATH-${SDL2_LIB})
message(FATAL_ERROR "sdl2 library ${SDL2_LIB} not found in ${PC_SDL2_LIBRARY_DIRS}")
endif()
message("Found ${SDL2_LIB} at ${SDL2_LIBRARY_PATH-${SDL2_LIB}}")
target_link_libraries(OpenApoc_Framework PUBLIC ${SDL2_LIB})
endforeach()
target_include_directories(OpenApoc_Framework PUBLIC ${PC_SDL2_INCLUDE_DIRS})

# Dialog is handled by SDL2
if(DIALOG_ON_ERROR)
target_compile_definitions(OpenApoc_Framework PUBLIC -DERROR_DIALOG)
endif()

# Backtrace required libunwind
if(BACKTRACE_ON_ERROR)
pkg_check_modules(PC_UNWIND libunwind)
if (NOT PC_UNWIND_FOUND)
#Ubuntu 12.04 libunwind doesn't have a pkgconfig - try 'current' paths anyway
find_path(UNWIND_INCLUDE_DIR libunwind.h HINTS ${FRAMEWORK_INCLUDE_DIRS})
if (NOT UNWIND_INCLUDE_DIR)
message(FATAL_ERROR "Libunwind not found")
endif()
target_link_libraries(OpenApoc_Framework PUBLIC unwind dl)
#HACK - this assumes the library path is already searched?
else()
find_path(UNWIND_INCLUDE_DIR libunwind.h HINTS ${PC_UNWIND_INCLUDEDIR})
target_link_libraries(OpenApoc_Framework PUBLIC ${PC_UNWIND_LIBRARIES} dl)
endif()
target_compile_definitions(OpenApoc_Framework PUBLIC -DBACKTRACE_LIBUNWIND)
target_include_directories(OpenApoc_Framework PUBLIC ${UNWIND_INCLUDE_DIR})
endif()

# OpenGL is required for any renderer
find_package(OpenGL)
if (NOT OPENGL_FOUND)
message(WARNING "OpenGL not found for GL_2_0 renderer")
else()
target_link_libraries(OpenApoc_Framework PUBLIC ${OPENGL_gl_LIBRARY})
target_include_directories(OpenApoc_Framework PUBLIC ${OPENGL_INCLUDE_DIR})
endif()
target_link_libraries(OpenApoc_Framework PUBLIC OpenApoc_Library)

# Physfs provides .iso reader & overlays etc.
pkg_check_modules(PC_PHYSFS REQUIRED physfs>=2.0.0)

find_path(PHYSFS_INCLUDE_DIR physfs.h HINTS ${PC_PHYSFS_INCLUDEDIR})
target_include_directories(OpenApoc_Framework PUBLIC ${PHYFSFS_INCLUDE_DIR})

foreach (PHYSFS_LIBRARY ${PC_PHYSFS_LIBRARIES})
find_library(PHYSFS_LIBRARY_PATH ${PHYSFS_LIBRARY} HINTS
${PC_PHYSFS_LIBRARY_DIRS})
if (NOT PHYSFS_LIBRARY_PATH)
message(FATAL_ERROR "Failed to find physfs library ${PHYSFS_LIBRARY} in ${PC_PHYSFS_LIBRARY_DIRS}")
endif()
target_link_libraries(OpenApoc_Framework PUBLIC ${PHYSFS_LIBRARY_PATH})
endforeach(PHYSFS_LIBRARY)

target_include_directories(OpenApoc_Framework PUBLIC ${CMAKE_SOURCE_DIR})
21 changes: 0 additions & 21 deletions framework/cmake/FindOpenGLESv2.cmake

This file was deleted.

Loading

0 comments on commit bff5904

Please sign in to comment.