1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-10 09:32:29 +01:00

Refactor project build scripts

This is mostly refactoring of cmake scripts, but also touches build.sh
and install.sh. The cmake should be much more palatable now for major
Linux distributions.

At the same time, new configuration is introduced to Linux version, one
with Twitch enabled.

Please note, however, this change requires update of orctlibs.zip for
mingw builds.
This commit is contained in:
Michał Janiszewski
2015-09-24 22:47:14 +02:00
parent c6b0d0919d
commit a16de307d7
7 changed files with 125 additions and 109 deletions

View File

@@ -10,18 +10,19 @@ notifications:
on_failure: change on_failure: change
on_success: change on_success: change
cache: cache:
directories: directories:
- cache - .cache
apt: true apt: true
env: env:
- OPENRCT2_CMAKE_OPTS="-DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt"
- OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt"
- OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DDISABLE_HTTP_TWITCH=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt"
- OPENRCT2_CMAKE_OPTS="-DDISABLE_HTTP_TWITCH=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt"
- OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DDISABLE_HTTP_TWITCH=ON -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8" - OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DDISABLE_HTTP_TWITCH=ON -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8"
- OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=OFF -DDISABLE_HTTP_TWITCH=ON -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8" - OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=OFF -DDISABLE_HTTP_TWITCH=ON -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8"
- OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=OFF -DDISABLE_HTTP_TWITCH=OFF -DCMAKE_C_COMPILER=gcc-4.8 -DCMAKE_CXX_COMPILER=g++-4.8"
- OPENRCT2_CMAKE_OPTS="-DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows
- OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows
- OPENRCT2_CMAKE_OPTS="-DDISABLE_NETWORK=ON -DDISABLE_HTTP_TWITCH=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows
- OPENRCT2_CMAKE_OPTS="-DDISABLE_HTTP_TWITCH=ON -DCMAKE_TOOLCHAIN_FILE=../CMakeLists_mingw.txt" TARGET=windows
sudo: required sudo: required

View File

