@@ -7,6 +7,7 @@ include_guard(GLOBAL)
77# Debug
88message (VERBOSE "rsp/debug module included" )
99
10+ include ("rsp/output/utils" )
1011include ("rsp/helpers" )
1112
1213if (NOT COMMAND "dump" )
@@ -194,3 +195,90 @@ if (NOT COMMAND "var_dump")
194195
195196 endfunction ()
196197endif ()
198+
199+ if (NOT COMMAND "build_info" )
200+
201+ #! build_info : Output build information to stdout or stderr (Cmake's message type specific)
202+ #
203+ # @see https://cmake.org/cmake/help/latest/command/message.html
204+ #
205+ # @param [<mode>] Option - Cmake's message type. Defaults to NOTICE, when not specified.
206+ # @param [OUTPUT <variable>] Optional - If specified, message is assigned to output variable instead of
207+ # being printed to stdout or stderr.
208+ #
209+ # @return
210+ # [OUTPUT] The resulting output variable, if OUTPUT was specified.
211+ #
212+ function (build_info)
213+ set (options "${RSP_CMAKE_MESSAGE_MODES} " )
214+ set (oneValueArgs OUTPUT )
215+ set (multiValueArgs "" )
216+
217+ cmake_parse_arguments (INPUT "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
218+
219+ # ---------------------------------------------------------------------------------------------- #
220+
221+ # Message mode
222+ resolve_msg_mode("NOTICE" )
223+
224+ # ---------------------------------------------------------------------------------------------- #
225+
226+ set (info_list
227+ # Build Type
228+ # @see https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html
229+ "Type|${CMAKE_BUILD_TYPE} "
230+
231+ # Library Type (NOTE: LIB_TYPE is NOT a predefined cmake variable)
232+ "Library Type|${LIB_TYPE} "
233+
234+ # Compiler flags
235+ "Compiler flags|${CMAKE_CXX_COMPILE_FLAGS} "
236+
237+ # Compiler cxx debug flags
238+ "Compiler cxx debug flags|${CMAKE_CXX_FLAGS_DEBUG} "
239+
240+ # Compiler cxx release flags
241+ "Compiler cxx release flags|${CMAKE_CXX_FLAGS_RELEASE} "
242+
243+ # Compiler cxx min size flags
244+ "Compiler cxx min size flags|${CMAKE_CXX_FLAGS_MINSIZEREL} "
245+
246+ # Compiler cxx flags
247+ "Compiler cxx flags|${CMAKE_CXX_FLAGS} "
248+ )
249+
250+ # ---------------------------------------------------------------------------------------------- #
251+
252+ set (buffer "" )
253+
254+ foreach (item IN LISTS info_list)
255+ string (REPLACE "|" ";" parts "${item} " )
256+ list (GET parts 0 label)
257+ list (GET parts 1 value )
258+
259+ list (APPEND buffer "${COLOR_MAGENTA}${label} :${RESTORE} ${value} " )
260+ endforeach ()
261+
262+ # ---------------------------------------------------------------------------------------------- #
263+
264+ # Convert list to a string with newlines...
265+ string (REPLACE ";" "\n " buffer "${buffer} " )
266+
267+ # Attempt to keep the formatting - see details in rsp/output::output()
268+ string (ASCII 13 CR)
269+ set (formatted_output "${CR}${COLOR_BRIGHT_MAGENTA} build info:${RESTORE} \n ${buffer} " )
270+ string (REPLACE "\n " "\n " formatted_output "${formatted_output} " )
271+
272+ # ---------------------------------------------------------------------------------------------- #
273+
274+ # Assign to output variable, if requested and stop any further processing.
275+ if (DEFINED INPUT_OUTPUT)
276+ set ("${INPUT_OUTPUT} " "${formatted_output} " )
277+ return (PROPAGATE "${INPUT_OUTPUT} " )
278+ endif ()
279+
280+ # ---------------------------------------------------------------------------------------------- #
281+
282+ message (${msg_mode} "${formatted_output} " )
283+ endfunction ()
284+ endif ()
0 commit comments