Skip to content

Commit a3c1d13

Browse files
authored
Merge pull request syslog-ng#5127 from HofiOne/cmake-config-summary-update
cmake: add better separation/grouping to the options summary list
2 parents d79f002 + 4e83a49 commit a3c1d13

File tree

1 file changed

+88
-41
lines changed

1 file changed

+88
-41
lines changed

cmake/print_config_summary.cmake

+88-41
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,24 @@
2121
#
2222
# ############################################################################
2323

24-
string (ASCII 27 Esc)
25-
set (Red "${Esc}[31m")
26-
set (Green "${Esc}[32m")
27-
set (Yellow "${Esc}[33m")
28-
set (ResetFG "${Esc}[39m")
24+
string(ASCII 27 Esc)
25+
set(Red "${Esc}[31m")
26+
set(Green "${Esc}[32m")
27+
set(Yellow "${Esc}[33m")
28+
set(Blue "${Esc}[34m")
29+
set(ResetFG "${Esc}[39m")
30+
31+
set(_maxHeaderLen 39)
32+
33+
list(APPEND _envInfo "CMAKE_HOST_SYSTEM" "CMAKE_HOST_SYSTEM_NAME" "CMAKE_HOST_SYSTEM_PROCESSOR" "CMAKE_HOST_SYSTEM_VERSION")
34+
list(APPEND _subModules "IVYKIS_SOURCE")
35+
list(APPEND _compilersInfo "CMAKE_C_COMPILER" "CMAKE_CXX_COMPILER" "CMAKE_OBJC_COMPILER")
36+
list(APPEND _compilationsOptions "CMAKE_BUILD_TYPE" "BUILD_TESTING" "ENABLE_EXTRA_WARNINGS")
37+
if(APPLE)
38+
list(APPEND _compilationsOptions "FORCE_CLASSIC_LINKING")
39+
endif()
40+
41+
option(SUMMARY_LEVEL "Detail level of the cmake options summary information (0,1 or 2)" 0)
2942

3043
function(_space_tabbed_string _variableName _maxVarNameLen _outputVariable)
3144
set(_spaces "")
@@ -38,7 +51,7 @@ function(_space_tabbed_string _variableName _maxVarNameLen _outputVariable)
3851
set(_variableNameLen 0)
3952
endif()
4053

41-
string (REPEAT " " ${_variableNameLen} _spaces)
54+
string(REPEAT " " ${_variableNameLen} _spaces)
4255
endif()
4356

4457
set(${_outputVariable} "${_variableName}${_spaces}" PARENT_SCOPE)
@@ -57,12 +70,25 @@ function(_print_summary_line _variableName _variableValue _maxVarNameLen)
5770
elseif(_upperValue STREQUAL "OFF" OR _upperValue STREQUAL "FALSE")
5871
message("${_spaceTabbedVariableName}${Red}Off${ResetFG}")
5972
else()
60-
message("${_spaceTabbedVariableName}${Green}${_variableValue}${ResetFG}")
73+
message("${_spaceTabbedVariableName}${Blue}${_variableValue}${ResetFG}")
6174
endif()
6275
endfunction()
6376

64-
function(_print_separator)
65-
message(NOTICE "-----------------------------------")
77+
function(_print_separator _header)
78+
string(LENGTH "${_header}" _headerLen)
79+
if(_headerLen LESS_EQUAL 0)
80+
string(REPEAT "-" ${_maxHeaderLen} _header)
81+
else()
82+
math(EXPR _headerSeparatorLen "(${_maxHeaderLen} - ${_headerLen} - 2) / 2")
83+
math(EXPR _total_len "((${_headerSeparatorLen} * 2) + ${_headerLen} + 2)")
84+
set(_padding "")
85+
if(_total_len LESS ${_maxHeaderLen})
86+
set(_padding "-")
87+
endif()
88+
string(REPEAT "-" ${_headerSeparatorLen} _headerSeparator)
89+
set(_header "${_headerSeparator} ${_header} ${_headerSeparator}${_padding}")
90+
endif()
91+
message(NOTICE "${_header}")
6692
endfunction()
6793

6894
function(_print_libraries _variableNames)
@@ -72,36 +98,40 @@ function(_print_libraries _variableNames)
7298
string(REGEX MATCH ".*(INCLUDE_DIR|INCLUDEDIR|INCLUDE_DIRS|INCLUDE_OPTS)$" _match_incl "${_variableName}")
7399
string(REGEX MATCH "^(CMAKE_|_).*" _cmakeInternal "${_variableName}")
74100

75-
if ((_match_lib OR _match_incl OR _match_found) AND NOT _cmakeInternal)
101+
if((_match_lib OR _match_incl OR _match_found) AND NOT _cmakeInternal)
76102
_print_summary_line("${_variableName}=" "${${_variableName}}" 0)
77103
endif()
78104
endforeach()
79105
endfunction()
80106

81-
function(_print_importants _variableNames _importantVariableNames)
82-
foreach(_variableName ${_variableNames})
83-
foreach(_importantVariableName ${_importantVariableNames})
107+
function(_print_compilers_info _variableNames _importantVariableNames)
108+
foreach(_importantVariableName ${_importantVariableNames})
109+
foreach(_variableName ${_variableNames})
84110
string(REGEX MATCH "^${_importantVariableName}$" _match "${_variableName}")
85111

86112
if(_match)
87113
string(REGEX MATCH ".*(_COMPILER)$" _isCompiler "${_variableName}")
88114