@@ -26,9 +26,19 @@ project(${PROJECT})
add_definitions(-DORCT2_RESOURCE_DIR="${ORCT2_RESOURCE_DIR}") add_definitions(-DORCT2_RESOURCE_DIR="${ORCT2_RESOURCE_DIR}")
add_definitions(-DHAVE_CONFIG_H) add_definitions(-DHAVE_CONFIG_H)
add_definitions(-DCURL_STATICLIB) add_definitions(-DCURL_STATICLIB)
INCLUDE(FindPkgConfig)
option(DISABLE_HTTP_TWITCH "Disable HTTP and Twitch support.") option(DISABLE_HTTP_TWITCH "Disable HTTP and Twitch support.")
if (DISABLE_HTTP_TWITCH) if (DISABLE_HTTP_TWITCH)
add_definitions(-DDISABLE_HTTP -DDISABLE_TWITCH) add_definitions(-DDISABLE_HTTP -DDISABLE_TWITCH)
else (DISABLE_HTTP_TWITCH)
PKG_CHECK_MODULES(LIBCURL REQUIRED libcurl)
PKG_CHECK_MODULES(JANSSON REQUIRED jansson)
SET(HTTPLIBS ${LIBCURL_LIBRARIES} ${JANSSON_LIBRARIES})
if (WIN32)
SET(HTTPLIBS ${HTTPLIBS} ssl crypto winmm.lib ws2_32)
endif (WIN32)
endif (DISABLE_HTTP_TWITCH) endif (DISABLE_HTTP_TWITCH)
option(DISABLE_NETWORK "Disable multiplayer functionality. Mainly for testing.") option(DISABLE_NETWORK "Disable multiplayer functionality. Mainly for testing.")
@@ -36,11 +46,6 @@ if (DISABLE_NETWORK)
add_definitions(-DDISABLE_NETWORK) add_definitions(-DDISABLE_NETWORK)
endif (DISABLE_NETWORK) endif (DISABLE_NETWORK)
set(ORCTLIBS_INCLUDE /usr/local/cross-tools/orctlibs/include)
set(JANSSON_INCLUDE /usr/local/cross-tools/orctlibs/include/jansson)
set(ORCTLIBS_LIB_DIR /usr/local/cross-tools/orctlibs/lib)
set(ORCTLIBS_LIB jansson curl ssl crypto)
# include lib # include lib
include_directories("lib/") include_directories("lib/")
# include speex header # include speex header
@@ -52,18 +57,15 @@ if (UNIX)
# force 32bit build for now and set necessary flags to compile code as is # force 32bit build for now and set necessary flags to compile code as is
set(CMAKE_C_FLAGS "-m32 -masm=intel -fvar-tracking-assignments -std=gnu99") set(CMAKE_C_FLAGS "-m32 -masm=intel -fvar-tracking-assignments -std=gnu99")
set(CMAKE_CXX_FLAGS "-m32 -std=gnu++11 -fvar-tracking-assignments -masm=intel") set(CMAKE_CXX_FLAGS "-m32 -std=gnu++11 -fvar-tracking-assignments -masm=intel")
set(LIB32 /usr/lib32) set(CMAKE_SHARED_LINKER_FLAGS "-m32 -Wl,-melf_i386")
set(CMAKE_SHARED_LINKER_FLAGS "-m32 -Wl,-melf_i386 -L${LIB32} -lSDL2_ttf")
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS}) set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS})
# find and include SDL2
INCLUDE(FindPkgConfig)
PKG_CHECK_MODULES(SDL2 REQUIRED sdl2 SDL2_ttf)
INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS})
endif (UNIX) endif (UNIX)
INCLUDE_DIRECTORIES(${ORCTLIBS_INCLUDE} ${JANSSON_INCLUDE}) # find and include SDL2
LINK_DIRECTORIES(${LINK_DIRECTORIES} ${LIB32} ${SDL2_LIBRARY_DIRS} ${ORCTLIBS_LIB_DIR}) PKG_CHECK_MODULES(SDL2 REQUIRED sdl2 SDL2_ttf)
INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS} ${LIBCURL_INCLUDE_DIRS} ${JANSSON_INCLUDE_DIRS})
LINK_DIRECTORIES(${SDL2_LIBRARY_DIRS} ${JANSSON_LIBRARY_DIRS} ${LIBCURL_LIBRARY_DIRS})
if (WIN32) if (WIN32)
# build as library for now, replace with add_executable # build as library for now, replace with add_executable
@@ -78,8 +80,4 @@ endif (WIN32)
# libopenrct2.dll -> openrct2.dll # libopenrct2.dll -> openrct2.dll
set_target_properties(${PROJECT} PROPERTIES PREFIX "") set_target_properties(${PROJECT} PROPERTIES PREFIX "")
TARGET_LINK_LIBRARIES(${PROJECT} ${SDL2_LIBRARIES} ${ORCTLIBS_LIB}) TARGET_LINK_LIBRARIES(${PROJECT} ${SDL2_LIBRARIES} ${ORCTLIBS_LIB} ${JANSSON_LIBRARIES} ${HTTPLIBS})
if (WIN32)
target_link_libraries(${PROJECT} winmm.lib -limm32 -lversion ws2_32)
endif (WIN32)

View File

@@ -19,11 +19,6 @@ else()
set(CMAKE_SHARED_LINKER_FLAGS "-static-libgcc -static-libstdc++" CACHE STRING "" FORCE) set(CMAKE_SHARED_LINKER_FLAGS "-static-libgcc -static-libstdc++" CACHE STRING "" FORCE)
endif(${ACTUAL_SYSTEM} MATCHES "Linux") endif(${ACTUAL_SYSTEM} MATCHES "Linux")
# find and include SDL2
INCLUDE(FindPkgConfig)
PKG_CHECK_MODULES(SDL2 REQUIRED sdl2 SDL2_ttf)
INCLUDE_DIRECTORIES(${SDL2_INCLUDE_DIRS})
if(APPLE) if(APPLE)
SET(TARGET_ENVIRONMENT /usr/local/mingw-w32-bin_i686-darwin/i686-w64-mingw32) SET(TARGET_ENVIRONMENT /usr/local/mingw-w32-bin_i686-darwin/i686-w64-mingw32)
else() else()
@@ -39,3 +34,5 @@ SET(CMAKE_FIND_ROOT_PATH ${TARGET_ENVIRONMENT})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# INCLUDE_DIRECTORIES(${ORCTLIBS_INCLUDE} ${JANSSON_INCLUDE})

