Patch from https://gitlab.com/wireshark/wireshark/-/merge_requests/17202 From ac7e2e846ed8cbcaf7938d3bda3e289068af743c Mon Sep 17 00:00:00 2001 From: John Thacker Date: Mon, 9 Sep 2024 08:49:44 -0400 Subject: [PATCH] filesystem: Work around CMake absolute paths CMake recommends that the various CMAKE_INSTALL_ variables be relative paths, and we have been assuming that they are. Absolute paths are technically allowed. Work around absolute paths, and just don't look for the doc dir, etc. in relocated paths if they are. Fix #20055 --- wsutil/CMakeLists.txt | 5 +++++ wsutil/filesystem.c | 26 +++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index 2daf371ca2f..976446bcfe7 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -7,6 +7,11 @@ # SPDX-License-Identifier: GPL-2.0-or-later # +# CMake says that these paths should be relative to the install prefix +# https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html +# Things generally work if they're not, but it becomes impossible +# to relocate paths. Work around that, and just don't try to support +# relocation. file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}" PATH_INSTALL_PREFIX) string(REPLACE "\\" "\\\\" PATH_INSTALL_PREFIX "${PATH_INSTALL_PREFIX}") file(TO_NATIVE_PATH "${CMAKE_INSTALL_DATADIR}" PATH_DATA_DIR) diff --git a/wsutil/filesystem.c b/wsutil/filesystem.c index bec1cea25b6..942a8c7dcf0 100644 --- a/wsutil/filesystem.c +++ b/wsutil/filesystem.c @@ -1107,7 +1107,11 @@ get_datafile_dir(void) */ datafile_dir = g_strdup(progfile_dir); } else { - datafile_dir = g_build_filename(install_prefix, DATA_DIR, CONFIGURATION_NAMESPACE_LOWER, (char *)NULL); + if (g_path_is_absolute(DATA_DIR)) { + datafile_dir = g_build_filename(DATA_DIR, CONFIGURATION_NAMESPACE_LOWER, (char *)NULL); + } else { + datafile_dir = g_build_filename(install_prefix, DATA_DIR, CONFIGURATION_NAMESPACE_LOWER, (char *)NULL); + } } #endif return datafile_dir; @@ -1159,7 +1163,11 @@ get_doc_dir(void) */ doc_dir = g_strdup(progfile_dir); } else { - doc_dir = g_build_filename(install_prefix, DOC_DIR, (char *)NULL); + if (g_path_is_absolute(DOC_DIR)) { + doc_dir = g_strdup(DOC_DIR); + } else { + doc_dir = g_build_filename(install_prefix, DOC_DIR, (char *)NULL); + } } #endif return doc_dir; @@ -1246,7 +1254,11 @@ init_plugin_dir(void) */ plugin_dir = g_build_filename(get_progfile_dir(), "plugins", (char *)NULL); } else { - plugin_dir = g_build_filename(install_prefix, PLUGIN_DIR, (char *)NULL); + if (g_path_is_absolute(PLUGIN_DIR)) { + plugin_dir = g_strdup(PLUGIN_DIR); + } else { + plugin_dir = g_build_filename(install_prefix, PLUGIN_DIR, (char *)NULL); + } } #endif // HAVE_MSYSTEM / _WIN32 #endif /* defined(HAVE_PLUGINS) || defined(HAVE_LUA) */ @@ -1379,8 +1391,12 @@ init_extcap_dir(void) CONFIGURATION_NAMESPACE_LOWER, (char *)NULL); } else { - extcap_dir = g_build_filename(install_prefix, - is_packet_configuration_namespace() ? EXTCAP_DIR : LOG_EXTCAP_DIR, (char *)NULL); + if (g_path_is_absolute(EXTCAP_DIR)) { + extcap_dir = g_strdup(is_packet_configuration_namespace() ? EXTCAP_DIR : LOG_EXTCAP_DIR); + } else { + extcap_dir = g_build_filename(install_prefix, + is_packet_configuration_namespace() ? EXTCAP_DIR : LOG_EXTCAP_DIR, (char *)NULL); + } } #endif // HAVE_MSYSTEM / _WIN32 } -- GitLab