File tree Expand file tree Collapse file tree 4 files changed +76
-1
lines changed
docs/+current/modules/compiler Expand file tree Collapse file tree 4 files changed +76
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010### Added
1111
1212* ` var_dump_all() ` macro in ` debug.cmake ` .
13+ * ` gcc_version() ` function in ` compilers/gcc.cmake ` .
1314
1415### Changed
1516
Original file line number Diff line number Diff line change @@ -191,4 +191,45 @@ if (NOT DEFINED RSP_GCC_STRICT_COMPILE_OPTIONS)
191191 #
192192 #-dD
193193 )
194+ endif ()
195+
196+ if (NOT COMMAND "gcc_version" )
197+
198+ #! gcc_version : Returns the GCC tool version
199+ #
200+ # @param OUTPUT <variable> The variable to assign result to.
201+ #
202+ # @return
203+ # [OUTPUT] GCC version.
204+ #
205+ function (gcc_version)
206+ set (options "" )
207+ set (oneValueArgs OUTPUT )
208+ set (multiValueArgs "" )
209+
210+ cmake_parse_arguments (INPUT "${options} " "${oneValueArgs} " "${multiValueArgs} " ${ARGN} )
211+ requires_arguments("OUTPUT" INPUT )
212+
213+ # ---------------------------------------------------------------------------------------------- #
214+
215+ find_program (GCC_TOOL NAMES g++-latest g++-HEAD g++-14 g++-13 g++-12 g++-11)
216+
217+ execute_process (
218+ COMMAND ${GCC_TOOL} --version
219+ OUTPUT_VARIABLE GCC_TOOL_VERSION
220+ ERROR_VARIABLE GCC_TOOL_VERSION
221+ )
222+
223+ string (REGEX MATCH "[0-9]+(\\ .[0-9]+)+" GCC_TOOL_VERSION "${GCC_TOOL_VERSION} " )
224+
225+ # ---------------------------------------------------------------------------------------------- #
226+
227+ # Set the resulting version
228+ set ("${INPUT_OUTPUT} " "${GCC_TOOL_VERSION} " )
229+
230+ return (
231+ PROPAGATE
232+ "${INPUT_OUTPUT} "
233+ )
234+ endfunction ()
194235endif ()
Original file line number Diff line number Diff line change @@ -36,4 +36,18 @@ set(my_compile_options "${RSP_GCC_STRICT_COMPILE_OPTIONS}")
3636
3737# Modify your preset...
3838list(REMOVE_ITEM my_compile_options "-Wswitch-default")
39- ```
39+ ```
40+
41+ ## ` gcc_version() `
42+
43+ ** Available Since: ` v0.2.0 ` **
44+
45+ Obtains the installed GCC version. The function accepts the following parameters:
46+
47+ * ` OUTPUT ` : _ Output variable to assign the result to._
48+
49+ ``` cmake
50+ gcc_version(OUTPUT version)
51+
52+ message("GCC: ${version}") # 14.2.0
53+ ```
Original file line number Diff line number Diff line change 1+ include ("rsp/testing" )
2+ include ("rsp/compilers/gcc" )
3+
4+ define_test_case(
5+ "GCC Version Test"
6+ LABELS "gcc;version;compilers"
7+ )
8+
9+ # -------------------------------------------------------------------------------------------------------------- #
10+ # Actual tests
11+ # -------------------------------------------------------------------------------------------------------------- #
12+
13+ define_test("can obtain GCC version" "can_obtain_gcc_version" )
14+ function (can_obtain_gcc_version)
15+
16+ gcc_version(OUTPUT version )
17+
18+ assert_string_not_empty("${version} " MESSAGE "GCC version not obtained" )
19+ endfunction ()
You can’t perform that action at this time.
0 commit comments