From 1269256e25700912bb0a450d2a41cc09d0cc9cff Mon Sep 17 00:00:00 2001 From: t-karatsu <49965247+t-karatsu@users.noreply.github.com> Date: Thu, 18 Jul 2019 07:37:18 +0900 Subject: libjpeg-turbo: set compiler flags with CMake args (#11938) Later versions of libjpeg-turbo build with CMake; to build with user-specified cflags, the user must supply these to CMake as -DCMAKE_C_FLAGS (Spack's typical approach of injecting these flags into the compiler wrapper invocation is insufficient in this case). Currently libjpeg-turbo cannot be implemented as a CMakePackage (and thereby take advantage of the flag_handler implementation it provides) because not all versions of libjpeg-turbo use CMake, so this adds a custom implementation of flag_handler and flags_to_build_system_args to libjpeg-turbo. --- .../repos/builtin/packages/libjpeg-turbo/package.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'var') diff --git a/var/spack/repos/builtin/packages/libjpeg-turbo/package.py b/var/spack/repos/builtin/packages/libjpeg-turbo/package.py index 3d80762e75..039b77052b 100644 --- a/var/spack/repos/builtin/packages/libjpeg-turbo/package.py +++ b/var/spack/repos/builtin/packages/libjpeg-turbo/package.py @@ -38,6 +38,22 @@ class LibjpegTurbo(Package): def libs(self): return find_libraries("libjpeg*", root=self.prefix, recursive=True) + def flag_handler(self, name, flags): + if self.spec.satisfies('@1.5.90:'): + return (None, None, flags) + else: + # compiler flags for earlier version are injected into the + # spack compiler wrapper + return (flags, None, None) + + def flags_to_build_system_args(self, flags): + # This only handles cflags, other flags are discarded + cmake_flag_args = [] + if 'cflags' in flags and flags['cflags']: + cmake_flag_args.append('-DCMAKE_C_FLAGS={0}'.format( + ' '.join(flags['cflags']))) + self.cmake_flag_args = cmake_flag_args + @when('@1.3.1:1.5.3') def install(self, spec, prefix): autoreconf('-ifv') @@ -48,6 +64,8 @@ class LibjpegTurbo(Package): @when('@1.5.90:') def install(self, spec, prefix): cmake_args = ['-GUnix Makefiles'] + if hasattr(self, 'cmake_flag_args'): + cmake_args.extend(self.cmake_flag_args) cmake_args.extend(std_cmake_args) with working_dir('spack-build', create=True): cmake('..', *cmake_args) -- cgit v1.2.3-70-g09d2