Rework install locations for better flexibility

Using the  CMake module  GNUInstallDirs to  set up  standard locations
which allows  better customisation for packagers  building for various
distributions.

The change does change some internal package file paths and will leave
some  files  in  old   locations  in  Windows  installations.  Running
uninstall  is probably  wise  on Windows  before  installing this  new
package layout if future clean uninstalls are desired.

Linux and other  *nix package maintainers can use  the CMake variables
CMAKE_INSTALL_xxx to vary the install paths of various components. See
the  CMake GNUInstallDirs  module documentation  for more  details. An
example might be for Slackware where package documents are expected to
be                            installed                           into
<install-prefix>/doc/<package-name>-<package-version>/ whereas the GNU
default         is         to        install         them         into
<install-prefix>/share/doc/<package-name>/.  To achieve  this set  the
CMake variable CMAKE_INSTALL_DOCDIR as follows when configuring:

cmake -D CMAKE_INSTALL_DOCDIR:PATH=doc/wsjtx-1.7.1 -D CMAKE_INSTALL_PREFIX= ...

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@7623 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Bill Somerville
2017-03-28 13:03:48 +00:00
parent 38ab140ab6
commit 0e214efb9c
6 changed files with 87 additions and 116 deletions
+41 -50
View File
@@ -731,14 +731,48 @@ void Configuration::sync_transceiver (bool force_signal, bool enforce_mode_and_s
}
}
namespace
{
#if defined (Q_OS_MAC)
char const * app_root = "/../../../";
#else
char const * app_root = "/../";
#endif
QString doc_path ()
{
#if CMAKE_BUILD
if (QDir::isRelativePath (CMAKE_INSTALL_DOCDIR))
{
return QApplication::applicationDirPath () + app_root + CMAKE_INSTALL_DOCDIR;
}
return CMAKE_INSTALL_DOCDIR;
#else
return QApplication::applicationDirPath ();
#endif
}
QString data_path ()
{
#if CMAKE_BUILD
if (QDir::isRelativePath (CMAKE_INSTALL_DATADIR))
{
return QApplication::applicationDirPath () + app_root + CMAKE_INSTALL_DATADIR + QChar {'/'} + CMAKE_PROJECT_NAME;
}
return CMAKE_INSTALL_DATADIR;
#else
return QApplication::applicationDirPath ();
#endif
}
}
Configuration::impl::impl (Configuration * self, QDir const& temp_directory,
QSettings * settings, QWidget * parent)
: QDialog {parent}
, self_ {self}
, ui_ {new Ui::configuration_dialog}
, settings_ {settings}
, doc_dir_ {QApplication::applicationDirPath ()}
, data_dir_ {QApplication::applicationDirPath ()}
, doc_dir_ {doc_path ()}
, data_dir_ {data_path ()}
, temp_dir_ {temp_directory}
, frequencies_ {&bands_}
, next_frequencies_ {&bands_}
@@ -763,63 +797,20 @@ Configuration::impl::impl (Configuration * self, QDir const& temp_directory,
ui_->setupUi (this);
// ui_->groupBox_6->setVisible(false); //### Temporary ??? ###
#if !defined (CMAKE_BUILD)
#define WSJT_SHARE_DESTINATION "."
#define WSJT_DOC_DESTINATION "."
#define WSJT_DATA_DESTINATION "."
#endif
#if !defined (Q_OS_WIN) || QT_VERSION >= 0x050300
auto doc_path = QStandardPaths::locate (QStandardPaths::DataLocation, WSJT_DOC_DESTINATION, QStandardPaths::LocateDirectory);
if (doc_path.isEmpty ())
{
doc_dir_.cdUp ();
#if defined (Q_OS_MAC)
doc_dir_.cdUp ();
doc_dir_.cdUp ();
#endif
doc_dir_.cd (WSJT_SHARE_DESTINATION);
doc_dir_.cd (WSJT_DOC_DESTINATION);
}
else
{
doc_dir_.cd (doc_path);
}
auto data_path = QStandardPaths::locate (QStandardPaths::DataLocation, WSJT_DATA_DESTINATION, QStandardPaths::LocateDirectory);
if (data_path.isEmpty ())
{
data_dir_.cdUp ();
#if defined (Q_OS_MAC)
data_dir_.cdUp ();
data_dir_.cdUp ();
#endif
data_dir_.cd (WSJT_SHARE_DESTINATION);
data_dir_.cd (WSJT_DATA_DESTINATION);
}
else
{
data_dir_.cd (data_path);
}
#else
doc_dir_.cd (WSJT_DOC_DESTINATION);
data_dir_.cd (WSJT_DATA_DESTINATION);
#endif
{
// Find a suitable data file location
QDir data_dir {QStandardPaths::writableLocation (QStandardPaths::DataLocation)};
if (!data_dir.mkpath ("."))
QDir writeable_data_dir {QStandardPaths::writableLocation (QStandardPaths::DataLocation)};
if (!writeable_data_dir.mkpath ("."))
{
MessageBox::critical_message (this, tr ("Failed to create data directory"),
tr ("path: \"%1\"").arg (data_dir.absolutePath ()));
tr ("path: \"%1\"").arg (writeable_data_dir.absolutePath ()));
throw std::runtime_error {"Failed to create data directory"};
}
// Make sure the default save directory exists
QString save_dir {"save"};
default_save_directory_ = data_dir;
default_azel_directory_ = data_dir;
default_save_directory_ = writeable_data_dir;
default_azel_directory_ = writeable_data_dir;
if (!default_save_directory_.mkpath (save_dir) || !default_save_directory_.cd (save_dir))
{
MessageBox::critical_message (this, tr ("Failed to create save directory"),