Add installation and packaging in cmake.

Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
Andrea Odetti 2020-07-12 15:53:53 +01:00
parent 2ebcb856a3
commit 60beb9aa58
6 changed files with 45 additions and 9 deletions

View file

@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 3.9)
include(CPack)
project(applewin)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-multichar -Werror=return-type")

View file

@ -84,3 +84,5 @@ target_link_libraries(appleii PRIVATE
${YAML_LIBRARIES}
${MINIZIP_LIBRARIES}
)
install(TARGETS appleii)

View file

@ -1,4 +1,5 @@
include(FindPkgConfig)
include(GNUInstallDirs)
add_executable(applen
main.cpp
@ -36,5 +37,10 @@ target_link_libraries(applen PRIVATE
appleii
)
file(RELATIVE_PATH RESOURCE_PATH ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/resource)
file(RELATIVE_PATH ROOT_PATH ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
file(RELATIVE_PATH SHARE_PATH ${CMAKE_INSTALL_FULL_BINDIR} ${CMAKE_INSTALL_FULL_DATADIR}/applewin)
configure_file(config.h.in config.h)
install(TARGETS applen)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/resource DESTINATION ${CMAKE_INSTALL_DATADIR}/applewin)

View file

@ -1,2 +1,3 @@
// relative path from executable to resources
#cmakedefine RESOURCE_PATH "@RESOURCE_PATH@"
#cmakedefine ROOT_PATH "@ROOT_PATH@"
#cmakedefine SHARE_PATH "@SHARE_PATH@"

View file

@ -1,6 +1,5 @@
#include "StdAfx.h"
#include <sstream>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
@ -11,21 +10,45 @@
namespace
{
bool dirExists(const std::string & folder)
{
struct stat stdbuf;
if (stat(folder.c_str(), &stdbuf) == 0 && S_ISDIR(stdbuf.st_mode))
{
return true;
}
else
{
return false;
}
}
std::string getResourcePath()
{
std::ostringstream resource;
char self[1024] = {0};
const int ch = readlink("/proc/self/exe", self, sizeof(self));
if (ch != -1)
{
const char * path = dirname(self);
resource << path;
resource << '/';
resource << RESOURCE_PATH;
resource << '/';
// case 1: run from the build folder
const std::string path1 = std::string(path) + '/'+ ROOT_PATH + "/resource/";
if (dirExists(path1))
{
return path1;
}
// case 2: run from the installation folder
const std::string path2 = std::string(path) + '/'+ SHARE_PATH + "/resource/";
if (dirExists(path2))
{
return path2;
}
}
// else?
return resource.str();
return std::string();
}
const std::string resourcePath = getResourcePath();

View file

@ -35,3 +35,5 @@ target_link_libraries(qapple PRIVATE
Qt5::Multimedia
appleii
)
install(TARGETS qapple)