File: print_config_summary.cmake

package info (click to toggle)
syslog-ng 4.8.1-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,456 kB
  • sloc: ansic: 177,631; python: 13,035; cpp: 11,611; makefile: 7,012; sh: 5,147; java: 3,651; xml: 3,344; yacc: 1,377; lex: 599; perl: 193; awk: 190; objc: 162
file content (208 lines) | stat: -rw-r--r-- 7,782 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# ############################################################################
# Copyright (c) 2022 One Identity
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# As an additional exemption you are allowed to compile & link against the
# OpenSSL libraries as published by the OpenSSL project. See the file
# COPYING for details.
#
# ############################################################################

string(ASCII 27 Esc)
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(ResetFG "${Esc}[39m")

set(_maxHeaderLen 39)

list(APPEND _envInfo "CMAKE_HOST_SYSTEM" "CMAKE_HOST_SYSTEM_NAME" "CMAKE_HOST_SYSTEM_PROCESSOR" "CMAKE_HOST_SYSTEM_VERSION")
list(APPEND _subModules "IVYKIS_SOURCE")
list(APPEND _compilersInfo "CMAKE_C_COMPILER" "CMAKE_CXX_COMPILER" "CMAKE_OBJC_COMPILER")
list(APPEND _compilationsOptions "CMAKE_BUILD_TYPE" "BUILD_TESTING" "ENABLE_EXTRA_WARNINGS" "ENABLE_FORCE_GNU99")
if(APPLE)
  list(APPEND _compilationsOptions "FORCE_CLASSIC_LINKING")
endif()

option(SUMMARY_LEVEL "Detail level of the cmake options summary information (0,1 or 2)" 0)

function(_space_tabbed_string _variableName _maxVarNameLen _outputVariable)
  set(_spaces "")

  if(_maxVarNameLen GREATER 0)
    string(LENGTH "${_variableName}" _variableNameLen)
    math(EXPR _variableNameLen "${_maxVarNameLen} - ${_variableNameLen}")

    if(_variableNameLen LESS 0)
      set(_variableNameLen 0)
    endif()

    string(REPEAT " " ${_variableNameLen} _spaces)
  endif()

  set(${_outputVariable} "${_variableName}${_spaces}" PARENT_SCOPE)
  # return(PROPAGATE ${_outputVariable})
endfunction()

function(_print_summary_line _variableName _variableValue _maxVarNameLen)
  set(_spaceTabbedVariableName "${_variableName}")

  _space_tabbed_string("${_variableName}" ${_maxVarNameLen} _spaceTabbedVariableName)

  string(TOUPPER "${_variableValue}" _upperValue)

  if(_upperValue STREQUAL "ON" OR _upperValue STREQUAL "TRUE")
    message("${_spaceTabbedVariableName}${Green}On${ResetFG}")
  elseif(_upperValue STREQUAL "OFF" OR _upperValue STREQUAL "FALSE")
    message("${_spaceTabbedVariableName}${Red}Off${ResetFG}")
  else()
    message("${_spaceTabbedVariableName}${Blue}${_variableValue}${ResetFG}")
  endif()
endfunction()

function(_print_separator _header)
  string(LENGTH "${_header}" _headerLen)
  if(_headerLen LESS_EQUAL 0)
    string(REPEAT "-" ${_maxHeaderLen} _header)
  else()
    math(EXPR _headerSeparatorLen "(${_maxHeaderLen} - ${_headerLen} - 2) / 2")
    math(EXPR _total_len "((${_headerSeparatorLen} * 2) + ${_headerLen} + 2)")
    set(_padding "")
    if(_total_len LESS ${_maxHeaderLen})
      set(_padding "-")
    endif()
    string(REPEAT "-" ${_headerSeparatorLen} _headerSeparator)
    set(_header "${_headerSeparator} ${_header} ${_headerSeparator}${_padding}")
  endif()
  message(NOTICE "${_header}")
endfunction()

