@@ -38,7 +38,7 @@ given headers, and determines if additional libraries need to be linked:
38
38
39
39
```cmake
40
40
php_search_libraries(
41
- SYMBOL <symbol> | SOURCE <code>
41
+ SYMBOL <symbol> | SOURCE_COMPILES <code> | SOURCE_RUNS <code>
42
42
[HEADERS <headers>...]
43
43
[LIBRARIES <libraries>...]
44
44
[RESULT_VARIABLE <var>]
@@ -59,10 +59,16 @@ libraries and links the first one in which the symbol is found.
59
59
60
60
The name of the C symbol to check.
61
61
62
- * `SOURCE <code>`
62
+ * `SOURCE_COMPILES <code>`
63
63
64
64
This argument can be used to check whether the specified C source `<code>` can
65
- be compiled and linked, instead of a `SYMBOL <symbol>` argument.
65
+ be compiled and linked, instead of a `SYMBOL`, or `SOURCE_RUNS` argument.
66
+
67
+ * `SOURCE_RUNS <code>`
68
+
69
+ This argument can be used to check whether the specified C source `<code>` can
70
+ be compiled, linked, and run, instead of a `SYMBOL`, or `SOURCE_COMPILES`
71
+ argument.
66
72
67
73
* `HEADERS <headers>...`
68
74
@@ -73,8 +79,8 @@ libraries and links the first one in which the symbol is found.
73
79
example, to be able to use `<arpa/nameser.h>` header on Solaris, the
74
80
`<sys/types.h>` header must be included before.
75
81
76
- When using `SOURCE <code>` argument, `<headers>` are prepended to the C source
77
- `<code>` using `#include <header>...`.
82
+ When using `SOURCE_COMPILES`, or `SOURCE_RUNS` argument, `<headers>` are
83
+ prepended to the C source `<code>` using `#include <header>...`.
78
84
79
85
* `LIBRARIES <libraries>...`
80
86
@@ -193,7 +199,7 @@ internal cache variable.
193
199
include(PHP/SearchLibraries)
194
200
195
201
php_search_libraries(
196
- SOURCE [[
202
+ SOURCE_COMPILES [[
197
203
#include <sys/types.h>
198
204
#include <sys/socket.h>
199
205
#include <netinet/in.h>
@@ -224,6 +230,7 @@ include_guard(GLOBAL)
224
230
225
231
include (CheckIncludeFiles)
226
232
include (CheckSourceCompiles)
233
+ include (CheckSourceRuns)
227
234
include (CheckSymbolExists)
228
235
include (CMakePushCheckState)
229
236
@@ -234,39 +241,64 @@ macro(_php_search_libraries_populate)
234
241
endif ()
235
242
endmacro ()
236
243
237
- function (_php_search_libraries_check_source source headers result)
244
+ function (_php_search_libraries_check_source_compiles source headers result)
238
245
foreach (header IN LISTS headers)
239
246
string (PREPEND source "#include <${header} >\n " )
240
247
endforeach ()
241
248
242
249
check_source_compiles(C "${source} " ${result} )
243
250
endfunction ()
244
251
252
+ function (_php_search_libraries_check_source_runs source headers result)
253
+ foreach (header IN LISTS headers)
254
+ string (PREPEND source "#include <${header} >\n " )
255
+ endforeach ()
256
+
257
+ check_source_runs(C "${source} " ${result} )
258
+ endfunction ()
259
+
245
260
function (php_search_libraries)
246
261
cmake_parse_arguments (
247
262
PARSE_ARGV
248
263
0
249
264
parsed # prefix
250
265
"RECHECK_HEADERS" # options
251
- "SYMBOL;SOURCE ;RESULT_VARIABLE;LIBRARY_VARIABLE" # one-value keywords
266
+ "SYMBOL;SOURCE_COMPILES;SOURCE_RUNS ;RESULT_VARIABLE;LIBRARY_VARIABLE" # one-value keywords
252
267
"HEADERS;LIBRARIES;TARGET" # multi-value keywords
253
268
)
254
269
255
270
if (parsed_UNPARSED_ARGUMENTS)
256
271
message (FATAL_ERROR "Unrecognized arguments: ${parsed_UNPARSED_ARGUMENTS} " )
257
272
endif ()
258
273
259
- if (NOT DEFINED parsed_SYMBOL AND NOT DEFINED parsed_SOURCE)
260
- message (FATAL_ERROR "Missing SYMBOL or SOURCE argument" )
261
- elseif (DEFINED parsed_SYMBOL AND DEFINED parsed_SOURCE)
262
- message (FATAL_ERROR "Use either SYMBOL or SOURCE argument. Not both." )
274
+ if (
275
+ NOT DEFINED parsed_SYMBOL
276
+ AND NOT DEFINED parsed_SOURCE_COMPILES
277
+ AND NOT DEFINED parsed_SOURCE_RUNS
278
+ )
279
+ message (
280
+ FATAL_ERROR
281
+ "Missing SYMBOL, SOURCE_COMPILES, or SOURCE_RUNS argument"
282
+ )
283
+ elseif (
284
+ (DEFINED parsed_SYMBOL AND DEFINED parsed_SOURCE_COMPILES)
285
+ OR (DEFINED parsed_SYMBOL AND DEFINED parsed_SOURCE_RUNS)
286
+ OR (DEFINED parsed_SOURCE_COMPILES AND DEFINED parsed_SOURCE_RUNS)
287
+ )
288
+ message (
289
+ FATAL_ERROR
290
+ "Use either SYMBOL, SOURCE_COMPILES, or SOURCE_RUNS argument. "
291
+ "Not multiple ones."
292
+ )
263
293
endif ()
264
294
265
295
if (NOT parsed_RESULT_VARIABLE OR NOT parsed_LIBRARY_VARIABLE)
266
296
if (DEFINED parsed_SYMBOL)
267
297
set (id "${parsed_SYMBOL} " )
268
- elseif (DEFINED parsed_SOURCE)
269
- set (id "${parsed_SOURCE} " )
298
+ elseif (DEFINED parsed_SOURCE_COMPILES)
299
+ set (id "${parsed_SOURCE_COMPILES} " )
300
+ elseif (DEFINED parsed_SOURCE_RUNS)
301
+ set (id "${parsed_SOURCE_RUNS} " )
270
302
endif ()
271
303
272
304
string (MD5 hash "${id} _${parsed_HEADERS} _${parsed_LIBRARIES} " )
@@ -344,9 +376,15 @@ function(php_search_libraries)
344
376
"${headersFound} "
345
377
${parsed_RESULT_VARIABLE}
346
378
)
347
- elseif (DEFINED parsed_SOURCE)
348
- _php_search_libraries_check_source(
349
- "${parsed_SOURCE} "
379
+ elseif (DEFINED parsed_SOURCE_COMPILES)
380
+ _php_search_libraries_check_source_compiles(
381
+ "${parsed_SOURCE_COMPILES} "
382
+ "${headersFound} "
383
+ ${parsed_RESULT_VARIABLE}
384
+ )
385
+ elseif (DEFINED parsed_SOURCE_RUNS)
386
+ _php_search_libraries_check_source_runs(
387
+ "${parsed_SOURCE_RUNS} "
350
388
"${headersFound} "
351
389
${parsed_RESULT_VARIABLE}
352
390
)
@@ -373,7 +411,7 @@ function(php_search_libraries)
373
411
CHECK_START
374
412
"Looking for ${parsed_SYMBOL} in library ${library} "
375
413
)
376
- elseif (DEFINED parsed_SOURCE )
414
+ elseif (DEFINED parsed_SOURCE_COMPILES OR DEFINED parsed_SOURCE_RUNS )
377
415
message (
378
416
CHECK_START
379
417
"Performing test ${parsed_RESULT_VARIABLE} with library ${library} "
@@ -399,9 +437,15 @@ function(php_search_libraries)
399
437
"${headersFound} "
400
438
${parsed_RESULT_VARIABLE}
401
439
)
402
- elseif (DEFINED parsed_SOURCE)
403
- _php_search_libraries_check_source(
404
- "${parsed_SOURCE} "
440
+ elseif (DEFINED parsed_SOURCE_COMPILES)
441
+ _php_search_libraries_check_source_compiles(
442
+ "${parsed_SOURCE_COMPILES} "
443
+ "${headersFound} "
444
+ ${parsed_RESULT_VARIABLE}
445
+ )
446
+ elseif (DEFINED parsed_SOURCE_RUNS)
447
+ _php_search_libraries_check_source_runs(
448
+ "${parsed_SOURCE_RUNS} "
405
449
"${headersFound} "
406
450
${parsed_RESULT_VARIABLE}
407
451
)
@@ -416,7 +460,7 @@ function(php_search_libraries)
416
460
# Store found library in a cache variable for internal purpose.
417
461
if (DEFINED parsed_SYMBOL)
418
462
set (help "Library required to use the '${parsed_SYMBOL} ' symbol." )
419
- elseif (DEFINED parsed_SOURCE )
463
+ elseif (DEFINED parsed_SOURCE_COMPILES OR DEFINED parsed_SOURCE_RUNS )
420
464
set (help "Library required for the '${parsed_RESULT_VARIABLE} ' test." )
421
465
endif ()
422
466
set (${parsed_LIBRARY_VARIABLE} ${library} CACHE INTERNAL "${help} " )
0 commit comments