Lots of changes to make glest binary more portable on linux.

This commit is contained in:
Jammyjamjamman 2019-04-12 21:28:19 +01:00
parent 629229a6bf
commit 35b08573f8
No known key found for this signature in database
GPG Key ID: A5541C132A56EAB4
9 changed files with 107 additions and 61 deletions

View File

@ -193,20 +193,28 @@ IF(CMAKE_COMPILER_IS_GNUCXX OR MINGW)
MESSAGE(STATUS "Using snapcraft path...")
ADD_DEFINITIONS("-DSNAPCRAFT")
ENDIF()
IF(NOT CMAKE_INSTALL_PREFIX)
SET(CMAKE_INSTALL_PREFIX "/usr")
ENDIF()
IF(NOT INSTALL_DIR_BIN)
SET(INSTALL_DIR_BIN "${CMAKE_INSTALL_PREFIX}/games/" CACHE PATH "The installation path for binaries")
IF(NOT BINDIR)
SET(BINDIR "/bin/")
add_definitions("-DBINDIR=${BINDIR}")
SET(INSTALL_DIR_BIN "${CMAKE_INSTALL_PREFIX}/${BINDIR}" CACHE PATH "The installation path for binaries")
ENDIF()
# The data dir will get defined as a macro at compile-time
IF(NOT INSTALL_DIR_DATA)
SET(INSTALL_DIR_DATA "${CMAKE_INSTALL_PREFIX}/share/glest/" CACHE PATH "The installation path for data files")
IF(NOT DATADIR)
SET(DATADIR "/share/glest/" CACHE PATH "The path for the executable to find data files")
add_definitions("-DDATADIR=${DATADIR}")
SET(INSTALL_DIR_DATA "${CMAKE_INSTALL_PREFIX}/${DATADIR}" CACHE PATH "The installation path for data files")
ENDIF()
SET(INSTALL_DIR_INI "${INSTALL_DIR_DATA}")
IF(NOT INSTALL_DIR_DESKTOP)
SET(INSTALL_DIR_DESKTOP "${CMAKE_INSTALL_PREFIX}/applications/" CACHE PATH "The installation path for desktop files")
SET(INSTALL_DIR_DESKTOP "${CMAKE_INSTALL_PREFIX}/share/applications/" CACHE PATH "The installation path for desktop files")
ENDIF()
IF(NOT INSTALL_DIR_ICON)
SET(INSTALL_DIR_ICON "${CMAKE_INSTALL_PREFIX}/share/pixmaps/" CACHE PATH "The installation path for icon files")
SET(INSTALL_DIR_ICON "${CMAKE_INSTALL_PREFIX}/share/icons/hicolor/256x256/apps" CACHE PATH "The installation path for icon files")
ENDIF()
IF(NOT INSTALL_DIR_MAN)
SET(INSTALL_DIR_MAN "${CMAKE_INSTALL_PREFIX}/share/man/man6/" CACHE PATH "The installation path for manpage files")

View File

