@@ -7,6 +7,8 @@ include_guard(GLOBAL)
77# Debug
88message (VERBOSE "rsp/debug module included" )
99
10+ include ("rsp/output/utils" )
11+
1012if (NOT COMMAND "dump" )
1113
1214 #! dump : Outputs given variables' name and value
@@ -37,4 +39,91 @@ if (NOT COMMAND "dd")
3739 # Output as fatal error to ensure that build stops.
3840 message (FATAL_ERROR " ${CMAKE_CURRENT_FUNCTION} () called from ${CMAKE_CURRENT_LIST_FILE} " )
3941 endfunction ()
40- endif ()
42+ endif ()
43+
44+ if (NOT COMMAND "build_info" )
45+
46+ #! build_info : Output build information to stdout or stderr (Cmake's message type specific)
47+ #
48+ # @see https://cmake.org/cmake/help/latest/command/message.html
49+ #
50+ # @param [<mode>] Option - Cmake's message type. Defaults to NOTICE, when not specified.
51+ # @param [OUTPUT <variable>] Optional - If specified, message is assigned to output variable instead of
52+ # being printed to stdout or stderr.
53+ #
54+ # @return
55+ # [OUTPUT] The resulting output variable, if OUTPUT was specified.
56+ #
57+ function (build_info)
58+ set (options "${RSP_CMAKE_MESSAGE_MODES} " )
59+ set (oneValueArgs OUTPUT )
60+ set (multiValueArgs "" )
61+
62+ cmake_parse_arguments (INPUT "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
63+
64+ # ---------------------------------------------------------------------------------------------- #
65+
66+ # Message mode
67+ resolve_msg_mode("NOTICE" )
68+
69+ # ---------------------------------------------------------------------------------------------- #
70+
71+ set (info_list
72+ # Build Type
73+ # @see https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html
74+ "Type|${CMAKE_BUILD_TYPE} "
75+
76+ # Library Type (NOTE: LIB_TYPE is NOT a predefined cmake variable)
77+ "Library Type|${LIB_TYPE} "
78+
79+ # Compiler flags
80+ "Compiler flags|${CMAKE_CXX_COMPILE_FLAGS} "
81+
82+ # Compiler cxx debug flags
83+ "Compiler cxx debug flags|${CMAKE_CXX_FLAGS_DEBUG} "
84+
85+ # Compiler cxx release flags
86+ "Compiler cxx release flags|${CMAKE_CXX_FLAGS_RELEASE} "
87+
88+ # Compiler cxx min size flags
89+ "Compiler cxx min size flags|${CMAKE_CXX_FLAGS_MINSIZEREL} "
90+
91+ # Compiler cxx flags
92+ "Compiler cxx flags|${CMAKE_CXX_FLAGS} "
93+ )
94+
95+ # ---------------------------------------------------------------------------------------------- #
96+
97+ set (buffer "" )
98+
99+ foreach (item IN LISTS info_list)
100+ string (REPLACE "|" ";" parts "${item} " )
101+ list (GET parts 0 label)
102+ list (GET parts 1 value )
103+
104+ list (APPEND buffer "${COLOR_MAGENTA}${label} :${RESTORE} ${value} " )
105+ endforeach ()
106+
107+ # ---------------------------------------------------------------------------------------------- #
108+
109+ # Convert list to a string with newlines...
110+ string (REPLACE ";" "\n " buffer "${buffer} " )
111+
112+ # Attempt to keep the formatting - see details in rsp/output::output()
113+ string (ASCII 13 CR)
114+ set (formatted_output "${CR}${COLOR_BRIGHT_MAGENTA} build info:${RESTORE} \n ${buffer} " )
115+ string (REPLACE "\n " "\n " formatted_output "${formatted_output} " )
116+
117+ # ---------------------------------------------------------------------------------------------- #
118+
119+ # Assign to output variable, if requested and stop any further processing.
120+ if (DEFINED INPUT_OUTPUT)
121+ set ("${INPUT_OUTPUT} " "${formatted_output} " )
122+ return (PROPAGATE "${INPUT_OUTPUT} " )
123+ endif ()
124+
125+ # ---------------------------------------------------------------------------------------------- #
126+
127+ message (${msg_mode} "${formatted_output} " )
128+ endfunction ()
129+ endif ()
0 commit comments