Skip to content

Commit

Permalink
lz4: switch to CMake build (spack#35101)
Browse files Browse the repository at this point in the history
Add support for building with CMake and make it the default build
system on all platforms. By doing this, lz4 can now be built on
Windows. The makefile-based build remains as an option.
  • Loading branch information
johnwparent authored Mar 20, 2023
1 parent b431c4d commit fa0749b
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions var/spack/repos/builtin/packages/lz4/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

import os
import sys

from spack.build_systems.cmake import CMakeBuilder
from spack.build_systems.makefile import MakefileBuilder
from spack.package import *


class Lz4(MakefilePackage):
class Lz4(CMakePackage, MakefilePackage):
"""LZ4 is lossless compression algorithm, providing compression speed
at 400 MB/s per core, scalable with multi-cores CPU. It also features
an extremely fast decoder, with speed in multiple GB/s per core,
Expand All @@ -28,6 +31,8 @@ class Lz4(MakefilePackage):

depends_on("valgrind", type="test")

build_system("cmake", "makefile", default="cmake")
parallel = False if sys.platform == "win32" else True
variant(
"libs",
default="shared,static",
Expand All @@ -44,6 +49,39 @@ def url_for_version(self, version):
else:
return "{0}/r{1}.tar.gz".format(url, version.joined)

def patch(self):
# Remove flags not recognized by the NVIDIA compiler
if self.spec.satisfies("%nvhpc@:20.11"):
filter_file("-fvisibility=hidden", "", "Makefile")
filter_file("-fvisibility=hidden", "", "lib/Makefile")
filter_file("-pedantic", "", "Makefile")

@run_after("install")
def darwin_fix(self):
if sys.platform == "darwin":
fix_darwin_install_name(self.prefix.lib)


class CMakeBuilder(CMakeBuilder):
@property
def root_cmakelists_dir(self):
return os.path.join(super().root_cmakelists_dir, "build", "cmake")

def cmake_args(self):
args = []
# # no pic on windows
if "platform=windows" in self.spec:
args.append(self.define("LZ4_POSITION_INDEPENDENT_LIB", False))
args.append(
self.define("BUILD_SHARED_LIBS", True if "libs=shared" in self.spec else False)
)
args.append(
self.define("BUILD_STATIC_LIBS", True if "libs=static" in self.spec else False)
)
return args


class MakefileBuilder(MakefileBuilder):
def build(self, spec, prefix):
par = True
if spec.compiler.name == "nvhpc":
Expand All @@ -63,15 +101,3 @@ def install(self, spec, prefix):
"BUILD_SHARED={0}".format("yes" if "libs=shared" in self.spec else "no"),
"BUILD_STATIC={0}".format("yes" if "libs=static" in self.spec else "no"),
)

def patch(self):
# Remove flags not recognized by the NVIDIA compiler
if self.spec.satisfies("%nvhpc@:20.11"):
filter_file("-fvisibility=hidden", "", "Makefile")
filter_file("-fvisibility=hidden", "", "lib/Makefile")
filter_file("-pedantic", "", "Makefile")

@run_after("install")
def darwin_fix(self):
if sys.platform == "darwin":
fix_darwin_install_name(self.prefix.lib)

0 comments on commit fa0749b

Please sign in to comment.