@ -6,38 +6,43 @@ then
echo "Ubuntu 18.04 is required! System found: $ID $VERSION_ID"
fi;
rm -rf Glest
mkdir Glest
mkdir deps
echo "\nGetting build deps..."
echo
echo "Getting build deps..."
sudo ../linux/build-deps.sh
echo "\nGetting and installing required libs..."
sudo apt clean
sudo apt --download-only --reinstall install famfamfam-flag-png p7zip-full libcurl4 libfontconfig1 libfribidi0 libftgl2 libgcc1 libgl1-mesa-glx libgl1 libglew2.0 libglu1-mesa libircclient1 libjpeg8 liblua5.3-0 libminiupnpc10 libopenal1 libpng16-16 libsdl2-2.0-0 libstdc++6 libvorbisfile3 libwxbase3.0-0v5 libwxgtk3.0-0v5 libx11-6 libpulse0
cp /var/cache/apt/archives/*.deb deps
mkdir curdep
cd curdep
for f in ../deps/*.deb;
do
ar x $f
tar -xf data.tar.* -C ../Glest
rm *
done;
cd ..
rm -rf curdep deps
echo "\nBuilding and installing Glest..."
echo
echo "Building and installing Glest..."
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_MAP_EDITOR=OFF -DBUILD_MODEL_VIEWER=OFF -DINSTALL_DIR_BIN=/usr/bin/ -DINSTALL_DIR_DATA=/usr/share/glest/ ../../..
make -j$(nproc) DESTDIR=../Glest
cmake -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_MAP_EDITOR=OFF -DBUILD_MODEL_VIEWER=OFF ../../..
make -j$(nproc) && make install DESTDIR=../Glest
rm -r *
echo "\n Getting and installing data..."
git clone https://github.com/glest/glest-data.git
mkdir build && cd build
cmake -DINSTALL_DIR_BIN=/usr/bin/ -DINSTALL_DIR_DATA=/usr/share/glest/ -DINSTALL_DIR_DESKTOP=/usr/share/applications/ -DINSTALL_DIR_ICON=/usr/share/icons/hicolor/256x256/ glest-data
make -j$(nproc) DESTDIR=../Glest
echo
echo "Getting and installing data..."
../../linux/clone-data.sh
cmake -DCMAKE_INSTALL_PREFIX=/usr ../../linux/../data
make && make install DESTDIR=../Glest
cd ..
rm -rf build
# Remove useless metainfo.
rm Glest/usr/share/metainfo/io.glest.Editor.appdata.xml
wget -c "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage"
echo
echo "Creating the AppImage..."
# Path to pulseaudio libs.
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/pulseaudio/
:/usr/lib/i386-linux-gnu/pulseaudio/:$LD_LIBRARY_PATH
chmod +x linuxdeploy-x86_64.AppImage
./linuxdeploy-x86_64.AppImage --appdir=Glest --output appimage
chmod +x Glest*.AppImage
echo
echo "done!"

View File

@ -19,10 +19,9 @@ parts:
glest:
plugin: cmake
configflags:
- "-DCMAKE_INSTALL_PREFIX=/usr"
- "-DBUILD_MAP_EDITOR=OFF"
- "-DBUILD_MODEL_VIEWER=OFF"
- "-DINSTALL_DIR_BIN=/usr/bin/"
- "-DINSTALL_DIR_DATA=/share/glest/"
source-type: git
source: https://github.com/glest/glest-source.git
#source-type: local
@ -95,10 +94,9 @@ parts:
glest-data:
plugin: cmake
configflags:
- "-DINSTALL_DIR_BIN=/usr/bin/"
- "-DINSTALL_DIR_DATA=/share/glest/"
- "-DINSTALL_DIR_DESKTOP=/share/applications/"
- "-DINSTALL_DIR_ICON=/share/glest/"
- "-DCMAKE_INSTALL_PREFIX=/usr"
- "-DBUILD_MAP_EDITOR=OFF"
- "-DBUILD_MODEL_VIEWER=OFF"
#source-type: local
#source: glest-data
source-type: git

View File

@ -9,7 +9,6 @@ IF(BUILD_GLEST)
MESSAGE(STATUS "Build ${TARGET_NAME} = YES")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=gnu++11")
add_definitions("-DDATADIR=${INSTALL_DIR_DATA}")
# This is an environment var that pops up when building with snapcraft.
# Use this to activate snapcraft path...

View File

@ -233,12 +233,10 @@ namespace Game {
foundPath = tryCustomPath(cfgType, fileName, custom_path);
}
#ifndef SNAPCRAFT
if (foundPath == false) {
currentpath = extractDirectoryPathFromFile(Properties::getApplicationPath());
foundPath = tryCustomPath(cfgType, fileName, currentpath);
}
#endif
#ifdef _WIN32
if (foundPath == false) {
@ -265,16 +263,11 @@ namespace Game {
}
#endif
#ifdef SNAPCRAFT
if (foundPath == false) {
foundPath = tryCustomPath(cfgType, fileName, std::getenv("SNAP") +
endPathWithSlash(formatPath(TOSTRING(DATADIR))));
}
#endif
#ifdef DATADIR
if (foundPath == false) {
foundPath = tryCustomPath(cfgType, fileName, endPathWithSlash(formatPath(TOSTRING(DATADIR))));
#if defined(DATADIR) && defined(BINDIR)
if ((foundPath == false)) {
currentpath = getDatPath();
foundPath = tryCustomPath(cfgType, fileName, currentpath);
}
#endif

View File

@ -3,8 +3,6 @@
OPTION(FORCE_EMBEDDED_LIBS "Force use of embedded libraries' code." OFF)
add_definitions("-DDATADIR=${INSTALL_DIR_DATA}")
# On Travis, the build fails on osx and Ubuntu trusty using
# clang 5.0 unless the -std=c++11 if used
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")

View File

@ -300,6 +300,13 @@ namespace Shared {
}
};
#ifdef __linux__
std::string getExecPath();
#endif // __linux
void eraseSubStr(std::string & mainStr, const std::string & toErase);
#if defined(DATADIR) && defined(BINDIR)
string getDatPath();
#endif
}
} //end namespace

View File

@ -53,12 +53,10 @@ namespace Shared {
namespace Util {
string Properties::applicationPath = "";
#ifdef SNAPCRAFT
string Properties::applicationDataPath = std::getenv("SNAP") + formatPath(TOSTRING(DATADIR));
#elif FLATPAK
string Properties::applicationDataPath = formatPath(TOSTRING(DATADIR));
#if defined(DATADIR) && defined(BINDIR)
string Properties::applicationDataPath = getDatPath();
#else
string Properties::applicationDataPath = "";
string Properties::applicationDataPath = "";
#endif
string Properties::techtreePath = "";
string Properties::scenarioPath = "";
@ -245,7 +243,7 @@ namespace Shared {
//char pMBBuffer[MAX_PATH + 1]="";
//wcstombs_s(&size, &pMBBuffer[0], (size_t)size, wBuf, (size_t)size);// Convert to char* from TCHAR[]
//string appPath="";
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
std::string appPath = utf8_encode(szPath);
replaceAll(appPath, "\\", "/");
@ -266,8 +264,7 @@ namespace Shared {
mapTagReplacementValues["$APPLICATIONPATH"] = Properties::applicationPath;
mapTagReplacementValues["%%APPLICATIONPATH%%"] = Properties::applicationPath;
mapTagReplacementValues["{APPLICATIONPATH}"] = Properties::applicationPath;
mapTagReplacementValues["$APPLICATIONDATAPATH"] = Properties::applicationDataPath;
mapTagReplacementValues["$APPLICATIONDATAPATH"] = Properties::applicationPath;
mapTagReplacementValues["%%APPLICATIONDATAPATH%%"] = Properties::applicationDataPath;
mapTagReplacementValues["{APPLICATIONDATAPATH}"] = Properties::applicationDataPath;
@ -372,7 +369,7 @@ namespace Shared {
//char pMBBuffer[MAX_PATH + 1]="";
//wcstombs_s(&size, &pMBBuffer[0], (size_t)size, wBuf, (size_t)size);// Convert to char* from TCHAR[]
//string appPath="";
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
//appPath.assign(&pMBBuffer[0]); // Now assign the char* to the string, and there you have it!!! :)
std::string appPath = utf8_encode(szPath);
//string appPath = szPath;

View File

@ -32,6 +32,7 @@
#include <io.h> // for open()
#else
#include <unistd.h>
#include <limits.h>
#endif
#include <sys/stat.h> // for open()
@ -874,5 +875,45 @@ namespace Shared {
return 0;
}
}
#ifdef __linux__
std::string getExecPath() {
char buff[PATH_MAX];
ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1);
if (len != -1) {
buff[len] = '\0';
return std::string(buff);
}
/* handle error condition */
return std::string("");
}
#endif // __linux__
void eraseSubStr(std::string & mainStr, const std::string & toErase)
{
// Search for the substring in string
size_t pos = mainStr.find(toErase);
if (pos != std::string::npos)
{
// If found then erase it from string
mainStr.erase(pos, toErase.length());
}
}
#if defined(DATADIR) && defined(BINDIR)
string getDatPath() {
string curPath = getExecPath();
printf("\n binary Path: %s", curPath.c_str());
const string subBinPath = endPathWithSlash(formatPath(TOSTRING(BINDIR))) + "glest";
printf("\n binary Path: %s", subBinPath.c_str());
eraseSubStr(curPath, subBinPath);
printf("\n path now: %s", curPath.c_str());
string datPath = curPath + endPathWithSlash(TOSTRING(DATADIR));
printf("\n what is this???: %s", TOSTRING(DATADIR));
printf("\n data path: %s", datPath.c_str());
return datPath;
}
#endif
}
} //end namespace