Skip to content

Commit adca0ce

Browse files
authored
Prefer to build against libjpeg-turbo and document this. (#8775)
1 parent 7ac0f7e commit adca0ce

File tree

4 files changed

+33
-35
lines changed

4 files changed

+33
-35
lines changed

CMakePresets.json

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@
157157
"rhs": "Darwin"
158158
},
159159
"cacheVariables": {
160-
"Halide_LLVM_ROOT": "/opt/homebrew/opt/llvm",
161-
"CMAKE_PREFIX_PATH": "/opt/homebrew;/opt/homebrew/opt/jpeg"
160+
"Halide_LLVM_ROOT": "/opt/homebrew/opt/llvm"
162161
}
163162
},
164163
{
@@ -168,10 +167,7 @@
168167
"vcpkg"
169168
],
170169
"displayName": "macOS (vcpkg)",
171-
"description": "macOS build with vcpkg dependencies",
172-
"cacheVariables": {
173-
"CMAKE_PREFIX_PATH": ""
174-
}
170+
"description": "macOS build with vcpkg dependencies"
175171
},
176172
{
177173
"name": "macOS-vcpkg-full",
@@ -180,10 +176,7 @@
180176
"vcpkg-full"
181177
],
182178
"displayName": "macOS (vcpkg-full)",
183-
"description": "macOS build with vcpkg-full dependencies",
184-
"cacheVariables": {
185-
"CMAKE_PREFIX_PATH": ""
186-
}
179+
"description": "macOS build with vcpkg-full dependencies"
187180
},
188181
{
189182
"name": "package",

Makefile

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -371,23 +371,36 @@ TEST_CXX_FLAGS += -DTEST_CUDA
371371
TEST_CXX_FLAGS += -I/usr/local/cuda/include
372372
endif
373373

374+
ifeq (,$(shell pkg-config --exists libpng && echo yes))
375+
ifeq ($(UNAME), Darwin)
376+
$(error libpng not found. Please install with: brew install libpng)
377+
else
378+
$(error libpng not found. Please install with: sudo apt install libpng-dev)
379+
endif
380+
endif
381+
382+
ifeq (,$(shell pkg-config --exists libjpeg && echo yes))
383+
ifeq ($(UNAME), Darwin)
384+
# Thanks to a schism between libjpeg and libjpeg-turbo, Homebrew
385+
# and many other distributions (Ubuntu, Debian, Fedora, Firefox,
386+
# Chrome, etc.) refuse to use the IJG's libjpeg. Instead, the
387+
# open-source world appears to have adopted libjpeg-turbo.
388+
# Users can override the search by setting PKG_CONFIG_PATH.
389+
# See: https://libjpeg-turbo.org/About/Jpeg-9
390+
$(error libjpeg not found. Please install with: brew install jpeg-turbo)
391+
else
392+
$(error libjpeg not found. Please install with: sudo apt install libjpeg-turbo8-dev)
393+
endif
394+
endif
395+
374396
# Find libjpeg and libpng. The code to set IMAGE_IO_LIBS is duplicated
375397
# in apps/support/Makefile.inc and any changes here should be repeated
376398
# there.
377399

378-
ifneq (,$(shell command -v brew))
379-
# Get png and jpeg paths from brew
380-
LIBPNG_LIBS_DEFAULT = -L $(shell brew --prefix libpng)/lib -lpng
381-
LIBPNG_CXX_FLAGS ?= -I $(shell brew --prefix libpng)/include
382-
LIBJPEG_LIBS ?= -L $(shell brew --prefix libjpeg)/lib -ljpeg
383-
LIBJPEG_CXX_FLAGS ?= -I $(shell brew --prefix libjpeg)/include
384-
else
385-
# Get png and jpeg paths from pkg-config
386400
LIBPNG_LIBS_DEFAULT = $(shell pkg-config libpng --libs)
387401
LIBPNG_CXX_FLAGS ?= $(shell pkg-config libpng --cflags)
388402
LIBJPEG_LIBS ?= $(shell pkg-config libjpeg --libs)
389403
LIBJPEG_CXX_FLAGS ?= $(shell pkg-config libjpeg --cflags)
390-
endif
391404

392405
# Workaround for libpng-config pointing to 64-bit versions on linux even when we're building for 32-bit
393406
ifneq (,$(findstring -m32,$(CXX)))

apps/support/Makefile.inc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,19 +192,10 @@ endif
192192
# Find libjpeg and libpng. The code to set IMAGE_IO_LIBS is duplicated
193193
# in the root Makefile and any changes here should be repeated there.
194194

195-
ifneq (,$(shell command -v brew))
196-
# Get png and jpeg paths from brew
197-
LIBPNG_LIBS_DEFAULT = -L $(shell brew --prefix libpng)/lib -lpng
198-
LIBPNG_CXX_FLAGS ?= -I $(shell brew --prefix libpng)/include
199-
LIBJPEG_LIBS ?= -L $(shell brew --prefix libjpeg)/lib -ljpeg
200-
LIBJPEG_CXX_FLAGS ?= -I $(shell brew --prefix libjpeg)/include
201-
else
202-
# Get png and jpeg paths from pkg-config
203195
LIBPNG_LIBS_DEFAULT = $(shell pkg-config libpng --libs)
204196
LIBPNG_CXX_FLAGS ?= $(shell pkg-config libpng --cflags)
205197
LIBJPEG_LIBS ?= $(shell pkg-config libjpeg --libs)
206198
LIBJPEG_CXX_FLAGS ?= $(shell pkg-config libjpeg --cflags)
207-
endif
208199

209200
# Workaround for libpng-config pointing to 64-bit versions on linux even when we're building for 32-bit
210201
ifneq (,$(findstring -m32,$(CXX)))
@@ -264,4 +255,3 @@ $(BIN)/%.run: $(BIN)/%.rungen
264255
.PHONY: %.benchmark
265256
%.benchmark: $(BIN)/$(HL_TARGET)/%.rungen
266257
@$^ --benchmarks=all --estimate_all --parsable_output
267-

doc/BuildingHalideWithCMake.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,18 @@ from the root of the repository.
244244
On macOS, it is possible to install all dependencies via [Homebrew][homebrew]:
245245

246246
```shell
247-
$ brew install llvm flatbuffers wabt python pybind11 doxygen eigen libpng libjpeg openblas
247+
$ brew install llvm flatbuffers wabt python pybind11 doxygen eigen libpng libjpeg-turbo openblas
248248
```
249249

250250
The `llvm` package includes `clang`, `clang-format`, and `lld`, too. To ensure
251-
CMake can find the keg-only dependencies, set the following:
251+
CMake can find LLVM, set the following cache variable:
252252

253253
```shell
254-
$ export CMAKE_PREFIX_PATH="/opt/homebrew:/opt/homebrew/opt/llvm:/opt/homebrew/opt/jpeg"
254+
$ cmake ... -DHalide_ROOT=/opt/homebrew/opt/llvm
255255
```
256256

257+
Or use the `macOS` CMake preset, which does this for you.
258+
257259
### Ubuntu / Debian
258260

259261
On Ubuntu you should install the following packages (this includes the Python
@@ -520,7 +522,7 @@ Python and C++ `find_package` workflows.
520522
Because Python's build infrastructure creates temporary CMake build directories,
521523
simply setting `CMAKE_CXX_COMPILER_LAUNCHER` to `ccache` is insufficient to
522524
produce a well-cached build. The following settings should serve as a starting
523-
point to configure your environment (assuming `$PWD` is the repository root)
525+
point to configure your environment (assuming `$PWD` is the repository root)
524526
for using `ccache` with `pip install .`.
525527

526528
```shell
@@ -545,7 +547,7 @@ export TMPDIR=$PWD/build/tmp
545547
export UV_NO_BUILD_ISOLATION=1
546548
```
547549

548-
See the CCache documentation on [compiling in different directories] and on
550+
See the CCache documentation on [compiling in different directories] and on
549551
using [precompiled headers] for more information about these settings. To check
550552
that ccache is working, run,
551553

@@ -578,7 +580,7 @@ Local storage:
578580
Misses: 0 / 1079 ( 0.00%)
579581
```
580582

581-
On this test system (an M3 MacBook Pro), the build is three times faster,
583+
On this test system (an M3 MacBook Pro), the build is three times faster,
582584
with a 100% cache hit rate!
583585

584586
[ATLAS]: http://math-atlas.sourceforge.net/

0 commit comments

Comments
 (0)