r23989 by jghali - Backport #15671 changes in order to enable building relocatable binaries

scribus-commit scribus-commit at lists.scribus.net
Thu Aug 20 20:15:34 UTC 2020


Author: jghali
Date: Thu Aug 20 20:15:34 2020
New Revision: 23989

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23989
Log:
Backport #15671 changes in order to enable building relocatable binaries

Modified:
    branches/Version14x/Scribus/CMakeLists.txt
    branches/Version14x/Scribus/scribus/scpaths.cpp

Modified: branches/Version14x/Scribus/CMakeLists.txt
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23989&path=/branches/Version14x/Scribus/CMakeLists.txt
==============================================================================
--- branches/Version14x/Scribus/CMakeLists.txt	(original)
+++ branches/Version14x/Scribus/CMakeLists.txt	Thu Aug 20 20:15:34 2020
@@ -213,6 +213,22 @@
 MESSAGE(STATUS "Building for target ${MACHINE}")
 
 ##############################################################################################################
+########## Relocatability                                                                           ##########
+
+IF (APPLEBUNDLE OR WIN32)
+	IF (WANT_RELOCATABLE)
+		message(STATUS "Ignoring relocatable option on Win32 or OSX when building bundle")
+		set(WANT_RELOCATABLE OFF)
+	ENDIF(WANT_RELOCATABLE)
+ENDIF (APPLEBUNDLE OR WIN32)
+
+IF (WANT_RELOCATABLE)
+	message(STATUS "Enabling relocatable binaries")
+	set(WANT_RELOCATABLE ON CACHE BOOL "Enable relocatable binaries")
+	add_definitions(-DWANT_RELOCATABLE)
+ENDIF (WANT_RELOCATABLE)
+
+##############################################################################################################
 ########## Versioning Setup                                                                         ##########
 
 #On Apple, we ignore the versioning tag so all items are "scribus" not "scribus-version"
@@ -281,11 +297,16 @@
 ELSE(WANT_VERSIONING)
     SET(SHAREDIR "${CMAKE_INSTALL_DATAROOTDIR}/${MAIN_DIR_NAME}/")
 ENDIF(WANT_VERSIONING)
