@@ -38,7 +38,7 @@ given headers, and determines if additional libraries need to be linked:
3838
3939```cmake
4040php_search_libraries(
41- SYMBOL <symbol> | SOURCE <code>
41+ SYMBOL <symbol> | SOURCE_COMPILES <code> | SOURCE_RUNS <code>
4242 [HEADERS <headers>...]
4343 [LIBRARIES <libraries>...]
4444 [RESULT_VARIABLE <var>]
@@ -59,10 +59,16 @@ libraries and links the first one in which the symbol is found.
5959
6060 The name of the C symbol to check.
6161
62- * `SOURCE <code>`
62+ * `SOURCE_COMPILES <code>`
6363
6464 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.
6672
6773* `HEADERS <headers>...`
6874
@@ -73,8 +79,8 @@ libraries and links the first one in which the symbol is found.
7379 example, to be able to use `<arpa/nameser.h>` header on Solaris, the
7480 `<sys/types.h>` header must be included before.
7581
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>...`.
7884
7985* `LIBRARIES <libraries>...`
8086
@@ -193,7 +199,7 @@ internal cache variable.
193199include(PHP/SearchLibraries)
194200
195201php_search_libraries(
196- SOURCE [[
202+ SOURCE_COMPILES [[
197203 #include <sys/types.h>
198204 #include <sys/socket.h>
199205 #include <netinet/in.h>
@@ -224,6 +230,7 @@ include_guard(GLOBAL)
224230
225231include (CheckIncludeFiles)
226232include (CheckSourceCompiles)
233+ include (CheckSourceRuns)
227234include (CheckSymbolExists)
228235include (CMakePushCheckState)
229236
@@ -234,39 +241,64 @@ macro(_php_search_libraries_populate)
234241 endif ()
235242endmacro ()
236243
237- function (_php_search_libraries_check_source source headers result)
244+ function (_php_search_libraries_check_source_compiles source headers result)
238245 foreach (header IN LISTS headers)
239246 string (PREPEND source "#include <${header} >\n " )
240247 endforeach ()
241248
242249 check_source_compiles(C "${source} " ${result} )
243250endfunction ()
244251
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+
245260function (php_search_libraries)
246261 cmake_parse_arguments (
247262 PARSE_ARGV
248263 0
249264 parsed # prefix
250265 "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
252267 "HEADERS;LIBRARIES;TARGET" # multi-value keywords
253268 )
254269
255270 if (parsed_UNPARSED_ARGUMENTS)
256271 message (FATAL_ERROR "Unrecognized arguments: ${parsed_UNPARSED_ARGUMENTS} " )
257272 endif ()
258273
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+ )
263293 endif ()
264294
265295 if (NOT parsed_RESULT_VARIABLE OR NOT parsed_LIBRARY_VARIABLE)
266296 if (DEFINED parsed_SYMBOL)
267297 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} " )
270302 endif ()
271303
272304 string (MD5 hash "${id} _${parsed_HEADERS} _${parsed_LIBRARIES} " )
@@ -344,9 +376,15 @@ function(php_search_libraries)
344376 "${headersFound} "
345377 ${parsed_RESULT_VARIABLE}
346378 )
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} "
350388 "${headersFound} "
351389 ${parsed_RESULT_VARIABLE}
352390 )
@@ -373,7 +411,7 @@ function(php_search_libraries)
373411 CHECK_START
374412 "Looking for ${parsed_SYMBOL} in library ${library} "
375413 )
376- elseif (DEFINED parsed_SOURCE )
414+ elseif (DEFINED parsed_SOURCE_COMPILES OR DEFINED parsed_SOURCE_RUNS )
377415 message (
378416 CHECK_START
379417 "Performing test ${parsed_RESULT_VARIABLE} with library ${library} "
@@ -399,9 +437,15 @@ function(php_search_libraries)
399437 "${headersFound} "
400438 ${parsed_RESULT_VARIABLE}
401439 )
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} "
405449 "${headersFound} "
406450 ${parsed_RESULT_VARIABLE}
407451 )
@@ -416,7 +460,7 @@ function(php_search_libraries)
416460 # Store found library in a cache variable for internal purpose.
417461 if (DEFINED parsed_SYMBOL)
418462 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 )
420464 set (help "Library required for the '${parsed_RESULT_VARIABLE} ' test." )
421465 endif ()
422466 set (${parsed_LIBRARY_VARIABLE} ${library} CACHE INTERNAL "${help} " )
0 commit comments