1
2# Copyright (C) 2011-2019 Daniel Scharrer
3#
4# This software is provided 'as-is', without any express or implied
5# warranty.  In no event will the author(s) be held liable for any damages
6# arising from the use of this software.
7#
8# Permission is granted to anyone to use this software for any purpose,
9# including commercial applications, and to alter it and redistribute it
10# freely, subject to the following restrictions:
11#
12# 1. The origin of this software must not be misrepresented; you must not
13#    claim that you wrote the original software. If you use this software
14#    in a product, an acknowledgment in the product documentation would be
15#    appreciated but is not required.
16# 2. Altered source versions must be plainly marked as such, and must not be
17#    misrepresented as being the original software.
18# 3. This notice may not be removed or altered from any source distribution.
19
20# Try to find the LZMA library and include path for lzma.h from xz-utils.
21# Once done this will define
22#
23# LZMA_FOUND
24# LZMA_INCLUDE_DIR   Where to find lzma.h
25# LZMA_LIBRARIES     The liblzma library
26# LZMA_DEFINITIONS   Definitions to use when compiling code that uses liblzma
27#
28# Typical usage could be something like:
29#   find_package(LZMA REQUIRED)
30#   include_directories(SYSTEM ${LZMA_INCLUDE_DIR})
31#   add_definitions(${LZMA_DEFINITIONS})
32#   ...
33#   target_link_libraries(myexe ${LZMA_LIBRARIES})
34#
35# The following additional options can be defined before the find_package() call:
36# LZMA_USE_STATIC_LIBS  Statically link against liblzma (default: OFF)
37
38if(UNIX)
39	find_package(PkgConfig QUIET)
40	pkg_check_modules(_PC_LZMA liblzma)
41endif()
42
43include(UseStaticLibs)
44
45foreach(static IN ITEMS 1 0)
46
47	if(static)
48		use_static_libs(LZMA _PC_LZMA)
49	endif()
50
51	find_path(LZMA_INCLUDE_DIR lzma.h
52		HINTS
53			${_PC_LZMA_INCLUDE_DIRS}
54		DOC "The directory where lzma.h resides"
55	)
56	mark_as_advanced(LZMA_INCLUDE_DIR)
57
58	# Prefer libraries in the same prefix as the include files
59	string(REGEX REPLACE "(.*)/include/?" "\\1" LZMA_BASE_DIR ${LZMA_INCLUDE_DIR})
60
61	find_library(LZMA_LIBRARY lzma liblzma
62		HINTS
63			${_PC_LZMA_LIBRARY_DIRS}
64			"${LZMA_BASE_DIR}/lib"
65		DOC "The LZMA library"
66	)
67	mark_as_advanced(LZMA_LIBRARY)
68
69	if(static)
70		use_static_libs_restore()
71	endif()
72
73	if(LZMA_LIBRARY OR STRICT_USE)
74		break()
75	endif()
76
77endforeach()
78
79set(LZMA_DEFINITIONS)
80if(WIN32 AND LZMA_USE_STATIC_LIBS)
81	set(LZMA_DEFINITIONS -DLZMA_API_STATIC)
82endif()
83
84# handle the QUIETLY and REQUIRED arguments and set LZMA_FOUND to TRUE if
85# all listed variables are TRUE
86include(FindPackageHandleStandardArgs)
87find_package_handle_standard_args(LZMA DEFAULT_MSG LZMA_LIBRARY LZMA_INCLUDE_DIR)
88
89if(LZMA_FOUND)
90	set(LZMA_LIBRARIES ${LZMA_LIBRARY})
91endif(LZMA_FOUND)
92