forked from OpenMW/openmw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindLZ4.cmake
132 lines (94 loc) · 4.2 KB
/
FindLZ4.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindLZ4
-------
Find the LZ4 include directory and library.
Use this module by invoking find_package with the form::
.. code-block:: cmake
find_package(LZ4
[version] # Minimum version e.g. 1.8.0
[REQUIRED] # Fail with error if LZ4 is not found
)
Imported targets
^^^^^^^^^^^^^^^^
This module defines the following :prop_tgt:`IMPORTED` targets:
.. variable:: LZ4::LZ4
Imported target for using the LZ4 library, if found.
Result variables
^^^^^^^^^^^^^^^^
.. variable:: LZ4_FOUND
Set to true if LZ4 library found, otherwise false or undefined.
.. variable:: LZ4_INCLUDE_DIRS
Paths to include directories listed in one variable for use by LZ4 client.
.. variable:: LZ4_LIBRARIES
Paths to libraries to linked against to use LZ4.
.. variable:: LZ4_VERSION
The version string of LZ4 found.
Cache variables
^^^^^^^^^^^^^^^
For users who wish to edit and control the module behavior, this module
reads hints about search locations from the following variables::
.. variable:: LZ4_INCLUDE_DIR
Path to LZ4 include directory with ``lz4.h`` header.
.. variable:: LZ4_LIBRARY
Path to LZ4 library to be linked.
NOTE: The variables above should not usually be used in CMakeLists.txt files!
#]=======================================================================]
### Find library ##############################################################
if(NOT LZ4_LIBRARY)
find_library(LZ4_LIBRARY_RELEASE NAMES lz4)
find_library(LZ4_LIBRARY_DEBUG NAMES lz4d)
include(SelectLibraryConfigurations)
select_library_configurations(LZ4)
else()
file(TO_CMAKE_PATH "${LZ4_LIBRARY}" LZ4_LIBRARY)
endif()
### Find include directory ####################################################
find_path(LZ4_INCLUDE_DIR NAMES lz4.h)
if(LZ4_INCLUDE_DIR AND EXISTS "${LZ4_INCLUDE_DIR}/lz4.h")
file(STRINGS "${LZ4_INCLUDE_DIR}/lz4.h" _lz4_h_contents
REGEX "#define LZ4_VERSION_[A-Z]+[ ]+[0-9]+")
string(REGEX REPLACE "#define LZ4_VERSION_MAJOR[ ]+([0-9]+).+" "\\1"
LZ4_VERSION_MAJOR "${_lz4_h_contents}")
string(REGEX REPLACE ".+#define LZ4_VERSION_MINOR[ ]+([0-9]+).+" "\\1"
LZ4_VERSION_MINOR "${_lz4_h_contents}")
string(REGEX REPLACE ".+#define LZ4_VERSION_RELEASE[ ]+([0-9]+).*" "\\1"
LZ4_VERSION_RELEASE "${_lz4_h_contents}")
set(LZ4_VERSION "${LZ4_VERSION_MAJOR}.${LZ4_VERSION_MINOR}.${LZ4_VERSION_RELEASE}")
unset(_lz4_h_contents)
endif()
### Set result variables ######################################################
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LZ4 DEFAULT_MSG
LZ4_LIBRARY LZ4_INCLUDE_DIR LZ4_VERSION)
set(LZ4_INCLUDE_DIR ${LZ4_INCLUDE_DIR} CACHE PATH "LZ4 include dir hint")
set(LZ4_LIBRARY ${LZ4_LIBRARY} CACHE FILEPATH "LZ4 library path hint")
mark_as_advanced(LZ4_INCLUDE_DIR LZ4_LIBRARY)
set(LZ4_LIBRARIES ${LZ4_LIBRARY})
set(LZ4_INCLUDE_DIRS ${LZ4_INCLUDE_DIR})
### Import targets ############################################################
if(LZ4_FOUND)
if(NOT TARGET LZ4::LZ4)
add_library(LZ4::LZ4 UNKNOWN IMPORTED)
set_target_properties(LZ4::LZ4 PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
INTERFACE_INCLUDE_DIRECTORIES "${LZ4_INCLUDE_DIR}")
if(LZ4_LIBRARY_RELEASE)
set_property(TARGET LZ4::LZ4 APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(LZ4::LZ4 PROPERTIES
IMPORTED_LOCATION_RELEASE "${LZ4_LIBRARY_RELEASE}")
endif()
if(LZ4_LIBRARY_DEBUG)
set_property(TARGET LZ4::LZ4 APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(LZ4::LZ4 PROPERTIES
IMPORTED_LOCATION_DEBUG "${LZ4_LIBRARY_DEBUG}")
endif()
if(NOT LZ4_LIBRARY_RELEASE AND NOT LZ4_LIBRARY_DEBUG)
set_property(TARGET LZ4::LZ4 APPEND PROPERTY
IMPORTED_LOCATION "${LZ4_LIBRARY}")
endif()
endif()
endif()