summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-09-29 17:19:23 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-09-29 17:19:23 +0200
commite7e895438497f4efcb4d8bee240b2fe4e5938184 (patch)
tree96af8bb4258a784babc027c801bd379639fd2074
parente9660c47c69327a131c4e4b15bea4bdc7937fd61 (diff)
downloadcolobot-e7e895438497f4efcb4d8bee240b2fe4e5938184.tar.gz
colobot-e7e895438497f4efcb4d8bee240b2fe4e5938184.tar.bz2
colobot-e7e895438497f4efcb4d8bee240b2fe4e5938184.zip
MXE support and CMake files refactoring
- added support for cross-compiling with MXE (http://mxe.cc/) - refactored CMake files, adding some options and moving definitions to more suitable places
-rw-r--r--CMakeLists.txt111
-rw-r--r--HOWTO-MXE.txt64
-rw-r--r--HOWTO.txt6
-rw-r--r--cmake/mxe.cmake29
-rw-r--r--src/CBot/CMakeLists.txt6
-rw-r--r--src/CMakeLists.txt70
-rw-r--r--src/common/config.h.cmake3
7 files changed, 228 insertions, 61 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index eee86fb..1353250 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,10 +1,42 @@
-# CMake project file for compiling with GCC/MinGW
+##
+# Main CMake project file
+# Contains global options and definitions
+##
cmake_minimum_required(VERSION 2.8)
project(colobot C CXX)
+# Include cmake directory with some additional scripts
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${colobot_SOURCE_DIR}/cmake")
+
+
+##
+# Build options
+##
+
+# Global build type
+set(CMAKE_BUILD_TYPE debug)
+
+# Global compile flags
+# These are specific to GCC/MinGW; for other compilers, change as necessary
+set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall -Wold-style-cast -std=gnu++0x")
+set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wold-style-cast -std=gnu++0x")
+
+# Asserts can be enabled/disabled regardless of build type
+option(ASSERTS "Enable assert()s" ON)
+
+# Building tests can be enabled/disabled
+option(TESTS "Enable tests" ON)
+
+# CBot can also be a static library
+option(CBOT_STATIC "Build CBot as static libary" OFF)
+
+
+##
# Required packages
+##
+
find_package(OpenGL 1.4 REQUIRED)
find_package(SDL 1.2.10 REQUIRED)
find_package(SDL_image 1.2 REQUIRED)
@@ -18,7 +50,6 @@ set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_ADDITIONALVERSION "1.51" "1.51.0")
find_package(Boost COMPONENTS system filesystem regex REQUIRED)
-
# GLEW requirement depends on platform
# By default it is auto detected
# This setting may be used to override
@@ -27,22 +58,76 @@ find_package(Boost COMPONENTS system filesystem regex REQUIRED)
# - 1 -> always enable
# - 0 -> always disable
set(USE_GLEW auto)
+# This is useful on Windows, if linking against standard GLEW dll fails
+option(GLEW_STATIC "Link statically with GLEW" OFF)
-# Build with debugging symbols
-set(CMAKE_BUILD_TYPE debug)
-# Global compile flags
-set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wall -Wold-style-cast -std=gnu++0x")
-set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wold-style-cast -std=gnu++0x")
+##
+# Additional settings to use when cross-compiling with MXE (http://mxe.cc/)
+##
+
+include("${colobot_SOURCE_DIR}/cmake/mxe.cmake")
+
+
+##
+# Platform detection and some related checks
+##
+
+if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
+ message(STATUS "Windows system detected")
+ set(PLATFORM_WINDOWS 1)
+ set(PLATFORM_LINUX 0)
+ set(PLATFORM_OTHER 0)
+
+ # On Windows, GLEW is required
+ if (${USE_GLEW} MATCHES "auto")
+ set(USE_GLEW 1)
+ endif()
+elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
+ message(STATUS "Linux system detected")
+ set(PLATFORM_WINDOWS 0)
+ set(PLATFORM_LINUX 1)
+ set(PLATFORM_OTHER 0)
+
+ # On Linux, we should be fine without GLEW
+ if (${USE_GLEW} MATCHES "auto")
+ set(USE_GLEW 0)
+ endif()
+else()
+ message(STATUS "Other system detected")
+ set(PLATFORM_WINDOWS 0)
+ set(PLATFORM_LINUX 0)
+ set(PLATFORM_OTHER 1)
+
+ # Use GLEW to be safe
+ if (${USE_GLEW} MATCHES "auto")
+ set(USE_GLEW 1)
+ endif()
+endif()
+
+
+if(${USE_GLEW})
+ find_package(GLEW REQUIRED)
+endif()
+
+if(NOT ${ASSERTS})
+ add_definitions(-DNDEBUG)
+endif()
+
+if(${TESTS})
+ enable_testing()
+endif()
-# Include cmake directory
-set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${colobot_SOURCE_DIR}/cmake")
-enable_testing()
+##
+# Targets
+##
-# Google Test library
-set(GTEST_DIR "${colobot_SOURCE_DIR}/lib/gtest")
-add_subdirectory(lib/gtest bin/test)
+if(${TESTS})
+ # Google Test library
+ set(GTEST_DIR "${colobot_SOURCE_DIR}/lib/gtest")
+ add_subdirectory(lib/gtest bin/test)
+endif()
# Subdirectory with sources
add_subdirectory(src bin)
diff --git a/HOWTO-MXE.txt b/HOWTO-MXE.txt
new file mode 100644
index 0000000..7b93143
--- /dev/null
+++ b/HOWTO-MXE.txt
@@ -0,0 +1,64 @@
+Cross-compiling with MXE (http://mxe.cc)
+
+MXE works for any BSD-compatible system (including Linux).
+It is a complete package with cross-compiler to Win32 (a MinGW variant)
+and includes scripts to automatically download and build many 3rd party
+libraries and tools.
+
+1. See the MXE website for list of required packages and make sure
+ you have them installed.
+
+2. Download MXE and unpack it in the directory, where you want to keep it
+ permanently. During the build, MXE will write that path to many files,
+ so moving that directory can be tricky.
+
+3. `cd' to the MXE root directory.
+ It already contains a univeral Makefile for everything.
+ Usage is simply `make [name_of_package]'.
+ It will automatically check for dependencies, etc.
+ The packages will be installed in the MXE directory in usr/.
+
+ You need to `make gcc' for basic compiler and then some additional
+ libraries. In the end, you should have the following packages installed
+ (this is the final listing of usr/installed/):
+
+ binutils
+ boost
+ bzip2
+ check-requirements
+ expat
+ freetype
+ gcc
+ gcc-gmp
+ gcc-mpc
+ gcc-mpfr
+ gettext
+ glew
+ jpeg
+ libiconv
+ libpng
+ libtool
+ mingwrt
+ openal
+ portaudio
+ sdl
+ sdl_image
+ sdl_ttf
+ tiff
+ w32api
+ xz
+ zlib
+
+4. Now `cd' to colobot directory. To cross-compile a CMake project, you have to specify
+ a CMake toolchain file. MXE has such file in MXE's directory:
+ usr/i686-pc-mingw32/share/cmake/mxe-conf.cmake
+ Toolchain file is specified thus:
+ `cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/mxe-conf.cmake .'
+ The new CMake files in colobot should detect that MXE is being used and they will
+ modify flags, paths, etc. You should not run into any problems.
+
+5. `make' should now compile the game with the resulting exe in bin/colobot.exe.
+ The exe is linked against all libraries *statically*, so there are no dependencies
+ on external dlls. However, the resulting binary will be huge with all these libraries,
+ so you should `strip bin/colobot.exe'.
+
diff --git a/HOWTO.txt b/HOWTO.txt
index 0dfb593..9e71bce 100644
--- a/HOWTO.txt
+++ b/HOWTO.txt
@@ -6,6 +6,9 @@ How to...
1.1 Windows:
+ CROSS-COMPILING: see the instructions in HOWTO-MXE.txt on how to cross-compile the project
+ with MXE (http://mxe.cc/).
+
NOTE: currently, there are some issues when compiling on Windows, connected mostly with
clashing macros defined in windows headers. Most probably, a special development package
will be provided, which will include MinGW, CMake and all necessary libraries.
@@ -63,6 +66,9 @@ Jak...
1.1 Windows:
+ CROSS-KOMPILACJA: zobacz plik HOWTO-MXE.txt z instrukcjami jak cross-skompilować projekt używając
+ MXE (http://mxe.cc/).
+
UWAGA: obecnie występują problemy z kompilacją na Windowsie, głównie ze względu na konflikt w makrach,
jakie definiują nagłówki windowsowe. Najprawdopodobniej, zostanie wydana specjalna paczka
dla developerów, która będzie zawierała MinGW, CMake i wszystkie potrzebne biblioteki.
diff --git a/cmake/mxe.cmake b/cmake/mxe.cmake
new file mode 100644
index 0000000..4507a80
--- /dev/null
+++ b/cmake/mxe.cmake
@@ -0,0 +1,29 @@
+# When cross-compiling with MXE, we need to straighten some things
+
+# Checking is a bit primitive, but this should detect MXE toolchain file
+if((${CMAKE_CROSSCOMPILING}) AND (DEFINED MSYS))
+ message(STATUS "Detected MXE build")
+ set(MXE 1)
+ # Because some tests will not compile
+ set(TESTS OFF)
+ # All must be static, CBOT and GLEW too
+ set(CBOT_STATIC ON)
+ set(GLEW_STATIC ON)
+ # Because find package scripts are lame
+ set(SDLTTF_INCLUDE_DIR ${CMAKE_FIND_ROOT_PATH}/include/SDL)
+ set(SDLIMAGE_INCLUDE_DIR ${CMAKE_FIND_ROOT_PATH}/include/SDL)
+ set(MXE_LIBS
+ # For some reason, these have to be absolute paths
+ ${CMAKE_FIND_ROOT_PATH}/lib/libintl.a
+ ${CMAKE_FIND_ROOT_PATH}/lib/libiconv.a
+ ${CMAKE_FIND_ROOT_PATH}/lib/libglew32s.a
+ ${CMAKE_FIND_ROOT_PATH}/lib/libfreetype.a
+ ${CMAKE_FIND_ROOT_PATH}/lib/libltdl.a
+ ${CMAKE_FIND_ROOT_PATH}/lib/libopengl32.a
+ ${CMAKE_FIND_ROOT_PATH}/lib/libjpeg.a
+ ${CMAKE_FIND_ROOT_PATH}/lib/libwinmm.a
+ ${CMAKE_FIND_ROOT_PATH}/lib/libdxguid.a
+ )
+else()
+ set(MXE 0)
+endif() \ No newline at end of file
diff --git a/src/CBot/CMakeLists.txt b/src/CBot/CMakeLists.txt
index 409ef3b..9f5b987 100644
--- a/src/CBot/CMakeLists.txt
+++ b/src/CBot/CMakeLists.txt
@@ -12,4 +12,8 @@ CBotVar.cpp
CBotWhile.cpp
)
-add_library(CBot SHARED ${SOURCES})
+if(${CBOT_STATIC})
+ add_library(CBot STATIC ${SOURCES})
+else()
+ add_library(CBot SHARED ${SOURCES})
+endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index fe42c62..a7f1c96 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,56 +1,38 @@
-# CBot shared library is built separately
+# CBot library is built separately
add_subdirectory(CBot)
# Tools directory is built separately
add_subdirectory(tools)
# Tests
-add_subdirectory(common/test)
-add_subdirectory(graphics/engine/test)
-add_subdirectory(math/test)
-
+if(${TESTS})
+ add_subdirectory(common/test)
+ add_subdirectory(graphics/engine/test)
+ add_subdirectory(math/test)
+endif()
-# Configure options
-option(DEBUG "Enable debug output" ON)
-set(PLATFORM_LIBS "")
+# Optional libraries
+set(OPTIONAL_LIBS "")
+set(OPTIONAL_INCLUDE_DIRS "")
-if (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
- set(PLATFORM_WINDOWS 1)
- set(PLATFORM_LINUX 0)
- set(PLATFORM_OTHER 0)
- set(PLATFORM_LIBS "-lintl")
- # On Windows, GLEW is required
- if (${USE_GLEW} MATCHES "auto")
- set(USE_GLEW 1)
- endif()
-elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
- set(PLATFORM_WINDOWS 0)
- set(PLATFORM_LINUX 1)
- set(PLATFORM_OTHER 0)
- # On Linux, we should be fine without GLEW
- if (${USE_GLEW} MATCHES "auto")
- set(USE_GLEW 0)
- endif()
- # for clock_gettime
- set(PLATFORM_LIBS "-lrt")
-else()
- set(PLATFORM_WINDOWS 0)
- set(PLATFORM_LINUX 0)
- set(PLATFORM_OTHER 1)
- # Use GLEW to be safe
- if (${USE_GLEW} MATCHES "auto")
- set(USE_GLEW 1)
- endif()
+if(${USE_GLEW} AND NOT ${MXE})
+ set(OPTIONAL_LIBS ${OPTIONAL_LIBS} ${GLEW_LIBRARY})
+ set(OPTIONAL_INCLUDE_DIRS ${OPTIONAL_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH})
endif()
-set(OPTIONAL_LIBS "")
-set(OPTIONAL_INCLUDE_DIRS "")
-if(${USE_GLEW} EQUAL 1)
- find_package(GLEW REQUIRED)
- set(OPTIONAL_LIBS ${OPTIONAL_LIBS} ${GLEW_LIBRARY})
- set(OPTIONAL_INCLUDE_DIRS ${OPTIONAL_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH})
+# Additional libraries per platform
+set(PLATFORM_LIBS "")
+
+if (${MXE}) # MXE requires special treatment
+ set(PLATFORM_LIBS ${MXE_LIBS})
+elseif (${PLATFORM_WINDOWS})
+ # because it isn't included in standard linking libraries
+ set(PLATFORM_LIBS "-lintl")
+elseif(${PLATFORM_LINUX})
+ # for clock_gettime
+ set(PLATFORM_LIBS "-lrt")
endif()
@@ -59,8 +41,6 @@ configure_file(common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h
# Source files
-# Commented out files are still dependent on DirectX or WinAPI
-
set(SOURCES
app/app.cpp
app/main.cpp
@@ -191,8 +171,8 @@ ${PNG_LIBRARIES}
${OPTIONAL_LIBS}
${PLATFORM_LIBS}
${Boost_LIBRARIES}
-CBot
ltdl
+CBot
)
include_directories(
@@ -200,7 +180,7 @@ include_directories(
..
${CMAKE_CURRENT_BINARY_DIR}
${SDL_INCLUDE_DIR}
-${SDL_IMAGE_INCLUDE_DIR}
+${SDLIMAGE_INCLUDE_DIR}
${SDLTTF_INCLUDE_DIR}
${PNG_INCLUDE_DIRS}
${OPTIONAL_INCLUDE_DIRS}
diff --git a/src/common/config.h.cmake b/src/common/config.h.cmake
index f496db0..8c85df1 100644
--- a/src/common/config.h.cmake
+++ b/src/common/config.h.cmake
@@ -1,10 +1,9 @@
#pragma once
// Macros set by CMake
-#cmakedefine DEBUG
-
#cmakedefine PLATFORM_WINDOWS @PLATFORM_WINDOWS@
#cmakedefine PLATFORM_LINUX @PLATFORM_LINUX@
#cmakedefine PLATFORM_OTHER @PLATFORM_OTHER@
#cmakedefine USE_GLEW @USE_GLEW@
+#cmakedefine GLEW_STATIC \ No newline at end of file