File: Add_OpenEXR_3.x_support.patch

package info (click to toggle)
field3d 1.7.3-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,732 kB
  • sloc: cpp: 25,324; ansic: 2,594; python: 221; sh: 72; makefile: 26
file content (260 lines) | stat: -rw-r--r-- 9,076 bytes parent folder | download | duplicates (2)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
From: Richard Shaw <hobbes1069@fedoraproject.org>
Date: Sun, 19 Feb 2023 10:48:42 +0100
Forwarded: not-needed
Subject: Add_OpenEXR_3.x_support

---
 CMakeLists.txt               | 25 +++++++++++++++++++----
 export/Curve.h               | 21 ++++++++++++++++++--
 export/StdMathLib.h          | 47 +++++++++++++++++++++++++++++++++-----------
 include/OgIAttribute.h       | 17 +++++++++++++++-
 include/OgUtil.h             | 17 +++++++++++++++-
 include/UtilFoundation.h     | 17 +++++++++++++++-
 test/unit_tests/UnitTest.cpp | 17 +++++++++++++++-
 7 files changed, 139 insertions(+), 22 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1610c2e..314e37f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -49,7 +49,13 @@ FIND_PACKAGE (Boost COMPONENTS regex thread program_options system)
 FIND_PACKAGE (MPI)
 ENDIF ()
 
-FIND_PACKAGE (ILMBase)
+# First, try to find just the right config files
+find_package(Imath CONFIG)
+if (NOT TARGET Imath::Imath)
+    # Couldn't find Imath::Imath, maybe it's older and has IlmBase?
+    find_package(IlmBase CONFIG)
+endif ()
+find_package(OpenEXR CONFIG)
 
 # Allow the developer to select if Dynamic or Static libraries are built
 OPTION (BUILD_SHARED_LIBS "Build Shared Libraries" ON)
@@ -146,9 +152,20 @@ IF ( CMAKE_HOST_UNIX )
       LIST ( APPEND Field3D_Libraries_Shared
              ${MPI_LIBRARIES} )
   ENDIF ( MPI_FOUND )
-  LIST ( APPEND Field3D_Libraries_Shared
-    Iex Half IlmThread Imath
-    pthread dl z )
+  if(TARGET Imath::Imath)
+	  list(APPEND Field3D_Libraries_Shared
+        # For OpenEXR/Imath 3.x:
+          $<$<TARGET_EXISTS:OpenEXR::OpenEXR>:OpenEXR::OpenEXR>
+          $<$<TARGET_EXISTS:Imath::Imath>:Imath::Imath>
+          $<$<TARGET_EXISTS:Imath::Half>:Imath::Half>
+		  pthread
+		  dl
+		  z)
+  else()
+    LIST ( APPEND Field3D_Libraries_Shared
+        Iex Half IlmThread Imath
+        pthread dl z )
+  endif()
   SET ( Field3D_DSO_Libraries ${Field3D_Libraries_Shared} )
   SET ( Field3D_BIN_Libraries Field3D ${Field3D_Libraries_Shared}
         ${Boost_LIBRARIES} )
diff --git a/export/Curve.h b/export/Curve.h
index 8b1b6cc..83132f0 100644
--- a/export/Curve.h
+++ b/export/Curve.h
@@ -53,8 +53,25 @@
 
 #include <boost/lexical_cast.hpp>
 
-#include <OpenEXR/ImathFun.h>
-#include <OpenEXR/ImathMatrix.h>
+// The version can reliably be found in this header file from OpenEXR,
+// for both 2.x and 3.x:
+#include <OpenEXR/OpenEXRConfig.h>
+#define COMBINED_OPENEXR_VERSION ((10000*OPENEXR_VERSION_MAJOR) + \
+                                  (100*OPENEXR_VERSION_MINOR) + \
+                                  OPENEXR_VERSION_PATCH)
+
+// There's just no easy way to have an `#include` that works in both
+// cases, so we use the version to switch which set of include files we
+// use.
+#if COMBINED_OPENEXR_VERSION >= 20599 /* 2.5.99: pre-3.0 */
+#   include <Imath/ImathFun.h>
+#   include <Imath/ImathMatrix.h>
+#else
+    // OpenEXR 2.x, use the old locations
+#   include <OpenEXR/ImathFun.h>
+#   include <OpenEXR/ImathMatrix.h>
+#endif
+
 
 //----------------------------------------------------------------------------//
 
