Package: toppic / 1.3.0+dfsg1-4

0002-Use-the-CMake-build-system-to-configure-the-DATADIR-.patch Patch series | download
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
From: Filippo Rusconi <lopippo@debian.org>
Date: Thu, 21 May 2020 22:20:48 +0200
Subject: Use the CMake build system to configure the DATADIR in
 /usr/share/toppic.

---
 CMakeLists.txt                | 9 +++++++--
 cmake/config.h.in             | 2 ++
 src/common/util/file_util.cpp | 8 ++++----
 src/common/util/file_util.hpp | 4 +++-
 4 files changed, 16 insertions(+), 7 deletions(-)
 create mode 100644 cmake/config.h.in

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0fd5226..fc93f80 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,7 +9,12 @@ SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../bin)
 
 SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/../lib)
 
-SET(CMAKE_INSTALL_PREFIX ${HOME}/toppic)
+SET(CMAKE_INSTALL_PREFIX /usr)
+SET(TOPPIC_DATA_DIR ${CMAKE_INSTALL_PREFIX}/share/toppic)
+
+# Now configure the software with the TOPPIC_DATA_DIR variable.
+configure_file(${CMAKE_SOURCE_DIR}/cmake/config.h.in
+	${CMAKE_BINARY_DIR}/config.h)
 
 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -O3 -DWITHOUT_MZ5 -fPIC")
 #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall  -g -std=c++11  -DWITHOUT_MZ5 -fPIC")
@@ -277,7 +282,7 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
 
 #file(MAKE_DIRECTORY ${CMAKE_INSTALL_PREFIX}/usr/bin)
 install (TARGETS topfd toppic topmg topdiff DESTINATION ${CMAKE_INSTALL_PREFIX}/usr/bin/)
-install (DIRECTORY toppic_resources/ DESTINATION ${CMAKE_INSTALL_PREFIX}/etc/toppic)
+install (DIRECTORY toppic_resources/ DESTINATION ${TOPPIC_DATA_DIR})
 
 ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux") 
 
diff --git a/cmake/config.h.in b/cmake/config.h.in
new file mode 100644
index 0000000..25159e9
--- /dev/null
+++ b/cmake/config.h.in
@@ -0,0 +1,2 @@
+#define TOPPIC_DATA_DIR "@TOPPIC_DATA_DIR@"
+
diff --git a/src/common/util/file_util.cpp b/src/common/util/file_util.cpp
index 1c28e6c..fe46768 100644
--- a/src/common/util/file_util.cpp
+++ b/src/common/util/file_util.cpp
@@ -73,11 +73,11 @@ std::string getResourceDir(const std::string &exec_dir) {
   }
 #if defined (_WIN32) || defined (_WIN64) || defined (__MINGW32__) || defined (__MINGW64__)
 #else
-  std::string etc_dir = exec_dir + getFileSeparator() + getEtcDirName();
-  if (exists(etc_dir)) {
-    return etc_dir;
+  std::string data_dir = getDataDirName();
+  if (exists(data_dir)) {
+    return data_dir;
   }
-  LOG_ERROR("The resource directory " << etc_dir << " does not exist!"); 
+  LOG_ERROR("The resource directory " << data_dir << " does not exist!"); 
 #endif
   LOG_ERROR("The resource directory " << resource_dir << " does not exist!"); 
   exit(EXIT_FAILURE);
diff --git a/src/common/util/file_util.hpp b/src/common/util/file_util.hpp
index 3ee11db..3d4e640 100644
--- a/src/common/util/file_util.hpp
+++ b/src/common/util/file_util.hpp
@@ -17,6 +17,8 @@
 
 #include <string>
 
+#include "config.h"
+
 namespace toppic {
 
 namespace file_util {
@@ -68,7 +70,7 @@ void moveFile(std::string &file_name, std::string &folder_name);
 
 inline std::string getToppicResourceDirName() {return "toppic_resources";}
 
-inline std::string getEtcDirName() {return "../../etc/toppic";}
+inline std::string getDataDirName() {return TOPPIC_DATA_DIR;}
 
 std::string getResourceDir(const std::string &exec_dir);