-IF(NOT IS_ABSOLUTE ${SHAREDIR})
-    ADD_DEFINITIONS("-DSHAREDIR=\\\"${CMAKE_INSTALL_PREFIX}/${SHAREDIR}\\\"")
-ELSE()
-    ADD_DEFINITIONS("-DSHAREDIR=\\\"${SHAREDIR}\\\"")
-ENDIF()
+
+IF (IS_ABSOLUTE ${SHAREDIR} AND WANT_RELOCATABLE)
+	message(FATAL_ERROR "ERROR: SHAREDIR must be relative when using WANT_RELOCATABLE option")
+ELSE (IS_ABSOLUTE ${SHAREDIR} AND WANT_RELOCATABLE)
+	IF (NOT IS_ABSOLUTE ${SHAREDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DSHAREDIR=\\\"${CMAKE_INSTALL_PREFIX}/${SHAREDIR}\\\"")
+	ELSE (NOT IS_ABSOLUTE ${SHAREDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DSHAREDIR=\\\"${SHAREDIR}\\\"")
+	ENDIF (NOT IS_ABSOLUTE ${SHAREDIR} AND NOT WANT_RELOCATABLE)
+ENDIF (IS_ABSOLUTE ${SHAREDIR} AND WANT_RELOCATABLE)
 
 #SHARE - use the default on Apple as TAG_VERSION is empty
 IF(WIN32 OR OS2)
@@ -301,11 +322,16 @@
         ENDIF(NOT WANT_VERSIONING)
   ENDIF (TAG_VERSION OR BUILD_OSX_BUNDLE)
 ENDIF (WIN32 OR OS2)
-IF(NOT IS_ABSOLUTE ${DOCDIR})
-    ADD_DEFINITIONS("-DDOCDIR=\\\"${CMAKE_INSTALL_PREFIX}/${DOCDIR}\\\"")
-ELSE()
-    ADD_DEFINITIONS("-DDOCDIR=\\\"${DOCDIR}\\\"")
-ENDIF()
+
+IF (IS_ABSOLUTE ${DOCDIR} AND WANT_RELOCATABLE)
+	message(FATAL_ERROR "ERROR: DOCDIR must be relative when using WANT_RELOCATABLE option")
+ELSE (IS_ABSOLUTE ${DOCDIR} AND WANT_RELOCATABLE)
+	IF (NOT IS_ABSOLUTE ${DOCDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DDOCDIR=\\\"${CMAKE_INSTALL_PREFIX}/${DOCDIR}\\\"")
+	ELSE (NOT IS_ABSOLUTE ${DOCDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DDOCDIR=\\\"${DOCDIR}\\\"")
+	ENDIF (NOT IS_ABSOLUTE ${DOCDIR} AND NOT WANT_RELOCATABLE)
+ENDIF (IS_ABSOLUTE ${DOCDIR} AND WANT_RELOCATABLE)
 
 #ICON
 IF(WIN32)
@@ -313,27 +339,50 @@
 ELSE(WIN32)
   SET(ICONDIR "${CMAKE_INSTALL_DATAROOTDIR}/${MAIN_DIR_NAME}${TAG_VERSION}/icons/")
 ENDIF(WIN32)
-IF(NOT IS_ABSOLUTE ${ICONDIR})
-    ADD_DEFINITIONS("-DICONDIR=\\\"${CMAKE_INSTALL_PREFIX}/${ICONDIR}\\\"")
+
+IF (IS_ABSOLUTE ${ICONDIR} AND WANT_RELOCATABLE)
+	message(FATAL_ERROR "ERROR: ICONDIR must be relative when using WANT_RELOCATABLE option")
+ELSE (IS_ABSOLUTE ${ICONDIR} AND WANT_RELOCATABLE)
+	IF (NOT IS_ABSOLUTE ${ICONDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DICONDIR=\\\"${CMAKE_INSTALL_PREFIX}/${ICONDIR}\\\"")
+	ELSE (NOT IS_ABSOLUTE ${ICONDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DICONDIR=\\\"${ICONDIR}\\\"")
+	ENDIF (NOT IS_ABSOLUTE ${ICONDIR} AND NOT WANT_RELOCATABLE)
+ENDIF (IS_ABSOLUTE ${ICONDIR} AND WANT_RELOCATABLE)
+
+#SAMPLES
+IF(WIN32)
+	set(SAMPLESDIR "${CMAKE_INSTALL_DATAROOTDIR}/samples/")
 ELSE()
-    ADD_DEFINITIONS("-DICONDIR=\\\"${ICONDIR}\\\"")
+	set(SAMPLESDIR "${CMAKE_INSTALL_DATAROOTDIR}/${MAIN_DIR_NAME}${TAG_VERSION}/samples/")
 ENDIF()
 
-#SAMPLES
-SET(SAMPLESDIR "${CMAKE_INSTALL_DATAROOTDIR}/${MAIN_DIR_NAME}${TAG_VERSION}/samples/")
-IF(NOT IS_ABSOLUTE ${SAMPLESDIR})
-    ADD_DEFINITIONS("-DSAMPLESDIR=\\\"${CMAKE_INSTALL_PREFIX}/${SAMPLESDIR}\\\"")
+IF (IS_ABSOLUTE ${SAMPLESDIR} AND WANT_RELOCATABLE)
+	message(FATAL_ERROR "ERROR: SAMPLESDIR must be relative when using WANT_RELOCATABLE option")
+ELSE (IS_ABSOLUTE ${SAMPLESDIR} AND WANT_RELOCATABLE)
+	IF (NOT IS_ABSOLUTE ${SAMPLESDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DSAMPLESDIR=\\\"${CMAKE_INSTALL_PREFIX}/${SAMPLESDIR}\\\"")
+	ELSE (NOT IS_ABSOLUTE ${SAMPLESDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DSAMPLESDIR=\\\"${SAMPLESDIR}\\\"")
+	ENDIF (NOT IS_ABSOLUTE ${SAMPLESDIR} AND NOT WANT_RELOCATABLE)
+ENDIF (IS_ABSOLUTE ${SAMPLESDIR} AND WANT_RELOCATABLE)
+
+#SCRIPTS
+IF(WIN32)
+	set(SCRIPTSDIR "${CMAKE_INSTALL_DATAROOTDIR}/scripts/")
 ELSE()
-    ADD_DEFINITIONS("-DSAMPLESDIR=\\\"${SAMPLESDIR}\\\"")
+	set(SCRIPTSDIR "${CMAKE_INSTALL_DATAROOTDIR}/${MAIN_DIR_NAME}${TAG_VERSION}/scripts/")
 ENDIF()
 
-#SCRIPTS
-SET(SCRIPTSDIR "${CMAKE_INSTALL_DATAROOTDIR}/${MAIN_DIR_NAME}${TAG_VERSION}/scripts/")
-IF(NOT IS_ABSOLUTE ${SCRIPTSDIR})
-    ADD_DEFINITIONS("-DSCRIPTSDIR=\\\"${CMAKE_INSTALL_PREFIX}/${SCRIPTSDIR}\\\"")
-ELSE()
-    ADD_DEFINITIONS("-DSCRIPTSDIR=\\\"${SCRIPTSDIR}\\\"")
-ENDIF()
+IF (IS_ABSOLUTE ${SCRIPTSDIR} AND WANT_RELOCATABLE)
+	message(FATAL_ERROR "ERROR: SCRIPTSDIR must be relative when using WANT_RELOCATABLE option")
+ELSE (IS_ABSOLUTE ${SCRIPTSDIR} AND WANT_RELOCATABLE)
+	IF (NOT IS_ABSOLUTE ${SCRIPTSDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DSCRIPTSDIR=\\\"${CMAKE_INSTALL_PREFIX}/${SCRIPTSDIR}\\\"")
+	ELSE (NOT IS_ABSOLUTE ${SCRIPTSDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DSCRIPTSDIR=\\\"${SCRIPTSDIR}\\\"")
+	ENDIF (NOT IS_ABSOLUTE ${SCRIPTSDIR} AND NOT WANT_RELOCATABLE)
+ENDIF (IS_ABSOLUTE ${SCRIPTSDIR} AND WANT_RELOCATABLE)
 
 #TEMPLATES
 IF(WIN32)
@@ -341,28 +390,42 @@
 ELSE(WIN32)
   SET(TEMPLATEDIR "${CMAKE_INSTALL_DATAROOTDIR}/${MAIN_DIR_NAME}${TAG_VERSION}/templates/")
 ENDIF(WIN32)
-IF(NOT IS_ABSOLUTE ${TEMPLATEDIR})
-    ADD_DEFINITIONS("-DTEMPLATEDIR=\\\"${CMAKE_INSTALL_PREFIX}/${TEMPLATEDIR}\\\"")
-ELSE()
-    ADD_DEFINITIONS("-DTEMPLATEDIR=\\\"${TEMPLATEDIR}\\\"")
-ENDIF()
+
+IF (IS_ABSOLUTE ${TEMPLATEDIR} AND WANT_RELOCATABLE)
+	message(FATAL_ERROR "ERROR: TEMPLATEDIR must be relative when using WANT_RELOCATABLE option")
+ELSE (IS_ABSOLUTE ${TEMPLATEDIR} AND WANT_RELOCATABLE)
+	IF (NOT IS_ABSOLUTE ${TEMPLATEDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DTEMPLATEDIR=\\\"${CMAKE_INSTALL_PREFIX}/${TEMPLATEDIR}\\\"")
+	ELSE (NOT IS_ABSOLUTE ${TEMPLATEDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DTEMPLATEDIR=\\\"${TEMPLATEDIR}\\\"")
+	ENDIF (NOT IS_ABSOLUTE ${TEMPLATEDIR} AND NOT WANT_RELOCATABLE)
+ENDIF (IS_ABSOLUTE ${TEMPLATEDIR} AND WANT_RELOCATABLE)
 
 #DESKTOP
 SET(DESKTOPDIR "${CMAKE_INSTALL_DATAROOTDIR}/applications/")
-IF(NOT IS_ABSOLUTE ${DESKTOPDIR})
-    ADD_DEFINITIONS("-DDESKTOPDIR=\\\"${CMAKE_INSTALL_PREFIX}/${DESKTOPDIR}\\\"")
-ELSE()
-    ADD_DEFINITIONS("-DDESKTOPDIR=\\\"${DESKTOPDIR}\\\"")
-ENDIF()
+
+IF (IS_ABSOLUTE ${DESKTOPDIR} AND WANT_RELOCATABLE)
+	message(FATAL_ERROR "ERROR: DESKTOPDIR must be relative when using WANT_RELOCATABLE option")
+ELSE (IS_ABSOLUTE ${DESKTOPDIR} AND WANT_RELOCATABLE)
+	IF (NOT IS_ABSOLUTE ${DESKTOPDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DDESKTOPDIR=\\\"${CMAKE_INSTALL_PREFIX}/${DESKTOPDIR}\\\"")
+	ELSE (NOT IS_ABSOLUTE ${DESKTOPDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DDESKTOPDIR=\\\"${DESKTOPDIR}\\\"")
+	ENDIF (NOT IS_ABSOLUTE ${DESKTOPDIR} AND NOT WANT_RELOCATABLE)
+ENDIF (IS_ABSOLUTE ${DESKTOPDIR} AND WANT_RELOCATABLE)
 
 #APPDATA
 SET(APPDATADIR "${CMAKE_INSTALL_DATAROOTDIR}/appdata/")
-IF(NOT IS_ABSOLUTE ${APPDATADIRR})
-    ADD_DEFINITIONS("-DAPPDATADIR=\\\"${CMAKE_INSTALL_PREFIX}/${APPDATADIR}\\\"")
-ELSE()
-    ADD_DEFINITIONS("-DAPPDATADIR=\\\"${APPDATADIR}\\\"")
-ENDIF()
-
+
+IF (IS_ABSOLUTE ${APPDATADIR} AND WANT_RELOCATABLE)
+	message(FATAL_ERROR "ERROR: APPDATADIR must be relative when using WANT_RELOCATABLE option")
+ELSE (IS_ABSOLUTE ${APPDATADIR} AND WANT_RELOCATABLE)
+	IF (NOT IS_ABSOLUTE ${APPDATADIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DAPPDATADIR=\\\"${CMAKE_INSTALL_PREFIX}/${APPDATADIR}\\\"")
+	ELSE (NOT IS_ABSOLUTE ${APPDATADIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DAPPDATADIR=\\\"${APPDATADIR}\\\"")
+	ENDIF (NOT IS_ABSOLUTE ${APPDATADIR} AND NOT WANT_RELOCATABLE)
+ENDIF (IS_ABSOLUTE ${APPDATADIR} AND WANT_RELOCATABLE)
 
 # APPLICATION_DATA_DIR
 # It allows specify the user configuration directory in the compile time.
@@ -383,25 +446,44 @@
   ENDIF(NOT ARCH_X86_64)
   SET(LIB_SUFFIX "64" CACHE TYPE STRING)
 ENDIF(WANT_LIB64)
+
 SET(LIB_DIR_NAME "lib${LIB_SUFFIX}")
 IF (APPLEBUNDLE)
   SET(LIBDIR "lib/")
 ELSE (APPLEBUNDLE)
   SET(LIBDIR "${LIB_DIR_NAME}/${MAIN_DIR_NAME}${TAG_VERSION}/")
 ENDIF (APPLEBUNDLE)
-ADD_DEFINITIONS("-DLIBDIR=\\\"${CMAKE_INSTALL_PREFIX}/${LIBDIR}\\\"")
+
+IF (IS_ABSOLUTE ${LIBDIR} AND WANT_RELOCATABLE)
+	message(FATAL_ERROR "ERROR: LIBDIR must be relative when using WANT_RELOCATABLE option")
+ELSE (IS_ABSOLUTE ${LIBDIR} AND WANT_RELOCATABLE)
+	IF (NOT IS_ABSOLUTE ${LIBDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DLIBDIR=\\\"${CMAKE_INSTALL_PREFIX}/${LIBDIR}\\\"")
+	ELSE (NOT IS_ABSOLUTE ${LIBDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DLIBDIR=\\\"${LIBDIR}\\\"")
+	ENDIF (NOT IS_ABSOLUTE ${LIBDIR} AND NOT WANT_RELOCATABLE)
+ENDIF (IS_ABSOLUTE ${LIBDIR} AND WANT_RELOCATABLE)
 
 #PLUGINS
-IF(WIN32)
-  SET(PLUGINDIR "plugins")
-ELSE(WIN32)
-  IF (APPLEBUNDLE)
-    SET(PLUGINDIR "${LIBDIR}")
-  ELSE (APPLEBUNDLE)
-    SET(PLUGINDIR "${LIB_DIR_NAME}/${MAIN_DIR_NAME}${TAG_VERSION}/plugins/")
-  ENDIF (APPLEBUNDLE)
-ENDIF(WIN32)
-ADD_DEFINITIONS("-DPLUGINDIR=\\\"${CMAKE_INSTALL_PREFIX}/${PLUGINDIR}\\\"")
+IF (WIN32)
+	set(PLUGINDIR "plugins")
+ELSE (WIN32)
+	IF (APPLEBUNDLE)
+		set(PLUGINDIR "${LIBDIR}")
+	ELSE (APPLEBUNDLE)
+		set(PLUGINDIR "${LIB_DIR_NAME}/${MAIN_DIR_NAME}${TAG_VERSION}/plugins/")
+	ENDIF (APPLEBUNDLE)
+ENDIF (WIN32)
+
+IF (IS_ABSOLUTE ${PLUGINDIR} AND WANT_RELOCATABLE)
+	message(FATAL_ERROR "ERROR: PLUGINDIR must be relative when using WANT_RELOCATABLE option")
+ELSE (IS_ABSOLUTE ${PLUGINDIR} AND WANT_RELOCATABLE)
+	IF (NOT IS_ABSOLUTE ${PLUGINDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DPLUGINDIR=\\\"${CMAKE_INSTALL_PREFIX}/${PLUGINDIR}\\\"")
+	ELSE (NOT IS_ABSOLUTE ${PLUGINDIR} AND NOT WANT_RELOCATABLE)
+		add_definitions("-DPLUGINDIR=\\\"${PLUGINDIR}\\\"")
+	ENDIF (NOT IS_ABSOLUTE ${PLUGINDIR} AND NOT WANT_RELOCATABLE)
+ENDIF (IS_ABSOLUTE ${PLUGINDIR} AND WANT_RELOCATABLE)
 
 #INCLUDE
 SET(INCLUDEDIR "include/${MAIN_DIR_NAME}${TAG_VERSION}/")

Modified: branches/Version14x/Scribus/scribus/scpaths.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23989&path=/branches/Version14x/Scribus/scribus/scpaths.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/scpaths.cpp	(original)
+++ branches/Version14x/Scribus/scribus/scpaths.cpp	Thu Aug 20 20:15:34 2020
@@ -49,17 +49,31 @@
 // Protected "real" constructor
 // All paths are initialized to compile-time defaults passed in
 // as preprocessor macros and set by autoconf.
-ScPaths::ScPaths() :
-	m_docDir(DOCDIR),
-	m_fontDir(),
-	m_iconDir(ICONDIR),
-	m_libDir(LIBDIR),
-	m_pluginDir(PLUGINDIR),
-	m_sampleScriptDir(SAMPLESDIR),
-	m_scriptDir(SCRIPTSDIR),
-	m_templateDir(TEMPLATEDIR),
-	m_shareDir(SHAREDIR)
-{
+ScPaths::ScPaths()
+{
+// On *nix, all paths are initialized to compile-time defaults passed in
+// as preprocessor macros and set by autoconf.
+#if !defined(Q_WS_MAC) && !defined(_WIN32) && defined(WANT_RELOCATABLE)
+	QString appPath = qApp->applicationDirPath();
+	m_docDir = appPath + "/../" + QString(DOCDIR);
+	m_iconDir = appPath + "/../" + QString(ICONDIR);
+	m_libDir = appPath + "/../" + QString(LIBDIR);
+	m_pluginDir = appPath + "/../" + QString(PLUGINDIR);
+	m_sampleScriptDir = appPath + "/../" + QString(SAMPLESDIR);
+	m_scriptDir = appPath + "/../" + QString(SCRIPTSDIR);
+	m_shareDir = appPath + "/../" + QString(SHAREDIR);
+	m_templateDir = appPath + "/../" + QString(TEMPLATEDIR);
+#elif !defined(Q_WS_MAC) && !defined(_WIN32)
+	m_docDir = QString(DOCDIR);
+	m_iconDir = QString(ICONDIR);
+	m_libDir = QString(LIBDIR);
+	m_pluginDir = QString(PLUGINDIR);
+	m_sampleScriptDir = QString(SAMPLESDIR);
+	m_scriptDir = QString(SCRIPTSDIR);
+	m_shareDir = QString(SHAREDIR);
+	m_templateDir = QString(TEMPLATEDIR);
+#endif
+
 // On MacOS/X, override the compile-time settings with a location
 // obtained from the system.
 #ifdef Q_WS_MAC




More information about the scribus-commit mailing list