diff --git a/export/StdMathLib.h b/export/StdMathLib.h
index 5551df4..a31f024 100644
--- a/export/StdMathLib.h
+++ b/export/StdMathLib.h
@@ -38,18 +38,41 @@
 #ifndef _INCLUDED_Field3D_StdMathLib_H_
 #define _INCLUDED_Field3D_StdMathLib_H_
 
-#include <OpenEXR/ImathBox.h> 
-#include <OpenEXR/ImathBoxAlgo.h>
-#include <OpenEXR/ImathColor.h>
-#include <OpenEXR/ImathHalfLimits.h>
-#include <OpenEXR/ImathMatrix.h>
-#include <OpenEXR/ImathMatrixAlgo.h>
-#include <OpenEXR/ImathPlane.h>
-#include <OpenEXR/ImathRandom.h> 
-#include <OpenEXR/ImathRoots.h>
-#include <OpenEXR/ImathVec.h>
-#include <OpenEXR/half.h> 
-
+// The version can reliably be found in this header file from OpenEXR,
+// for both 2.x and 3.x:
+#include <OpenEXR/OpenEXRConfig.h>
+#define COMBINED_OPENEXR_VERSION ((10000*OPENEXR_VERSION_MAJOR) + \
+                                  (100*OPENEXR_VERSION_MINOR) + \
+                                  OPENEXR_VERSION_PATCH)
+
+// There's just no easy way to have an `#include` that works in both
+// cases, so we use the version to switch which set of include files we
+// use.
+#if COMBINED_OPENEXR_VERSION >= 20599 /* 2.5.99: pre-3.0 */
+#   include <Imath/ImathBox.h>
+#   include <Imath/ImathBoxAlgo.h>
+#   include <Imath/ImathColor.h>
+#   include <Imath/ImathMatrix.h>
+#   include <Imath/ImathMatrixAlgo.h>
+#   include <Imath/ImathPlane.h>
+#   include <Imath/ImathRandom.h>
+#   include <Imath/ImathRoots.h>
+#   include <Imath/ImathVec.h>
+#   include <Imath/half.h>
+#else
+    // OpenEXR 2.x, use the old locations
+#   include <OpenEXR/ImathBox.h>
+#   include <OpenEXR/ImathBoxAlgo.h>
+#   include <OpenEXR/ImathColor.h>
+#   include <OpenEXR/ImathHalfLimits.h>
+#   include <OpenEXR/ImathMatrix.h>
+#   include <OpenEXR/ImathMatrixAlgo.h>
+#   include <OpenEXR/ImathPlane.h>
+#   include <OpenEXR/ImathRandom.h>
+#   include <OpenEXR/ImathRoots.h>
+#   include <OpenEXR/ImathVec.h>
+#   include <OpenEXR/half.h>
+#endif
 //----------------------------------------------------------------------------//
 
 #include "ns.h"
diff --git a/include/OgIAttribute.h b/include/OgIAttribute.h
index 7d0e128..2f27e80 100644
--- a/include/OgIAttribute.h
+++ b/include/OgIAttribute.h
@@ -9,7 +9,22 @@
 
 #include "OgUtil.h"
 
-#include <OpenEXR/ImathMatrix.h>
+// The version can reliably be found in this header file from OpenEXR,
+// for both 2.x and 3.x:
+#include <OpenEXR/OpenEXRConfig.h>
+#define COMBINED_OPENEXR_VERSION ((10000*OPENEXR_VERSION_MAJOR) + \
+                                  (100*OPENEXR_VERSION_MINOR) + \
+                                  OPENEXR_VERSION_PATCH)
+
+// There's just no easy way to have an `#include` that works in both
+// cases, so we use the version to switch which set of include files we
+// use.
+#if COMBINED_OPENEXR_VERSION >= 20599 /* 2.5.99: pre-3.0 */
+#   include <Imath/ImathMatrix.h>
+#else
+    // OpenEXR 2.x, use the old locations
+#   include <OpenEXR/ImathMatrix.h>
+#endif
 
 //----------------------------------------------------------------------------//
 