View File

@@ -42,7 +42,7 @@ if [[ "$needsdownload" = "true" ]]; then
if [[ -d $cachedir/orctlibs ]]; then if [[ -d $cachedir/orctlibs ]]; then
rm -rf $cachedir/orctlibs rm -rf $cachedir/orctlibs
fi fi
curl https://download.openrct2.website/dev/lib/mingw -o $cachedir/orctlibs.zip curl https://dl.dropboxusercontent.com/u/1323345/orctlibs.zip -o $cachedir/orctlibs.zip
mkdir -p $cachedir/orctlibs mkdir -p $cachedir/orctlibs
pushd $cachedir/orctlibs pushd $cachedir/orctlibs
unzip -uaq ../orctlibs.zip unzip -uaq ../orctlibs.zip
@@ -55,7 +55,7 @@ if [[ "$needsdownload" = "true" ]]; then
fi fi
pushd build pushd build
echo OPENRCT2_CMAKE_OPTS = $OPENRCT_CMAKE_OPTS echo OPENRCT2_CMAKE_OPTS = $OPENRCT2_CMAKE_OPTS
cmake -DCMAKE_BUILD_TYPE=Debug $OPENRCT2_CMAKE_OPTS .. cmake -DCMAKE_BUILD_TYPE=Debug $OPENRCT2_CMAKE_OPTS ..
make make
popd popd

View File

