@@ -15,26 +15,34 @@ This module provides the following imported targets:
1515
1616## Result variables
1717
18+ This module defines the following variables:
19+
1820* `ACL_FOUND` - Boolean indicating whether (the requested version of) package
1921 was found.
2022* `ACL_VERSION` - The version of package found.
2123
2224## Cache variables
2325
24- * `ACL_IS_BUILT_IN` - Whether ACL is a part of the C library (BSD-based
25- systems).
26+ The following cache variables may also be set:
27+
28+ * `ACL_IS_BUILT_IN` - Whether ACL is a part of the C library (for example, on
29+ BSD-based systems).
2630* `ACL_INCLUDE_DIR` - Directory containing package library headers.
2731* `ACL_LIBRARY` - The path to the package library.
2832
2933## Hints
3034
31- * Set `ACL_USE_USER_GROUP` to `TRUE` before calling `find_package(ACL)` to also
32- check if the ACL library supports `ACL_USER` and `ACL_GROUP`. For example,
33- macOS doesn't have support for user/group.
35+ This module accepts the following variables before calling `find_package(ACL)`:
36+
37+ * `ACL_USE_USER_GROUP` - When set to boolean true a check is performed whether
38+ the ACL library supports `ACL_USER` and `ACL_GROUP`. For example, macOS
39+ doesn't have support for user/group.
3440
3541## Examples
3642
37- Basic usage:
43+ ### Example: Basic usage
44+
45+ Finding ACL library and linking its imported target to the project target:
3846
3947```cmake
4048# CMakeLists.txt
@@ -63,15 +71,17 @@ set_package_properties(
6371function (_acl_check result)
6472 cmake_push_check_state(RESET)
6573 set (CMAKE_REQUIRED_QUIET TRUE )
74+
6675 if (ACL_INCLUDE_DIR)
6776 set (CMAKE_REQUIRED_INCLUDES ${ACL_INCLUDE_DIR} )
6877 endif ()
78+
6979 if (ACL_LIBRARY)
7080 set (CMAKE_REQUIRED_LIBRARIES ${ACL_LIBRARY} )
7181 endif ()
7282
7383 if (NOT ACL_USE_USER_GROUP)
74- check_symbol_exists(acl_free sys/acl.h _acl_successful )
84+ check_symbol_exists(acl_free sys/acl.h ${result} )
7585 else ()
7686 check_source_compiles(C [[
7787 #include <sys/acl.h>
@@ -88,71 +98,73 @@ function(_acl_check result)
8898 acl_free(acl);
8999 return 0;
90100 }
91- ]] _acl_successful )
101+ ]] ${result} )
92102 endif ()
93103 cmake_pop_check_state()
94-
95- if (_acl_successful)
96- set (${result} TRUE PARENT_SCOPE)
97- else ()
98- set (${result} FALSE PARENT_SCOPE)
99- endif ()
100-
101- unset (_acl_successful CACHE )
102104endfunction ()
103105
104106################################################################################
105- # Disable built-in ACL when overriding search paths in FindACL .
107+ # Find package .
106108################################################################################
107- if (CMAKE_PREFIX_PATH OR ACL_ROOT)
109+
110+ # Disable searching for built-in ACL when overriding search paths.
111+ if (
112+ NOT DEFINED ACL_IS_BUILT_IN
113+ AND NOT DEFINED ACL_INCLUDE_DIR
114+ AND NOT DEFINED ACL_LIBRARY
115+ AND (
116+ CMAKE_PREFIX_PATH
117+ OR ACL_ROOT
118+ OR DEFINED ENV{ACL_ROOT}
119+ )
120+ )
108121 find_path (
109- _acl_INCLUDE_DIR
110- NAMES
111- sys/acl.h
112- PATHS
113- ${CMAKE_PREFIX_PATH}
114- ${ACL_ROOT}
115- PATH_SUFFIXES
116- include
117- NO_DEFAULT_PATH
122+ ACL_INCLUDE_DIR
123+ NAMES sys/acl.h
124+ DOC "Directory containing ACL library headers"
125+ NO_CMAKE_ENVIRONMENT_PATH
126+ NO_SYSTEM_ENVIRONMENT_PATH
127+ NO_CMAKE_INSTALL_PREFIX
128+ NO_CMAKE_SYSTEM_PATH
118129 )
119130
120- if (_acl_INCLUDE_DIR)
121- set (ACL_INCLUDE_DIR ${_acl_INCLUDE_DIR} )
131+ find_library (
132+ ACL_LIBRARY
133+ NAMES acl
134+ DOC "The path to the ACL library"
135+ NO_CMAKE_ENVIRONMENT_PATH
136+ NO_SYSTEM_ENVIRONMENT_PATH
137+ NO_CMAKE_INSTALL_PREFIX
138+ NO_CMAKE_SYSTEM_PATH
139+ )
140+
141+ if (ACL_INCLUDE_DIR AND ACL_LIBRARY)
122142 set (ACL_IS_BUILT_IN FALSE )
143+ else ()
144+ unset (ACL_INCLUDE_DIR CACHE )
145+ unset (ACL_LIBRARY CACHE )
123146 endif ()
124147endif ()
125148
126- ################################################################################
127- # Find package.
128- ################################################################################
129-
130149set (_reason "" )
150+ set (_ACL_REQUIRED_VARS "" )
131151
132152# If no compiler is loaded C library can't be checked anyway.
133153if (NOT CMAKE_C_COMPILER_LOADED AND NOT CMAKE_CXX_COMPILER_LOADED)
134154 set (ACL_IS_BUILT_IN FALSE )
135155endif ()
136156
137157if (NOT DEFINED ACL_IS_BUILT_IN)
138- block(PROPAGATE ACL_IS_BUILT_IN _acl_works)
139- _acl_check(_acl_works)
140-
141- if (_acl_works)
142- set (
143- ACL_IS_BUILT_IN
144- TRUE
145- CACHE INTERNAL
146- "Whether ACL is a part of the C library."
147- )
148- else ()
149- set (ACL_IS_BUILT_IN FALSE )
150- endif ()
151- endblock()
158+ _acl_check(ACL_IS_BUILT_IN)
159+
160+ if (ACL_IS_BUILT_IN)
161+ set (ACL_SANITY_CHECK TRUE )
162+ endif ()
152163endif ()
153164
154- set (_ACL_REQUIRED_VARS "" )
155165if (ACL_IS_BUILT_IN)
166+ _acl_check(ACL_SANITY_CHECK)
167+
156168 set (_ACL_REQUIRED_VARS _ACL_IS_BUILT_IN_MSG)
157169 set (_ACL_IS_BUILT_IN_MSG "built in to C library" )
158170else ()
@@ -169,9 +181,10 @@ else()
169181 HINTS ${PC_ACL_INCLUDE_DIRS}
170182 DOC "Directory containing ACL library headers"
171183 )
184+ mark_as_advanced (ACL_INCLUDE_DIR)
172185
173186 if (NOT ACL_INCLUDE_DIR)
174- string (APPEND _reason "sys/acl.h not found. " )
187+ string (APPEND _reason "< sys/acl.h> not found. " )
175188 endif ()
176189
177190 find_library (
@@ -180,6 +193,7 @@ else()
180193 HINTS ${PC_ACL_LIBRARY_DIRS}
181194 DOC "The path to the ACL library"
182195 )
196+ mark_as_advanced (ACL_LIBRARY)
183197
184198 if (NOT ACL_LIBRARY)
185199 string (APPEND _reason "ACL library not found. " )
@@ -190,35 +204,26 @@ else()
190204 set (ACL_VERSION ${PC_ACL_VERSION} )
191205 endif ()
192206
193- _acl_check(_acl_works)
194-
195- mark_as_advanced (ACL_INCLUDE_DIR ACL_LIBRARY)
207+ _acl_check(ACL_SANITY_CHECK)
196208endif ()
197209
198- if (NOT _acl_works )
210+ if (NOT ACL_SANITY_CHECK )
199211 if (ACL_USE_USER_GROUP)
200- string (APPEND _reason "ACL_USER and ACL_GROUP check failed. " )
212+ string (APPEND _reason "ACL_USER and ACL_GROUP sanity check failed. " )
201213 else ()
202- string (APPEND _reason "acl_free check failed. " )
214+ string (APPEND _reason "ACL sanity check failed. " )
203215 endif ()
204216endif ()
205217
206- ################################################################################
207- # Handle find_package arguments.
208- ################################################################################
209-
210218find_package_handle_standard_args(
211219 ACL
212- REQUIRED_VARS
213- ${_ACL_REQUIRED_VARS}
214- _acl_works
220+ REQUIRED_VARS ${_ACL_REQUIRED_VARS} ACL_SANITY_CHECK
215221 VERSION_VAR ACL_VERSION
216222 HANDLE_VERSION_RANGE
217223 REASON_FAILURE_MESSAGE "${_reason} "
218224)
219225
220226unset (_reason)
221- unset (_acl_works)
222227unset (_ACL_REQUIRED_VARS)
223228unset (_ACL_IS_BUILT_IN_MSG)
224229
0 commit comments