Skip to content

Commit f753d29

Browse files
committed
Add PHP/VerboseLink module with PHP_VERBOSE_LINK option
The output by linker when using flags such as `/VERBOSE` on MSVC or `--verbose` on some other linkers can be extremely verbose. This module provides option to enable verbosity at the link step.
1 parent 82a09d9 commit f753d29

File tree

2 files changed

+66
-17
lines changed

2 files changed

+66
-17
lines changed

cmake/cmake/Flags.cmake

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Check and configure compilation options.
44

55
include_guard(GLOBAL)
66

7-
include(CheckLinkerFlag)
87
include(CheckSourceRuns)
98
include(CMakePushCheckState)
109
include(PHP/CheckCompilerFlag)
@@ -499,21 +498,6 @@ endif()
499498
# Check linker flags.
500499
################################################################################
501500

502-
# Align segments on huge page boundary.
503501
include(${CMAKE_CURRENT_LIST_DIR}/checks/CheckSegmentsAlignment.cmake)
504502

505-
check_linker_flag(C LINKER:/verbose PHP_HAS_VERBOSE_LINKER_FLAG_C)
506-
if(PHP_HAS_VERBOSE_LINKER_FLAG_C)
507-
target_link_options(
508-
php_config
509-
INTERFACE $<$<AND:$<CONFIG:Debug>,$<LINK_LANGUAGE:C>>:LINKER:/verbose>
510-
)
511-
endif()
512-
513-
check_linker_flag(CXX LINKER:/verbose PHP_HAS_VERBOSE_LINKER_FLAG_CXX)
514-
if(PHP_HAS_VERBOSE_LINKER_FLAG_CXX)
515-
target_link_options(
516-
php_config
517-
INTERFACE $<$<AND:$<CONFIG:Debug>,$<LINK_LANGUAGE:CXX>>:LINKER:/verbose>
518-
)
519-
endif()
503+
include(PHP/VerboseLink)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)