@@ -8,6 +8,11 @@ mkdir -p $cachedir
echo `uname` echo `uname`
# Sets default target to "linux", if none specified
TARGET=${TARGET-linux}
echo TARGET = $TARGET
if [[ `uname` == "Darwin" ]]; then if [[ `uname` == "Darwin" ]]; then
echo "Installation of OpenRCT2 assumes you have homebrew and use it to install packages." echo "Installation of OpenRCT2 assumes you have homebrew and use it to install packages."
@@ -84,81 +89,96 @@ elif [[ `uname` == "Linux" ]]; then
sudo apt-get install -y wine sudo apt-get install -y wine
fi fi
else else
apt-cache search libsdl2 case "$TARGET" in
apt-cache policy libsdl2-dev:i386 "linux")
apt-cache policy libsdl2-dev sudo apt-get install -y --force-yes cmake libsdl2-dev:i386 libsdl2-ttf-dev:i386 gcc-4.8 pkg-config:i386 g++-4.8-multilib gcc-4.8-multilib libjansson-dev:i386 libspeex-dev:i386 libspeexdsp-dev:i386 libcurl4-openssl-dev:i386 libcrypto++-dev:i386
sudo apt-get install -y --force-yes binutils-mingw-w64-i686 gcc-mingw-w64-i686 g++-mingw-w64-i686 cmake libsdl2-dev:i386 libsdl2-ttf-dev:i386 gcc-4.8 pkg-config:i386 g++-4.8-multilib gcc-4.8-multilib libjansson-dev:i386 libspeex-dev:i386 libspeexdsp-dev:i386 libcurl4-openssl-dev:i386 libcrypto++-dev:i386 wget https://launchpad.net/ubuntu/+archive/primary/+files/libjansson4_2.7-1ubuntu1_i386.deb
export CC=gcc-4.8 wget https://launchpad.net/ubuntu/+archive/primary/+files/libjansson-dev_2.7-1ubuntu1_i386.deb
export CXX=g++-4.8 sudo dpkg -i libjansson4_2.7-1ubuntu1_i386.deb
sudo dpkg -i libjansson-dev_2.7-1ubuntu1_i386.deb
sudo apt-get install -f
export CC=gcc-4.8
export CXX=g++-4.8
;;
"windows")
sudo apt-get install -y --force-yes binutils-mingw-w64-i686 gcc-mingw-w64-i686 g++-mingw-w64-i686 cmake
;;
*)
echo "unkown target $TARGET"
exit 1
esac
fi fi
fi fi
if [[ ! -f $cachedir/SDL2-devel-${SDL2_PV}-mingw.tar.gz ]]; then if [[ $TARGET == "windows" ]]; then
wget http://libsdl.org/release/SDL2-devel-${SDL2_PV}-mingw.tar.gz --output-document $cachedir/SDL2-devel-${SDL2_PV}-mingw.tar.gz; if [[ ! -f $cachedir/SDL2-devel-${SDL2_PV}-mingw.tar.gz ]]; then
fi wget http://libsdl.org/release/SDL2-devel-${SDL2_PV}-mingw.tar.gz --output-document $cachedir/SDL2-devel-${SDL2_PV}-mingw.tar.gz;
if [[ ! -f $cachedir/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz ]]; then fi
wget https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz --output-document $cachedir/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz; if [[ ! -f $cachedir/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz ]]; then
fi wget https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz --output-document $cachedir/SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz;
if [[ ! -d $cachedir/SDL2-${SDL2_PV} ]]; then fi
pushd $cachedir if [[ ! -d $cachedir/SDL2-${SDL2_PV} ]]; then
tar -xzf SDL2-devel-${SDL2_PV}-mingw.tar.gz pushd $cachedir
popd tar -xzf SDL2-devel-${SDL2_PV}-mingw.tar.gz
fi popd
if [[ ! -d $cachedir/SDL2_ttf-${SDL2_TTF_PV} ]]; then fi
pushd $cachedir if [[ ! -d $cachedir/SDL2_ttf-${SDL2_TTF_PV} ]]; then
tar -xzf SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz pushd $cachedir
popd tar -xzf SDL2_ttf-devel-${SDL2_TTF_PV}-mingw.tar.gz
fi popd
if [[ ! -f $cachedir/orctlibs.zip ]]; then fi
curl https://download.openrct2.website/dev/lib/mingw -o $cachedir/orctlibs.zip; if [[ ! -f $cachedir/orctlibs.zip ]]; then
fi curl https://dl.dropboxusercontent.com/u/1323345/orctlibs.zip -o $cachedir/orctlibs.zip;
if [[ ! -d $cachedir/orctlibs ]]; then fi
mkdir -p $cachedir/orctlibs if [[ ! -d $cachedir/orctlibs ]]; then
pushd $cachedir/orctlibs mkdir -p $cachedir/orctlibs
unzip -uaq ../orctlibs.zip pushd $cachedir/orctlibs
popd unzip -uaq ../orctlibs.zip
fi ls -lR .
popd
fi
# Apply platform patch # Apply platform patch
mingw_patch=libsdl2-mingw-2.0.3-fix-platform-detection-for-mingw.patch mingw_patch=libsdl2-mingw-2.0.3-fix-platform-detection-for-mingw.patch
if [[ ! -f $cachedir/$mingw_patch ]]; then if [[ ! -f $cachedir/$mingw_patch ]]; then
wget "https://github.com/anyc/anyc-overlay/raw/master/media-libs/libsdl2-mingw/files/$mingw_patch" --output-document $cachedir/$mingw_patch; wget "https://github.com/anyc/anyc-overlay/raw/master/media-libs/libsdl2-mingw/files/$mingw_patch" --output-document $cachedir/$mingw_patch;
# XXX not sure how to make this idempotent. # XXX not sure how to make this idempotent.
pushd $cachedir/SDL2-${SDL2_PV}/i686-w64-mingw32/include/SDL2/ pushd $cachedir/SDL2-${SDL2_PV}/i686-w64-mingw32/include/SDL2/
echo "Applying patch." echo "Applying patch."
patch -p2 < ../../../../$mingw_patch patch -p2 < ../../../../$mingw_patch
popd popd
fi
if [[ ! -d /usr/local/cross-tools ]]; then
sudo mkdir -p /usr/local/cross-tools
fi
if [[ ! -d /usr/local/cross-tools/i686-w64-mingw32 ]]; then
sudo cp -r $cachedir/SDL2-${SDL2_PV}/i686-w64-mingw32 /usr/local/cross-tools/
sudo cp -r $cachedir/SDL2_ttf-${SDL2_TTF_PV}/i686-w64-mingw32 /usr/local/cross-tools/
fi
if [[ ! -d /usr/local/cross-tools/orctlibs ]]; then
sudo mkdir -p /usr/local/cross-tools/orctlibs
mkdir -p lib
sudo cp -rf $cachedir/orctlibs/glob/* /usr/local/cross-tools/orctlibs/.
cp -rf $cachedir/orctlibs/local/* ./lib/.
fi
if [[ ! -f $cachedir/i686-w64-mingw32-pkg-config ]]; then
# If this fails to work because of newlines, be sure you are running this
# script with Bash, and not sh. We should really move this to a separate
# file.
echo -e "#!/bin/sh\nexport PKG_CONFIG_PATH=/usr/local/cross-tools/i686-w64-mingw32/lib/pkgconfig:/usr/local/cross-tools/orctlibs/lib/pkgconfig\npkg-config \$@" > $cachedir/i686-w64-mingw32-pkg-config;
for i in /usr/local/cross-tools/orctlibs/lib/pkgconfig/*.pc
do
cat $i
done
fi
chmod +x $cachedir/i686-w64-mingw32-pkg-config
sudo cp $cachedir/i686-w64-mingw32-pkg-config /usr/local/bin/
ls -al /usr/local/bin | grep pkg-config
cat /usr/local/bin/i686-w64-mingw32-pkg-config
# $TARGET == "windows"
fi fi
if [[ ! -d /usr/local/cross-tools ]]; then
sudo mkdir -p /usr/local/cross-tools
fi
if [[ ! -d /usr/local/cross-tools/i686-w64-mingw32 ]]; then
sudo cp -r $cachedir/SDL2-${SDL2_PV}/i686-w64-mingw32 /usr/local/cross-tools/
sudo cp -r $cachedir/SDL2_ttf-${SDL2_TTF_PV}/i686-w64-mingw32 /usr/local/cross-tools/
fi
if [[ ! -d /usr/local/cross-tools/orctlibs ]]; then
sudo mkdir -p /usr/local/cross-tools/orctlibs
mkdir -p lib
sudo cp -rf $cachedir/orctlibs/glob/* /usr/local/cross-tools/orctlibs/.
cp -rf $cachedir/orctlibs/local/* ./lib/.
fi
if [[ ! -f $cachedir/i686-w64-mingw32-pkg-config ]]; then
# If this fails to work because of newlines, be sure you are running this
# script with Bash, and not sh. We should really move this to a separate
# file.
echo -e "#!/bin/sh\nexport PKG_CONFIG_LIBDIR=/usr/local/cross-tools/i686-w64-mingw32/lib/pkgconfig\npkg-config \$@" > $cachedir/i686-w64-mingw32-pkg-config;
fi
set -x
dpkg -L libsdl2-dev
dpkg -L libsdl2-ttf-dev
set +x
chmod +x $cachedir/i686-w64-mingw32-pkg-config
sudo cp $cachedir/i686-w64-mingw32-pkg-config /usr/local/bin/
ls -al /usr/local/bin | grep pkg-config
cat /usr/local/bin/i686-w64-mingw32-pkg-config

View File

@@ -1,5 +1,6 @@
extern "C" { extern "C" {
#include "http.h" #include "http.h"
#include "../platform/platform.h"
} }
#ifdef DISABLE_HTTP #ifdef DISABLE_HTTP
@@ -10,7 +11,6 @@ void http_dispose() { }
#else #else
#include <SDL.h> #include <SDL.h>
#include <jansson/jansson.h>
// cURL includes windows.h, but we don't need all of it. // cURL includes windows.h, but we don't need all of it.
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
@@ -69,8 +69,8 @@ http_json_response *http_request_json(const char *url)
writeBuffer.length = 0; writeBuffer.length = 0;
writeBuffer.capacity = 0; writeBuffer.capacity = 0;
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, TRUE); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, TRUE); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, true);
curl_easy_setopt(curl, CURLOPT_CAINFO, "curl-ca-bundle.crt"); curl_easy_setopt(curl, CURLOPT_CAINFO, "curl-ca-bundle.crt");
curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &writeBuffer); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &writeBuffer);
@@ -149,4 +149,4 @@ void http_request_json_dispose(http_json_response *response)
free(response); free(response);
} }
#endif #endif

View File

@@ -2,7 +2,7 @@
#define _HTTP_H_ #define _HTTP_H_
#ifndef DISABLE_HTTP #ifndef DISABLE_HTTP
#include <jansson/jansson.h> #include <jansson.h>
#include "../common.h" #include "../common.h"
typedef struct { typedef struct {