Skip to content
Snippets Groups Projects
Unverified Commit 8a4bc98f authored by Guilherme Amadio's avatar Guilherme Amadio
Browse files

Update FindLZ4.cmake

parent b28c3828
No related branches found
No related tags found
No related merge requests found
# Find the LZ4 includes and library.
#.rst:
# FindLZ4
# -------
#
# This module defines
# LZ4_INCLUDE_DIR, where to locate LZ4 header files
# LZ4_LIBRARIES, the libraries to link against to use LZ4
# LZ4_FOUND. If false, you cannot build anything that requires LZ4.
# Find the LZ4 library header and define variables.
#
# Imported Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines :prop_tgt:`IMPORTED` target ``LZ4::LZ4``,
# if LZ4 has been found
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module defines the following variables:
#
# ::
#
# LZ4_FOUND - True if LZ4 is found.
# LZ4_INCLUDE_DIRS - Where to find lz4.h
#
# ::
#
# LZ4_VERSION - The version of LZ4 found (x.y.z)
# LZ4_VERSION_MAJOR - The major version of LZ4
# LZ4_VERSION_MINOR - The minor version of LZ4
# LZ4_VERSION_PATCH - The patch version of LZ4
find_path(LZ4_INCLUDE_DIR NAME lz4.h PATH_SUFFIXES include)
if(LZ4_CONFIG_EXECUTABLE)
set(LZ4_FIND_QUIETLY 1)
if(NOT LZ4_LIBRARY)
find_library(LZ4_LIBRARY NAMES lz4 PATH_SUFFIXES lib)
endif()
set(LZ4_FOUND 0)
find_path(LZ4_INCLUDE_DIR NAMES lz4.h PATHS
$ENV{LZ4_DIR}/include
/usr/include
/usr/local/include
/opt/lz4/include
DOC "Specify the directory containing lz4.h"
)
mark_as_advanced(LZ4_INCLUDE_DIR)
# Checking for xxhash library includes (part of https://github.com/lz4/lz4.git,
# but not provided in .deb and .rpm packages)
find_path(XXHASH_INCLUDE_DIR NAMES xxhash.h PATHS
/usr/include
/usr/local/include
/opt/xxhash/include
DOC "Specify the directory containing xxhash.h"
)
if(LZ4_INCLUDE_DIR AND EXISTS "${LZ4_INCLUDE_DIR}/lz4.h")
file(STRINGS "${LZ4_INCLUDE_DIR}/lz4.h" LZ4_H REGEX "^#define LZ4_VERSION_[A-Z]+[ ]+[0-9]+.*$")
string(REGEX REPLACE ".+LZ4_VERSION_MAJOR[ ]+([0-9]+).*$" "\\1" LZ4_VERSION_MAJOR "${LZ4_H}")
string(REGEX REPLACE ".+LZ4_VERSION_MINOR[ ]+([0-9]+).*$" "\\1" LZ4_VERSION_MINOR "${LZ4_H}")
string(REGEX REPLACE ".+LZ4_VERSION_RELEASE[ ]+([0-9]+).*$" "\\1" LZ4_VERSION_PATCH "${LZ4_H}")
set(LZ4_VERSION "${LZ4_VERSION_MAJOR}.${LZ4_VERSION_MINOR}.${LZ4_VERSION_PATCH}")
endif()
find_library(LZ4_LIBRARY NAMES lz4 PATHS
$ENV{LZ4_DIR}/lib
/usr/local/lz4/lib
/usr/local/lib
/usr/lib/lz4
/usr/local/lib/lz4
/usr/lz4/lib /usr/lib
/usr/lz4 /usr/local/lz4
/opt/lz4 /opt/lz4/lib
DOC "Specify the lz4 library here."
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LZ4
REQUIRED_VARS LZ4_LIBRARY LZ4_INCLUDE_DIR VERSION_VAR LZ4_VERSION)
# Checking for xxhash library, in case it was built separately from
# https://github.com/Cyan4973/xxHash.git
find_library(XXHASH_LIBRARY NAMES xxhash PATHS
/usr/local/lib
/usr/lib
DOC "Specify the xxhash library here."
)
if(LZ4_FOUND)
set(LZ4_INCLUDE_DIRS "${LZ4_INCLUDE_DIR}")
if(LZ4_INCLUDE_DIR AND LZ4_LIBRARY AND XXHASH_INCLUDE_DIR)
set(LZ4_FOUND 1)
if(NOT LZ4_FIND_QUIETLY)
message(STATUS "Found LZ4 includes at ${LZ4_INCLUDE_DIR}")
message(STATUS "Found LZ4 library at ${LZ4_LIBRARY}")
message(STATUS "Found xxhash include at ${XXHASH_INCLUDE_DIR}")
if(NOT LZ4_LIBRARIES)
set(LZ4_LIBRARIES ${LZ4_LIBRARY})
endif()
endif()
set(LZ4_LIBRARIES ${LZ4_LIBRARY})
if(XXHASH_LIBRARY)
list(APPEND LZ4_LIBRARIES ${XXHASH_LIBRARY})
endif()
if(NOT("${XXHASH_INCLUDE_DIR}" MATCHES ${LZ4_INCLUDE_DIR}))
list(APPEND LZ4_INCLUDE_DIR ${XXHASH_INCLUDE_DIR})
if(NOT TARGET LZ4::LZ4)
add_library(LZ4::LZ4 UNKNOWN IMPORTED)
set_target_properties(LZ4::LZ4 PROPERTIES
IMPORTED_LOCATION "${LZ4_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${LZ4_INCLUDE_DIRS}")
endif()
endif()
mark_as_advanced(LZ4_FOUND LZ4_LIBRARY LZ4_INCLUDE_DIR XXHASH_INCLUDE_DIR)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment