|
| 1 | +# Copyright 2017 Google Inc. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +# Description: |
| 16 | +# Bazel build file for the ILM OpenEXR libraries. |
| 17 | + |
| 18 | +package( |
| 19 | + default_visibility = ["//visibility:public"], |
| 20 | + features = [ |
| 21 | + "-layering_check", |
| 22 | + "-parse_headers", |
| 23 | + ], |
| 24 | +) |
| 25 | + |
| 26 | +licenses(["notice"]) # BSD |
| 27 | + |
| 28 | +exports_files(["LICENSE"]) |
| 29 | + |
| 30 | +config_setting( |
| 31 | + name = "linux_x86_64", |
| 32 | + values = {"cpu": "k8"}, |
| 33 | + visibility = ["//visibility:public"], |
| 34 | +) |
| 35 | + |
| 36 | +config_setting( |
| 37 | + name = "windows_x86_64", |
| 38 | + values = {"cpu": "x64_windows"}, |
| 39 | + visibility = ["//visibility:public"], |
| 40 | +) |
| 41 | + |
| 42 | +DEFINES = [ |
| 43 | + "DISABLE_GOOGLE_GLOBAL_USING_DECLARATIONS", |
| 44 | +] + select({ |
| 45 | + ":linux_x86_64": [ |
| 46 | + "OS_LINUX=OS_LINUX", |
| 47 | + "ARCH_K8", |
| 48 | + ], |
| 49 | + ":windows_x86_64": [ |
| 50 | + "NOGDI", # Don't pollute with GDI macros in windows.h. |
| 51 | + "NOMINMAX", # Don't define min/max macros in windows.h. |
| 52 | + "OS_WINDOWS=OS_WINDOWS", |
| 53 | + "PRAGMA_SUPPORTED", |
| 54 | + "WIN32", |
| 55 | + "WINVER=0x0600", |
| 56 | + "_CRT_SECURE_NO_DEPRECATE", |
| 57 | + "_WIN32", |
| 58 | + "_WIN32_WINNT=0x0600", |
| 59 | + "_WINDOWS", |
| 60 | + |
| 61 | + # Defaults for other headers (along with OS_WINDOWS). |
| 62 | + "COMPILER_MSVC", |
| 63 | + |
| 64 | + # Use math constants (M_PI, etc.) from the math library |
| 65 | + "_USE_MATH_DEFINES", |
| 66 | + |
| 67 | + # Allows 'Foo&&' (e.g., move constructors). |
| 68 | + "COMPILER_HAS_RVALUEREF", |
| 69 | + |
| 70 | + # Doublespeak for "don't bloat namespace with incompatible winsock |
| 71 | + # versions that I didn't include". |
| 72 | + # http://msdn.microsoft.com/en-us/library/windows/desktop/ms737629.aspx |
| 73 | + "WIN32_LEAN_AND_MEAN=1", |
| 74 | + |
| 75 | + "PLATFORM_WINDOWS", |
| 76 | + ], |
| 77 | +}) |
| 78 | + |
| 79 | +# Options for everything below |
| 80 | +all_options = [ |
| 81 | + "-D_THREAD_SAFE", |
| 82 | +] + select({ |
| 83 | + ":windows_x86_64": ["/EHsc"], |
| 84 | + ":linux_x86_64": [ |
| 85 | + "-fexceptions", |
| 86 | + "-fno-common", |
| 87 | + "-Wno-unused-variable", |
| 88 | + "-Wno-unused-result", |
| 89 | + "-Wno-string-conversion", |
| 90 | + "-Wno-switch", |
| 91 | + "-Wno-tautological-compare", |
| 92 | + "-Wno-deprecated-register", |
| 93 | + # IlmImf/ImfHuf.cpp:111 wants to put a 21520 byte object on the stack. |
| 94 | + "$(STACK_FRAME_UNLIMITED)", |
| 95 | + ], |
| 96 | +}) |
| 97 | + |
| 98 | +# Generates the config headers. Note we don't use the autoconf, but the |
| 99 | +# libraries still require a header. |
| 100 | +genrule( |
| 101 | + name = "configure_ilmbase", |
| 102 | + outs = ["IlmBase/config/IlmBaseConfig.h"], |
| 103 | + cmd = "touch $@", |
| 104 | +) |
| 105 | + |
| 106 | +# Wraps the config header auto generation, then injects the desired defines and |
| 107 | +# include folder configuration. |
| 108 | +cc_library( |
| 109 | + name = "ilmbase_config", |
| 110 | + hdrs = [":configure_ilmbase"], |
| 111 | + defines = DEFINES, |
| 112 | + includes = ["IlmBase/config/"], |
| 113 | +) |
| 114 | + |
| 115 | +################################################################################ |
| 116 | +# Build the half library and its support components |
| 117 | +# ILM's libhalf is considered the reference implementation. |
| 118 | +half_path = "IlmBase/Half/" |
| 119 | + |
| 120 | +cc_binary( |
| 121 | + name = "toFloat", |
| 122 | + srcs = [half_path + "toFloat.cpp"], |
| 123 | + copts = all_options, |
| 124 | + defines = DEFINES, |
| 125 | +) |
| 126 | + |
| 127 | +cc_binary( |
| 128 | + name = "eLut", |
| 129 | + srcs = [half_path + "eLut.cpp"], |
| 130 | + copts = all_options, |
| 131 | + defines = DEFINES, |
| 132 | +) |
| 133 | + |
| 134 | +genrule( |
| 135 | + name = "toFloatAutoGen", |
| 136 | + outs = [half_path + "toFloat.h"], |
| 137 | + # Runs the tool from its built location, and captures to the single output |
| 138 | + # of this rule. |
| 139 | + cmd = "$(location :toFloat) > $@", |
| 140 | + tools = [":toFloat"], |
| 141 | +) |
| 142 | + |
| 143 | +genrule( |
| 144 | + name = "eLutAutoGen", |
| 145 | + outs = [half_path + "eLut.h"], |
| 146 | + # Runs the tool from its built location, and captures to the single output |
| 147 | + # of this rule. |
| 148 | + cmd = "$(location :eLut) > $@", |
| 149 | + tools = [":eLut"], |
| 150 | +) |
| 151 | + |
| 152 | +cc_library( |
| 153 | + name = "half", |
| 154 | + srcs = glob([half_path + "half.cpp"]), |
| 155 | + copts = all_options, |
| 156 | + defines = DEFINES, |
| 157 | + includes = [half_path], |
| 158 | + textual_hdrs = glob([ |
| 159 | + half_path + "half.h", |
| 160 | + half_path + "halfExport.h", |
| 161 | + half_path + "halfFunction.h", |
| 162 | + half_path + "halfLimits.h", |
| 163 | + ]) + [ |
| 164 | + ":toFloatAutoGen", |
| 165 | + ":eLutAutoGen", |
| 166 | + ], |
| 167 | + deps = [":ilmbase_config"], |
| 168 | +) |
| 169 | + |
| 170 | +################################################################################ |
| 171 | +# Build the Iex library |
| 172 | +iex_path = "IlmBase/Iex/" |
| 173 | + |
| 174 | +cc_library( |
| 175 | + name = "iex", |
| 176 | + srcs = glob([iex_path + "*.cpp"]), |
| 177 | + hdrs = glob([iex_path + "*.h"]), |
| 178 | + copts = all_options, |
| 179 | + defines = DEFINES, |
| 180 | + includes = [iex_path], |
| 181 | + deps = [":ilmbase_config"], |
| 182 | +) |
| 183 | + |
| 184 | +################################################################################ |
| 185 | +# Build the IexMath library |
| 186 | +iex_math_path = "IlmBase/IexMath/" |
| 187 | + |
| 188 | +cc_library( |
| 189 | + name = "iex_math", |
| 190 | + srcs = glob([iex_math_path + "*.cpp"]), |
| 191 | + hdrs = glob([iex_math_path + "*.h"]), |
| 192 | + copts = all_options, |
| 193 | + includes = [iex_math_path], |
| 194 | + deps = [ |
| 195 | + ":half", |
| 196 | + ":iex", |
| 197 | + ], |
| 198 | +) |
| 199 | + |
| 200 | +################################################################################ |
| 201 | +# Build the IlmThread library and its tests components |
| 202 | +ilm_thread_path = "IlmBase/IlmThread/" |
| 203 | + |
| 204 | +ilm_thread_win_srcs_pattern = ilm_thread_path + "*Win32.cpp" |
| 205 | + |
| 206 | +ilm_thread_win_hdrs_pattern = ilm_thread_path + "*Win32.h" |
| 207 | + |
| 208 | +cc_library( |
| 209 | + name = "ilm_thread", |
| 210 | + srcs = glob( |
| 211 | + [ilm_thread_path + "*.cpp"], |
| 212 | + exclude = [ilm_thread_win_srcs_pattern], |
| 213 | + ) + select({ |
| 214 | + ":windows_x86_64": glob([ilm_thread_win_srcs_pattern]), |
| 215 | + ":linux_x86_64": [], |
| 216 | + }), |
| 217 | + hdrs = glob( |
| 218 | + [ilm_thread_path + "*.h"], |
| 219 | + exclude = [ilm_thread_win_hdrs_pattern], |
| 220 | + ) + select({ |
| 221 | + ":windows_x86_64": glob([ilm_thread_win_hdrs_pattern]), |
| 222 | + ":linux_x86_64": [], |
| 223 | + }), |
| 224 | + copts = all_options, |
| 225 | + defines = DEFINES, |
| 226 | + includes = [ |
| 227 | + ilm_thread_path, |
| 228 | + ], |
| 229 | + deps = [ |
| 230 | + ":iex", |
| 231 | + ":ilmbase_config", |
| 232 | + ], |
| 233 | +) |
| 234 | + |
| 235 | +################################################################################ |
| 236 | +# Build the Imath library |
| 237 | +imath_path = "IlmBase/Imath/" |
| 238 | + |
| 239 | +cc_library( |
| 240 | + name = "imath", |
| 241 | + srcs = glob([imath_path + "*.cpp"]), |
| 242 | + hdrs = glob([imath_path + "*.h"]), |
| 243 | + copts = all_options, |
| 244 | + defines = DEFINES, |
| 245 | + includes = [ |
| 246 | + imath_path, |
| 247 | + ], |
| 248 | + deps = [ |
| 249 | + ":half", |
| 250 | + ":iex", |
| 251 | + ":iex_math", |
| 252 | + ":ilmbase_config", |
| 253 | + ], |
| 254 | +) |
| 255 | + |
| 256 | +################################################################################ |
| 257 | +# Build the IlmImf library |
| 258 | +ilm_imf_path = "OpenEXR/IlmImf/" |
| 259 | + |
| 260 | +ilm_imf_util_path = "OpenEXR/IlmImfUtil/" |
| 261 | + |
| 262 | +# Generates the config headers. Note we don't use the autoconf, but the |
| 263 | +# libraries still require a header. |
| 264 | +genrule( |
| 265 | + name = "configure_openexr", |
| 266 | + outs = ["OpenEXR/config/OpenEXRConfig.h"], |
| 267 | + cmd = "touch $@", |
| 268 | +) |
| 269 | + |
| 270 | +# Wraps the config auto generation with the include folder configuration. |
| 271 | +cc_library( |
| 272 | + name = "openexr_config", |
| 273 | + hdrs = [":configure_openexr"], |
| 274 | + defines = DEFINES, |
| 275 | + includes = ["OpenEXR/config/"], |
| 276 | +) |
| 277 | + |
| 278 | +cc_binary( |
| 279 | + name = "dwaLookups", |
| 280 | + srcs = [ |
| 281 | + ilm_imf_path + "dwaLookups.cpp", |
| 282 | + ] + |
| 283 | + # Note we include various headers via glob since we don't have cc_library |
| 284 | + # targets for some of the sub-libraries of OpenEXR. |
| 285 | + glob([ |
| 286 | + ilm_imf_util_path + "**/*.h", |
| 287 | + ilm_imf_path + "*.h", |
| 288 | + ]), |
| 289 | + copts = all_options, |
| 290 | + defines = DEFINES, |
| 291 | + includes = [ |
| 292 | + imath_path, |
| 293 | + iex_math_path, |
| 294 | + ilm_imf_path, |
| 295 | + ilm_imf_util_path, |
| 296 | + ], |
| 297 | + deps = [ |
| 298 | + ":half", |
| 299 | + ":iex", |
| 300 | + ":ilm_thread", |
| 301 | + ":imath", |
| 302 | + ":openexr_config", |
| 303 | + ], |
| 304 | +) |
| 305 | + |
| 306 | +cc_binary( |
| 307 | + name = "b44ExpLogTable", |
| 308 | + srcs = [ |
| 309 | + ilm_imf_path + "b44ExpLogTable.cpp", |
| 310 | + ] + glob(["**/*.h"]), |
| 311 | + copts = all_options, |
| 312 | + defines = DEFINES, |
| 313 | + includes = [ |
| 314 | + half_path, |
| 315 | + imath_path, |
| 316 | + iex_math_path, |
| 317 | + iex_path, |
| 318 | + ilm_imf_path, |
| 319 | + ilm_imf_util_path, |
| 320 | + ilm_thread_path, |
| 321 | + ], |
| 322 | + deps = [ |
| 323 | + ":half", |
| 324 | + ":iex", |
| 325 | + ":ilm_thread", |
| 326 | + ":openexr_config", |
| 327 | + ], |
| 328 | +) |
| 329 | + |
| 330 | +genrule( |
| 331 | + name = "dwaLookupsAutoGen", |
| 332 | + outs = [ilm_imf_path + "dwaLookups.h"], |
| 333 | + # Runs the tool from its built location, and captures to the single output |
| 334 | + # of this rule. |
| 335 | + cmd = "$(location :dwaLookups) > $@", |
| 336 | + tools = [":dwaLookups"], |
| 337 | +) |
| 338 | + |
| 339 | +genrule( |
| 340 | + name = "b44ExpLogTableAutoGen", |
| 341 | + outs = [ilm_imf_path + "b44ExpLogTable.h"], |
| 342 | + # Runs the tool from its built location, and captures to the single output |
| 343 | + # of this rule. |
| 344 | + cmd = "$(location :b44ExpLogTable) > $@", |
| 345 | + tools = [":b44ExpLogTable"], |
| 346 | +) |
| 347 | + |
| 348 | +cc_library( |
| 349 | + name = "ilm_imf", |
| 350 | + srcs = glob([ilm_imf_path + "Imf*.cpp"]) + [ |
| 351 | + ":dwaLookupsAutoGen", |
| 352 | + ":b44ExpLogTableAutoGen", |
| 353 | + ], |
| 354 | + hdrs = glob([ilm_imf_path + "Imf*.h"]), |
| 355 | + copts = all_options, |
| 356 | + defines = DEFINES, |
| 357 | + includes = [ilm_imf_path], |
| 358 | + deps = [ |
| 359 | + ":half", |
| 360 | + ":iex", |
| 361 | + ":iex_math", |
| 362 | + ":ilm_thread", |
| 363 | + ":imath", |
| 364 | + ":openexr_config", |
| 365 | + "@zlib//:zlib" |
| 366 | + ], |
| 367 | +) |
0 commit comments