@@ -28,7 +28,7 @@ php_search_libraries(
2828 [LIBRARIES <library>...]
2929 [VARIABLE <variable>]
3030 [LIBRARY_VARIABLE <library_variable>]
31- [TARGET <target> <PRIVATE|PUBLIC|INTERFACE>]
31+ [TARGET <target> [ <PRIVATE|PUBLIC|INTERFACE>] ]
3232 [RECHECK_HEADERS]
3333)
3434```
@@ -68,11 +68,11 @@ If `<variable>` is given, check result is stored in an internal cache variable.
6868* `TARGET`
6969
7070 If the `TARGET` is given, the resulting library is linked to a given
71- `<target>` with the scope of `PRIVATE`, `PUBLIC`, or `INTERFACE`. It is
71+ `<target>` with the scope of `PRIVATE`, `PUBLIC`, or `INTERFACE`. Behavior is
7272 homogeneous to:
7373
7474 ```cmake
75- target_link_libraries(<target> PRIVATE|PUBLIC|INTERFACE <library>)
75+ target_link_libraries(<target> [ PRIVATE|PUBLIC|INTERFACE] <library>)
7676 ```
7777
7878* `RECHECK_HEADERS`
@@ -85,11 +85,21 @@ If `<variable>` is given, check result is stored in an internal cache variable.
8585 checked elsewhere in the application using the `check_header_include()`. In
8686 most cases this won't be needed.
8787
88- For example:
88+ ## Basic usage
89+
90+ In the following example, the library containing `dlopen` is linked to
91+ `php_configuration` target with the `INTERFACE` scope when needed to use the
92+ `dlopen` symbol. Cache variable `HAVE_LIBDL` is set if `dlopen` is found either
93+ in the default system libraries or in one of the libraries set in the
94+ `CMAKE_DL_LIBS` variable.
8995
9096```cmake
97+ # CMakeLists.txt
98+
99+ # Include the module
91100include(PHP/SearchLibraries)
92101
102+ # Search and link library containing dlopen and dlclose .
93103php_search_libraries(
94104 dlopen
95105 HEADERS dlfcn.h
@@ -108,9 +118,10 @@ https://cmake.org/cmake/help/latest/module/CheckSymbolExists.html
108118* `CMAKE_REQUIRED_INCLUDES`
109119* `CMAKE_REQUIRED_LINK_OPTIONS`
110120* `CMAKE_REQUIRED_LIBRARIES`
121+ * `CMAKE_REQUIRED_LINK_DIRECTORIES`
111122* `CMAKE_REQUIRED_QUIET`
112123
113- Caveats:
124+ ## Caveats
114125
115126* If symbol declaration is missing in its belonging headers, it won't be found
116127 with this module. There are still rare cases of such functions on some systems
@@ -207,20 +218,18 @@ function(php_search_libraries)
207218 # Validate optional TARGET.
208219 if (parsed_TARGET)
209220 list (GET parsed_TARGET 0 target )
210- list (GET parsed_TARGET 1 targetScope)
211221
212222 if (NOT TARGET ${target} )
213223 message (FATAL_ERROR "Bad TARGET arguments: ${target} is not a target" )
214224 endif ()
215225
216- if (NOT targetScope)
217- message (
218- FATAL_ERROR
219- "Bad TARGET arguments: Target scope PRIVATE|PUBLIC|INTERFACE is missing"
220- )
226+ list (LENGTH parsed_TARGET length )
227+ set (targetScope)
228+ if (length GREATER 1)
229+ list (GET parsed_TARGET 1 targetScope)
221230 endif ()
222231
223- if (NOT targetScope MATCHES "^(PRIVATE|PUBLIC|INTERFACE)$" )
232+ if (targetScope AND NOT targetScope MATCHES "^(PRIVATE|PUBLIC|INTERFACE)$" )
224233 message (
225234 FATAL_ERROR
226235 "Bad TARGET arguments: ${targetScope} is not a target scope. Use one "
0 commit comments