From 5e4f313471524acb1ced474fbc487c0779aa1fb8 Mon Sep 17 00:00:00 2001 From: anyc Date: Tue, 20 May 2014 18:35:27 +0200 Subject: [PATCH] added cmake build scripts --- CMakeLists.txt | 58 ++++++++++++++++++++++++++++++++++++++++++++ CMakeLists_mingw.txt | 28 +++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 CMakeLists_mingw.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000..1ac432ad6a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,58 @@ +cmake_minimum_required(VERSION 2.6) + +# +# Execute these commands in this directory: +# +# 1. mkdir build/; cd build/ +# +# 2. Choose compiler: +# Build with native toolchain: +# cmake -DCMAKE_BUILD_TYPE=Debug .. +# +# Build with mingw: +# cmake -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt -DCMAKE_BUILD_TYPE=Debug .. +# +# 3. make +# + + +# project title +set (PROJECT openrct2) +# OpenRCT2 resource directory +set (ORCT2_RESOURCE_DIR ${CMAKE_INSTALL_PREFIX}/share/${PROJECT}/) + +project(${PROJECT}) + +add_definitions(-DORCT2_RESOURCE_DIR="${ORCT2_RESOURCE_DIR}") + +# include lodepng +include_directories("lodepng/") +file(GLOB_RECURSE ORCT2_SOURCES "src/*.c" "lodepng/*.c") + +# build as library for now, replace with add_executable +add_library(${PROJECT} SHARED ${ORCT2_SOURCES}) + +# install into ${CMAKE_INSTALL_PREFIX}/bin/ +install (TARGETS ${PROJECT} DESTINATION bin) + +# libopenrct2.dll -> openrct2.dll +set_target_properties(${PROJECT} PROPERTIES PREFIX "") + +if (UNIX) + # force 32bit build for now and set necessary flags to compile code as is + set(CMAKE_C_FLAGS "-m32 -masm=intel -std=c99") + set(CMAKE_LDFLAGS_FLAGS "-m32") + + # find and include SDL2 + INCLUDE(FindPkgConfig) + PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2) + INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS}) + TARGET_LINK_LIBRARIES(${PROJECT} ${SDL2_LIBRARIES}) +endif (UNIX) + +TARGET_LINK_LIBRARIES(${PROJECT} ${SDL2_LIBRARIES}) + +if (WIN32) + target_link_libraries(${PROJECT} winmm.lib -limm32 -lversion) +endif (WIN32) + diff --git a/CMakeLists_mingw.txt b/CMakeLists_mingw.txt new file mode 100644 index 0000000000..6acff59606 --- /dev/null +++ b/CMakeLists_mingw.txt @@ -0,0 +1,28 @@ +SET(CMAKE_SYSTEM_NAME Windows) + +SET(COMPILER_PREFIX i686-w64-mingw32) +SET(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc) +SET(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-c++) +SET(CMAKE_RC_COMPILER ${COMPILER_PREFIX}-windres) +SET(CMAKE_PKGCONFIG_EXECUTABLE ${COMPILER_PREFIX}-pkg-config) +SET(PKG_CONFIG_EXECUTABLE ${COMPILER_PREFIX}-pkg-config) + +set(CMAKE_C_FLAGS "-masm=intel -std=gnu99" CACHE STRING "" FORCE) +set(CMAKE_SHARED_LINKER_FLAGS "-static-libgcc" CACHE STRING "" FORCE) + +include_directories("/usr/include/wine/windows/") + +# find and include SDL2 +INCLUDE(FindPkgConfig) +PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2) +INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS}) + +# here is the target environment located +SET(CMAKE_FIND_ROOT_PATH /usr/${COMPILER_PREFIX}) + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)