|
| 1 | +#[=============================================================================[ |
| 2 | +# PHP/VerboseLink |
| 3 | +
|
| 4 | +This module checks whether to enable verbose output by linker: |
| 5 | +
|
| 6 | +```cmake |
| 7 | +include(PHP/VerboseLink) |
| 8 | +``` |
| 9 | +
|
| 10 | +This module provides the `PHP_VERBOSE_LINK` option to control enabling the |
| 11 | +verbose link output. Verbose linker flag is added to the global `php_config` |
| 12 | +target. |
| 13 | +
|
| 14 | +## Examples |
| 15 | +
|
| 16 | +When configuring project, enable the `PHP_VERBOSE_LINK` option to get verbose |
| 17 | +output at the link step: |
| 18 | +
|
| 19 | +```sh |
| 20 | +cmake -B php-build -D PHP_VERBOSE_LINK=ON |
| 21 | +cmake --build php-build -j |
| 22 | +``` |
| 23 | +#]=============================================================================] |
| 24 | + |
| 25 | +include_guard(GLOBAL) |
| 26 | + |
| 27 | +include(CheckLinkerFlag) |
| 28 | + |
| 29 | +option(PHP_VERBOSE_LINK "Whether to show additional info at the link step") |
| 30 | +mark_as_advanced(PHP_VERBOSE_LINK) |
| 31 | + |
| 32 | +if(NOT PHP_VERBOSE_LINK) |
| 33 | + return() |
| 34 | +endif() |
| 35 | + |
| 36 | +block() |
| 37 | + get_property(enabledLanguages GLOBAL PROPERTY ENABLED_LANGUAGES) |
| 38 | + |
| 39 | + foreach(lang IN ITEMS C CXX) |
| 40 | + if(NOT lang IN_LIST enabledLanguages) |
| 41 | + continue() |
| 42 | + endif() |
| 43 | + |
| 44 | + if(CMAKE_${lang}_COMPILER_LINKER_ID STREQUAL "MSVC") |
| 45 | + set(flags "LINKER:/VERBOSE") |
| 46 | + elseif(MSVC AND CMAKE_${lang}_COMPILER_LINKER_ID STREQUAL "LLD") |
| 47 | + set(flags "LINKER:-verbose") |
| 48 | + elseif(CMAKE_${lang}_COMPILER_LINKER_ID MATCHES "^(GNU|GNUgold|LLD)$") |
| 49 | + set(flags "LINKER:--verbose") |
| 50 | + else() |
| 51 | + set(flags "LINKER:--verbose") |
| 52 | + check_linker_flag(${lang} "${flags}" PHP_HAS_VERBOSE_LINK_FLAG_${lang}) |
| 53 | + if(NOT PHP_HAS_VERBOSE_LINK_FLAG_${lang}) |
| 54 | + set(flags "") |
| 55 | + endif() |
| 56 | + endif() |
| 57 | + |
| 58 | + if(flags) |
| 59 | + target_link_options( |
| 60 | + php_config |
| 61 | + INTERFACE $<$<LINK_LANGUAGE:${lang}>:${flags}> |
| 62 | + ) |
| 63 | + endif() |
| 64 | + endforeach() |
| 65 | +endblock() |
0 commit comments