diff --git a/include/OgUtil.h b/include/OgUtil.h
index 07254c7..0623859 100644
--- a/include/OgUtil.h
+++ b/include/OgUtil.h
@@ -10,7 +10,22 @@
 #include <iostream>
 #include <string>
 
-#include <OpenEXR/ImathVec.h>
+// The version can reliably be found in this header file from OpenEXR,
+// for both 2.x and 3.x:
+#include <OpenEXR/OpenEXRConfig.h>
+#define COMBINED_OPENEXR_VERSION ((10000*OPENEXR_VERSION_MAJOR) + \
+                                  (100*OPENEXR_VERSION_MINOR) + \
+                                  OPENEXR_VERSION_PATCH)
+
+// There's just no easy way to have an `#include` that works in both
+// cases, so we use the version to switch which set of include files we
+// use.
+#if COMBINED_OPENEXR_VERSION >= 20599 /* 2.5.99: pre-3.0 */
+#   include <Imath/ImathVec.h>
+#else
+    // OpenEXR 2.x, use the old locations
+#   include <OpenEXR/ImathVec.h>
+#endif
 
 #include "All.h"
 #include "UtilFoundation.h"
diff --git a/include/UtilFoundation.h b/include/UtilFoundation.h
index 2eb6290..48f0d4b 100644
--- a/include/UtilFoundation.h
+++ b/include/UtilFoundation.h
@@ -68,7 +68,22 @@
 
 #include <memory>
 
-#include <half.h>
+// The version can reliably be found in this header file from OpenEXR,
+// for both 2.x and 3.x:
+#include <OpenEXR/OpenEXRConfig.h>
+#define COMBINED_OPENEXR_VERSION ((10000*OPENEXR_VERSION_MAJOR) + \
+                                  (100*OPENEXR_VERSION_MINOR) + \
+                                  OPENEXR_VERSION_PATCH)
+
+// There's just no easy way to have an `#include` that works in both
+// cases, so we use the version to switch which set of include files we
+// use.
+#if COMBINED_OPENEXR_VERSION >= 20599 /* 2.5.99: pre-3.0 */
+#   include <Imath/half.h>
+#else
+    // OpenEXR 2.x, use the old locations
+#   include <OpenEXR/half.h>
+#endif
 
 #include <iomanip>
 #include <iostream>
diff --git a/test/unit_tests/UnitTest.cpp b/test/unit_tests/UnitTest.cpp
index 42f8654..b6072c9 100644
--- a/test/unit_tests/UnitTest.cpp
+++ b/test/unit_tests/UnitTest.cpp
@@ -44,7 +44,22 @@
 #include <boost/thread/thread.hpp>
 #include <boost/thread/mutex.hpp>
 
-#include <OpenEXR/ImathFrustum.h>
+// The version can reliably be found in this header file from OpenEXR,
+// for both 2.x and 3.x:
+#include <OpenEXR/OpenEXRConfig.h>
+#define COMBINED_OPENEXR_VERSION ((10000*OPENEXR_VERSION_MAJOR) + \
+                                  (100*OPENEXR_VERSION_MINOR) + \
+                                  OPENEXR_VERSION_PATCH)
+
+// There's just no easy way to have an `#include` that works in both
+// cases, so we use the version to switch which set of include files we
+// use.
+#if COMBINED_OPENEXR_VERSION >= 20599 /* 2.5.99: pre-3.0 */
+#   include <Imath/ImathFrustum.h>
+#else
+    // OpenEXR 2.x, use the old locations
+#   include <OpenEXR/ImathFrustum.h>
+#endif
 
 #include "Field3D/DenseField.h"
 #include "Field3D/EmptyField.h"