function(_print_libraries _variableNames)
  foreach(_variableName ${_variableNames})
    string(REGEX MATCH ".*(_FOUND)$" _match_found "${_variableName}")
    string(REGEX MATCH ".*(_LIBRARY|_LIBRARIES|_LIBRARY_OPTS)$" _match_lib "${_variableName}")
    string(REGEX MATCH ".*(INCLUDE_DIR|INCLUDEDIR|INCLUDE_DIRS|INCLUDE_OPTS)$" _match_incl "${_variableName}")
    string(REGEX MATCH "^(CMAKE_|_).*" _cmakeInternal "${_variableName}")

    if((_match_lib OR _match_incl OR _match_found) AND NOT _cmakeInternal)
      _print_summary_line("${_variableName}=" "${${_variableName}}" 0)
    endif()
  endforeach()
endfunction()

function(_print_compilers_info _variableNames _importantVariableNames)
  foreach(_importantVariableName ${_importantVariableNames})
    foreach(_variableName ${_variableNames})
      string(REGEX MATCH "^${_importantVariableName}$" _match "${_variableName}")

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

        if(_isCompiler)
          set(_compilerVersion "")
          get_filename_component(_executable_name "${${_variableName}}" NAME_WE)
          execute_process(
            COMMAND which ${${_variableName}}
            OUTPUT_VARIABLE _compilerPath
            OUTPUT_STRIP_TRAILING_WHITESPACE
          )
          execute_process(
            COMMAND "${_compilerPath}" --version
            # version info does not always contain the exact executable name (clang++ -> clang)
            # using now the hardcoded first line content instead :S
            #COMMAND grep -i ${_executable_name}
            COMMAND head -n 1
            OUTPUT_VARIABLE _compilerVersion
            OUTPUT_STRIP_TRAILING_WHITESPACE
          )
          _space_tabbed_string("${_variableName}" 32 _spaceTabbedVariableName)
          _space_tabbed_string ("${_executable_name}" 10 _spaceTabbedExecutable_name)
          _print_summary_line("${_spaceTabbedVariableName}" "${_spaceTabbedExecutable_name}${Green}[${Yellow}${_compilerVersion}${Green}]${ResetFG} - ${_compilerPath}" 32)
          unset(_compilerVersion)
        else()
          _print_summary_line("${_importantVariableName}" "${${_importantVariableName}}" 32)
        endif()
      endif()
    endforeach()
  endforeach()
endfunction()

function(_print_module_options _variableNames)
  foreach(_variableName ${_variableNames})
    string(REGEX MATCH "^ENABLE_" _match "${_variableName}")
    list(FIND _compilationsOptions "${_variableName}" _index)

    if(_match AND _index LESS 0)
      _print_summary_line("${_variableName}" "${${_variableName}}" 32)
    endif()
  endforeach()
endfunction()

function(_print_options _variableNames _options)
  foreach (_option ${_options})
    list(FIND _variableNames "${_option}" _index)

    if(_index GREATER_EQUAL 0)
      _print_summary_line("${_option}" "${${_option}}" 32)
    endif()
  endforeach ()
endfunction ()

function(_print_full _variableNames)
  foreach(_variableName ${_variableNames})
    message("${_variableName}=${${_variableName}}")
  endforeach()
endfunction()

# Lists actual module definition results
# Behaves similar to the cmake -L option but filters out the relevant information and adds some highlighting
#
function(print_config_summary)
  get_cmake_property(_variableNames VARIABLES)
  list(SORT _variableNames)
  list(REMOVE_DUPLICATES _variableNames)

  if(SUMMARY_FULL OR SUMMARY_LEVEL GREATER_EQUAL 2)
    _print_separator("")
    _print_full("${_variableNames}")
  else()
    if(SUMMARY_VERBOSE OR SUMMARY_LEVEL EQUAL 1)
      _print_separator("")
      _print_libraries("${_variableNames}")
    endif()
  endif()

  _print_separator("")
  message (NOTICE "syslog-ng Open Source Edition ${SYSLOG_NG_VERSION} configured")

  _print_separator("Environment")
  _print_options ("${_variableNames}" "${_envInfo}")

  _print_separator("Compilers")
  _print_compilers_info("${_variableNames}" "${_compilersInfo}")

  _print_separator("Compilation")
  _print_options("${_variableNames}" "${_compilationsOptions}")

  _print_separator("Sub-modules")
  _print_options("${_variableNames}" "${_subModules}")

  _print_separator("Modules")
  _print_module_options("${_variableNames}")

  _print_separator("")
endfunction()