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 placesdev-ui
parent
e9660c47c6
commit
e7e8954384
111
CMakeLists.txt
111
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)
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
|
||||||
project(colobot C CXX)
|
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
|
# Required packages
|
||||||
|
##
|
||||||
|
|
||||||
find_package(OpenGL 1.4 REQUIRED)
|
find_package(OpenGL 1.4 REQUIRED)
|
||||||
find_package(SDL 1.2.10 REQUIRED)
|
find_package(SDL 1.2.10 REQUIRED)
|
||||||
find_package(SDL_image 1.2 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")
|
set(Boost_ADDITIONALVERSION "1.51" "1.51.0")
|
||||||
find_package(Boost COMPONENTS system filesystem regex REQUIRED)
|
find_package(Boost COMPONENTS system filesystem regex REQUIRED)
|
||||||
|
|
||||||
|
|
||||||
# GLEW requirement depends on platform
|
# GLEW requirement depends on platform
|
||||||
# By default it is auto detected
|
# By default it is auto detected
|
||||||
# This setting may be used to override
|
# This setting may be used to override
|
||||||
|
@ -27,22 +58,76 @@ find_package(Boost COMPONENTS system filesystem regex REQUIRED)
|
||||||
# - 1 -> always enable
|
# - 1 -> always enable
|
||||||
# - 0 -> always disable
|
# - 0 -> always disable
|
||||||
set(USE_GLEW auto)
|
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")
|
# Additional settings to use when cross-compiling with MXE (http://mxe.cc/)
|
||||||
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wold-style-cast -std=gnu++0x")
|
##
|
||||||
|
|
||||||
# Include cmake directory
|
include("${colobot_SOURCE_DIR}/cmake/mxe.cmake")
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${colobot_SOURCE_DIR}/cmake")
|
|
||||||
|
|
||||||
enable_testing()
|
|
||||||
|
|
||||||
# Google Test library
|
##
|
||||||
set(GTEST_DIR "${colobot_SOURCE_DIR}/lib/gtest")
|
# Platform detection and some related checks
|
||||||
add_subdirectory(lib/gtest bin/test)
|
##
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
##
|
||||||
|
# Targets
|
||||||
|
##
|
||||||
|
|
||||||
|
if(${TESTS})
|
||||||
|
# Google Test library
|
||||||
|
set(GTEST_DIR "${colobot_SOURCE_DIR}/lib/gtest")
|
||||||
|
add_subdirectory(lib/gtest bin/test)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Subdirectory with sources
|
# Subdirectory with sources
|
||||||
add_subdirectory(src bin)
|
add_subdirectory(src bin)
|
||||||
|
|
|
@ -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'.
|
||||||
|
|
|
@ -6,6 +6,9 @@ How to...
|
||||||
|
|
||||||
1.1 Windows:
|
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
|
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
|
clashing macros defined in windows headers. Most probably, a special development package
|
||||||
will be provided, which will include MinGW, CMake and all necessary libraries.
|
will be provided, which will include MinGW, CMake and all necessary libraries.
|
||||||
|
@ -63,6 +66,9 @@ Jak...
|
||||||
|
|
||||||
1.1 Windows:
|
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,
|
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
|
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.
|
dla developerów, która będzie zawierała MinGW, CMake i wszystkie potrzebne biblioteki.
|
||||||
|
|
|
@ -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()
|
|
@ -12,4 +12,8 @@ CBotVar.cpp
|
||||||
CBotWhile.cpp
|
CBotWhile.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(CBot SHARED ${SOURCES})
|
if(${CBOT_STATIC})
|
||||||
|
add_library(CBot STATIC ${SOURCES})
|
||||||
|
else()
|
||||||
|
add_library(CBot SHARED ${SOURCES})
|
||||||
|
endif()
|
||||||
|
|
|
@ -1,56 +1,38 @@
|
||||||
# CBot shared library is built separately
|
# CBot library is built separately
|
||||||
add_subdirectory(CBot)
|
add_subdirectory(CBot)
|
||||||
|
|
||||||
# Tools directory is built separately
|
# Tools directory is built separately
|
||||||
add_subdirectory(tools)
|
add_subdirectory(tools)
|
||||||
|
|
||||||
# Tests
|
# Tests
|
||||||
add_subdirectory(common/test)
|
if(${TESTS})
|
||||||
add_subdirectory(graphics/engine/test)
|
add_subdirectory(common/test)
|
||||||
add_subdirectory(math/test)
|
add_subdirectory(graphics/engine/test)
|
||||||
|
add_subdirectory(math/test)
|
||||||
|
|
||||||
# Configure options
|
|
||||||
option(DEBUG "Enable debug output" ON)
|
|
||||||
|
|
||||||
set(PLATFORM_LIBS "")
|
|
||||||
|
|
||||||
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()
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
# Optional libraries
|
||||||
set(OPTIONAL_LIBS "")
|
set(OPTIONAL_LIBS "")
|
||||||
set(OPTIONAL_INCLUDE_DIRS "")
|
set(OPTIONAL_INCLUDE_DIRS "")
|
||||||
|
|
||||||
if(${USE_GLEW} EQUAL 1)
|
if(${USE_GLEW} AND NOT ${MXE})
|
||||||
find_package(GLEW REQUIRED)
|
set(OPTIONAL_LIBS ${OPTIONAL_LIBS} ${GLEW_LIBRARY})
|
||||||
set(OPTIONAL_LIBS ${OPTIONAL_LIBS} ${GLEW_LIBRARY})
|
set(OPTIONAL_INCLUDE_DIRS ${OPTIONAL_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH})
|
||||||
set(OPTIONAL_INCLUDE_DIRS ${OPTIONAL_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH})
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
# 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()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,8 +41,6 @@ configure_file(common/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/common/config.h
|
||||||
|
|
||||||
|
|
||||||
# Source files
|
# Source files
|
||||||
# Commented out files are still dependent on DirectX or WinAPI
|
|
||||||
|
|
||||||
set(SOURCES
|
set(SOURCES
|
||||||
app/app.cpp
|
app/app.cpp
|
||||||
app/main.cpp
|
app/main.cpp
|
||||||
|
@ -191,8 +171,8 @@ ${PNG_LIBRARIES}
|
||||||
${OPTIONAL_LIBS}
|
${OPTIONAL_LIBS}
|
||||||
${PLATFORM_LIBS}
|
${PLATFORM_LIBS}
|
||||||
${Boost_LIBRARIES}
|
${Boost_LIBRARIES}
|
||||||
CBot
|
|
||||||
ltdl
|
ltdl
|
||||||
|
CBot
|
||||||
)
|
)
|
||||||
|
|
||||||
include_directories(
|
include_directories(
|
||||||
|
@ -200,7 +180,7 @@ include_directories(
|
||||||
..
|
..
|
||||||
${CMAKE_CURRENT_BINARY_DIR}
|
${CMAKE_CURRENT_BINARY_DIR}
|
||||||
${SDL_INCLUDE_DIR}
|
${SDL_INCLUDE_DIR}
|
||||||
${SDL_IMAGE_INCLUDE_DIR}
|
${SDLIMAGE_INCLUDE_DIR}
|
||||||
${SDLTTF_INCLUDE_DIR}
|
${SDLTTF_INCLUDE_DIR}
|
||||||
${PNG_INCLUDE_DIRS}
|
${PNG_INCLUDE_DIRS}
|
||||||
${OPTIONAL_INCLUDE_DIRS}
|
${OPTIONAL_INCLUDE_DIRS}
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// Macros set by CMake
|
// Macros set by CMake
|
||||||
#cmakedefine DEBUG
|
|
||||||
|
|
||||||
#cmakedefine PLATFORM_WINDOWS @PLATFORM_WINDOWS@
|
#cmakedefine PLATFORM_WINDOWS @PLATFORM_WINDOWS@
|
||||||
#cmakedefine PLATFORM_LINUX @PLATFORM_LINUX@
|
#cmakedefine PLATFORM_LINUX @PLATFORM_LINUX@
|
||||||
#cmakedefine PLATFORM_OTHER @PLATFORM_OTHER@
|
#cmakedefine PLATFORM_OTHER @PLATFORM_OTHER@
|
||||||
|
|
||||||
#cmakedefine USE_GLEW @USE_GLEW@
|
#cmakedefine USE_GLEW @USE_GLEW@
|
||||||
|
#cmakedefine GLEW_STATIC
|
Loading…
Reference in New Issue