libjpeg-turbo: follow the parent build's toolchain when cross-compiling
libjpeg-turbo is brought in with ExternalProject_Add rather than FetchContent, because upstream does not support inclusion via add_subdirectory. An ExternalProject is a separate cmake invocation that inherits nothing from its parent, and the CMAKE_CACHE_ARGS here named only the feature options, so it always configured for the build host. That is invisible in a native build and fatal in a cross build: the library compiles for x86_64 inside an aarch64 build and the mistake only surfaces at the final link of whatever consumes it, as an architecture mismatch on libjpeg.a rather than anything pointing at this file. rugnux reaches it through JFJochWriter -> JFJochPreview, so it is on the path of every build, not just the viewer's. Forward the toolchain file and the compiler. CMAKE_TOOLCHAIN_FILE is empty in a native build and cmake ignores it there, so nothing changes off the cross path. libjpeg-turbo selects its own SIMD from the target architecture, so this also gets the NEON kernels for free on aarch64 and stops nasm from being consulted at all; a cross-compiled libjpeg.a comes out ELF aarch64 with 14 NEON objects. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SQjneRUssfhi1k9rq8Ts3h
This commit is contained in:
+11
-1
@@ -34,7 +34,17 @@ ExternalProject_Add(libjpeg-turbo-project
|
||||
-DREQUIRE_SIMD:BOOL=OFF
|
||||
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
|
||||
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
|
||||
-DCMAKE_INSTALL_LIBDIR:PATH=<INSTALL_DIR>/lib)
|
||||
-DCMAKE_INSTALL_LIBDIR:PATH=<INSTALL_DIR>/lib
|
||||
# An ExternalProject is a separate cmake invocation and inherits nothing, so without these
|
||||
# it configures for the BUILD host: a cross build would link an x86_64 libjpeg.a into an
|
||||
# aarch64 binary and only fail at the final link. Forward the toolchain file (empty when not
|
||||
# cross-compiling, which cmake ignores) and the compilers, so it follows the parent build.
|
||||
# libjpeg-turbo picks its own SIMD from the target arch, so NEON comes for free on aarch64
|
||||
# and nasm is simply not consulted there.
|
||||
-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${CMAKE_TOOLCHAIN_FILE}
|
||||
-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
|
||||
-DCMAKE_SYSTEM_NAME:STRING=${CMAKE_SYSTEM_NAME}
|
||||
-DCMAKE_SYSTEM_PROCESSOR:STRING=${CMAKE_SYSTEM_PROCESSOR})
|
||||
|
||||
# Create the include dir up front so setting INTERFACE_INCLUDE_DIRECTORIES below does not fail.
|
||||
FILE(MAKE_DIRECTORY ${LIBJPEG_TURBO_INCLUDE_DIRS})
|
||||
|
||||
Reference in New Issue
Block a user