89115
if(_isCompiler)
90116
set(_compilerVersion "")
91-
get_filename_component (_executable_name "${${_variableName}}" NAME_WE)
92-
execute_process (
93-
COMMAND ${${_variableName}} --version
94-
COMMAND grep -i ${_executable_name}
95-
OUTPUT_VARIABLE _compilerVersion
96-
OUTPUT_STRIP_TRAILING_WHITESPACE
97-
)
98-
execute_process (
117+
get_filename_component(_executable_name "${${_variableName}}" NAME_WE)
118+
execute_process(
99119
COMMAND which ${${_variableName}}
100120
OUTPUT_VARIABLE _compilerPath
101121
OUTPUT_STRIP_TRAILING_WHITESPACE
102122
)
123+
execute_process(
124+
COMMAND "${_compilerPath}" --version
125+
# version info does not always contain the exact executable name (clang++ -> clang)
126+
# using now the hardcoded first line content instead :S
127+
#COMMAND grep -i ${_executable_name}
128+
COMMAND head -n 1
129+
OUTPUT_VARIABLE _compilerVersion
130+
OUTPUT_STRIP_TRAILING_WHITESPACE
131+
)
103132
_space_tabbed_string("${_variableName}" 32 _spaceTabbedVariableName)
104-
_print_summary_line("${_spaceTabbedVariableName}${_executable_name}" "[${Yellow}${_compilerVersion}${Green}]${ResetFG} - ${_compilerPath}" 40)
133+
_space_tabbed_string ("${_executable_name}" 10 _spaceTabbedExecutable_name)
134+
_print_summary_line("${_spaceTabbedVariableName}" "${_spaceTabbedExecutable_name}${Green}[${Yellow}${_compilerVersion}${Green}]${ResetFG} - ${_compilerPath}" 32)
105135
unset(_compilerVersion)
106136
else()
107137
_print_summary_line("${_importantVariableName}" "${${_importantVariableName}}" 32)
@@ -111,16 +141,27 @@ function(_print_importants _variableNames _importantVariableNames)
111141
endforeach()
112142
endfunction()
113143

114-
function(_print_options _variableNames)
144+
function(_print_module_options _variableNames)
115145
foreach(_variableName ${_variableNames})
116146
string(REGEX MATCH "^ENABLE_" _match "${_variableName}")
147+
list(FIND _compilationsOptions "${_variableName}" _index)
117148

118-
if(_match)
149+
if(_match AND _index LESS 0)
119150
_print_summary_line("${_variableName}" "${${_variableName}}" 32)
120151
endif()
121152
endforeach()
122153
endfunction()
123154

155+
function(_print_options _variableNames _options)
156+
foreach (_option ${_options})
157+
list(FIND _variableNames "${_option}" _index)
158+
159+
if(_index GREATER_EQUAL 0)
160+
_print_summary_line("${_option}" "${${_option}}" 32)
161+
endif()
162+
endforeach ()
163+
endfunction ()
164+
124165
function(_print_full _variableNames)
125166
foreach(_variableName ${_variableNames})
126167
message("${_variableName}=${${_variableName}}")
@@ -133,29 +174,35 @@ endfunction()
133174
function(print_config_summary)
134175
get_cmake_property(_variableNames VARIABLES)
135176
list(SORT _variableNames)
136-
list (REMOVE_DUPLICATES _variableNames)
137-
138-
_print_separator()
139-
message(NOTICE "syslog-ng Open Source Edition ${SYSLOG_NG_VERSION} configured")
140-
_print_separator()
177+
list(REMOVE_DUPLICATES _variableNames)
141178

142-
if(SUMMARY_FULL)
179+
if(SUMMARY_FULL OR SUMMARY_LEVEL GREATER_EQUAL 2)
180+
_print_separator("")
143181
_print_full("${_variableNames}")
144182
else()
145-
if(SUMMARY_VERBOSE)
183+
if(SUMMARY_VERBOSE OR SUMMARY_LEVEL EQUAL 1)
184+
_print_separator("")
146185
_print_libraries("${_variableNames}")
147-
_print_separator()
148186
endif()
187+
endif()
149188

150-
list(APPEND _importantVariableNames "IVYKIS_INTERNAL" "BUILD_TESTING" "CMAKE_C_COMPILER" "CMAKE_CXX_COMPILER" "CMAKE_OBJC_COMPILER" "CMAKE_BUILD_TYPE")
151-
if (APPLE)
152-
list(APPEND _importantVariableNames "FORCE_CLASSIC_LINKING")
153-
endif()
154-
_print_importants("${_variableNames}" "${_importantVariableNames}")
155-
_print_separator()
189+
_print_separator("")
190+
message (NOTICE "syslog-ng Open Source Edition ${SYSLOG_NG_VERSION} configured")
156191

157-
_print_options("${_variableNames}")
158-
endif()
192+
_print_separator("Environment")
193+
_print_options ("${_variableNames}" "${_envInfo}")
194+
195+
_print_separator("Compilers")
196+
_print_compilers_info("${_variableNames}" "${_compilersInfo}")
197+
198+
_print_separator("Compilation")
199+
_print_options("${_variableNames}" "${_compilationsOptions}")
200+
201+
_print_separator("Sub-modules")
202+
_print_options("${_variableNames}" "${_subModules}")
203+
204+
_print_separator("Modules")
205+
_print_module_options("${_variableNames}")
159206

160-
_print_separator()
207+
_print_separator("")
161208
endfunction()

0 commit comments

Comments
 (0)