summaryrefslogtreecommitdiff
blob: ff7a8f25591cb0e34df6439feb3621649c90f120 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
Patch from https://gitlab.com/wireshark/wireshark/-/merge_requests/17202

From ac7e2e846ed8cbcaf7938d3bda3e289068af743c Mon Sep 17 00:00:00 2001
From: John Thacker <johnthacker@gmail.com>
Date: Mon, 9 Sep 2024 08:49:44 -0400
Subject: [PATCH] filesystem: Work around CMake absolute paths

CMake recommends that the various CMAKE_INSTALL_<dir> 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