@@ -8,59 +8,136 @@ summary alphabetically and categorizes enabled features into SAPIs, extensions,
88and other global PHP features. Common misconfiguration issues are summarized
99together with missing required system packages.
1010
11- https://cmake.org/cmake/help/latest/module/FeatureSummary.html
11+ See also: https://cmake.org/cmake/help/latest/module/FeatureSummary.html
12+
13+ ## Basic usage
14+
15+ ```cmake
16+ # CMakeLists.txt
17+
18+ # Include module and output configuration summary
19+ include(PHP/FeatureSummary)
20+ php_feature_summary()
21+ ```
22+
23+ ## Functions
24+
25+ Output PHP configuration summary:
26+
27+ ```cmake
28+ php_feature_summary()
29+ ```
1230#]=============================================================================]
1331
1432include_guard (GLOBAL )
1533
1634include (FeatureSummary)
1735
18- # Output summary prelude.
19- block()
36+ # Add new item to the summary preamble with dotted leader:
37+ # " * <what> ..................... : <value>"
38+ function (php_feature_summary_preamble_add_item what value output )
39+ if (${output} )
40+ # If preamble is already set, get first line to calculate column width:
41+ string (REGEX MATCH "^ \\\* ([^\r\n ]+ [.]+) : " _ "${${output} }" )
42+ else ()
43+ # Helper template to calculate column width:
44+ set (template " * <what> ..................... : <value>" )
45+ string (REGEX MATCH [[^ \* (<what> [.]+)]] _ "${template} " )
46+ endif ()
47+
48+ string (LENGTH "${CMAKE_MATCH_1} " width)
49+ string (LENGTH "${what} " length )
50+ math (EXPR numberOfDots "${width} - ${length} - 1" )
51+
52+ if (numberOfDots GREATER 0)
53+ string (REPEAT "." ${numberOfDots} leader)
54+ set (leader " ${leader} " )
55+ else ()
56+ set (leader)
57+ endif ()
58+
59+ string (APPEND ${output} " * ${what}${leader} : ${value} \n " )
60+ set ("${output} " "${${output} }" PARENT_SCOPE)
61+ endfunction ()
62+
63+ # Get summary preamble.
64+ function (php_feature_summary_preamble result)
2065 get_target_property (zendVersion Zend::Zend VERSION )
2166 get_target_property (zendExtensionApiNumber Zend::Zend ZEND_EXTENSION_API_NO)
2267 get_target_property (zendModuleApiNumber Zend::Zend ZEND_MODULE_API_NO)
2368
24- set (info )
69+ set (preamble )
2570 string (
2671 APPEND
27- info
72+ preamble
2873 " * PHP version ................ : ${PHP_VERSION} \n "
2974 " * PHP API version ............ : ${PHP_API_VERSION} \n "
3075 " * Zend Engine version ........ : ${zendVersion} \n "
3176 " * Zend extension API number .. : ${zendExtensionApiNumber} \n "
3277 " * Zend module API number ..... : ${zendModuleApiNumber} \n "
33- " * C compiler ................. : ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} (${CMAKE_C_COMPILER} )\n "
3478 )
3579
80+ if (CMAKE_C_COMPILER_LOADED)
81+ set (compiler)
82+ if (CMAKE_C_COMPILER_ID)
83+ string (APPEND compiler "${CMAKE_C_COMPILER_ID} " )
84+ endif ()
85+ if (CMAKE_C_COMPILER_VERSION)
86+ string (APPEND compiler " ${CMAKE_C_COMPILER_VERSION} " )
87+ endif ()
88+ string (STRIP "${compiler} " compiler)
89+ if (compiler)
90+ string (APPEND compiler " (${CMAKE_C_COMPILER} )" )
91+ else ()
92+ string (APPEND compiler "${CMAKE_C_COMPILER} " )
93+ endif ()
94+ php_feature_summary_preamble_add_item("C compiler" "${compiler} " preamble)
95+ endif ()
96+
3697 if (CMAKE_CXX_COMPILER_LOADED)
37- string (
38- APPEND
39- info
40- " * CXX compiler ............... : ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} (${CMAKE_CXX_COMPILER} )\n "
41- )
98+ set (compiler)
99+ if (CMAKE_CXX_COMPILER_ID)
100+ string (APPEND compiler "${CMAKE_CXX_COMPILER_ID} " )
101+ endif ()
102+ if (CMAKE_CXX_COMPILER_VERSION)
103+ string (APPEND compiler " ${CMAKE_CXX_COMPILER_VERSION} " )
104+ endif ()
105+ string (STRIP "${compiler} " compiler)
106+ if (compiler)
107+ string (APPEND compiler " (${CMAKE_CXX_COMPILER} )" )
108+ else ()
109+ string (APPEND compiler "${CMAKE_CXX_COMPILER} " )
110+ endif ()
111+ php_feature_summary_preamble_add_item("CXX compiler" "${compiler} " preamble)
42112 endif ()
43113
44- string (
45- APPEND
46- info
47- " * Install prefix ............. : ${CMAKE_INSTALL_PREFIX} \n "
48- )
114+ get_property (isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
115+ if (isMultiConfig)
116+ set (buildType "Multi-config generator" )
117+ elseif (CMAKE_BUILD_TYPE )
118+ set (buildType "${CMAKE_BUILD_TYPE} " )
119+ else ()
120+ set (buildType "N/A" )
121+ endif ()
122+
123+ php_feature_summary_preamble_add_item("Build type" "${buildType} " preamble)
124+ php_feature_summary_preamble_add_item("Install prefix" "${CMAKE_INSTALL_PREFIX} " preamble)
125+
126+ set (${result} "${preamble} " PARENT_SCOPE)
127+ endfunction ()
128+
129+ # Output configuration summary.
130+ function (php_feature_summary)
131+ php_feature_summary_preamble(preamble)
49132
50133 message (STATUS "" )
51134 message (STATUS "" )
52- message (STATUS "PHP summary" )
53- message (STATUS "===========\n\n ${info} " )
54- endblock()
135+ message (STATUS "PHP configuration summary" )
136+ message (STATUS "=========================\n\n ${preamble} " )
55137
56- # Output enabled features.
57- block()
138+ # Output enabled features.
58139 get_property (enabledFeatures GLOBAL PROPERTY ENABLED_FEATURES )
59-
60- if (enabledFeatures)
61- list (REMOVE_DUPLICATES enabledFeatures)
62- endif ()
63-
140+ list (REMOVE_DUPLICATES enabledFeatures)
64141 list (SORT enabledFeatures COMPARE NATURAL CASE INSENSITIVE)
65142
66143 set (php "" )
@@ -116,10 +193,8 @@ block()
116193 if (extensions)
117194 message (STATUS "Enabled PHP extensions:\n\n ${extensions} " )
118195 endif ()
119- endblock()
120196
121- # Get missing extensions.
122- block()
197+ # Get missing extensions.
123198 set (missingExtensions "" )
124199 set (sharedExtensionsSummary "" )
125200
@@ -216,4 +291,4 @@ block()
216291 QUIET_ON_EMPTY
217292 DESCRIPTION "The following REQUIRED packages have not been found:\n "
218293 )
219- endblock ()
294+ endfunction ()
0 commit comments