1+ # Copyright 2025 CMakePP
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ include_guard ()
16+ include (cmakepp_lang/utilities/return )
17+
18+ #[[ [
19+ # Wraps the process of retrieving a list of enabled languages.
20+ #
21+ # CMake sets a global property
22+ # :ref:`ENABLED_LANGUAGES <https://cmake.org/cmake/help/latest/prop_gbl/ENABLED_LANGUAGES.html>`
23+ # to be a list of coding
24+ # languages which have been enabled either via
25+ # :ref:`project() <https://cmake.org/cmake/help/latest/command/project.html>` or
26+ # the
27+ # :ref:`enable_language() <https://cmake.org/cmake/help/latest/command/enable_language.html>`
28+ # commands. CMake's documentation is a bit dodgy in
29+ # discussing what variables the aforementioned commands set, so we wrote this
30+ # function as a wrapper around the logic in the event that CMake changes how
31+ # they do things. At the very least, this function should be more user-
32+ # friendly.
33+ #
34+ # :param: return_variable A variable to hold the resulting list.
35+ # :type: list*
36+ #]]
37+ function (cpp_enabled_languages _el_return_variable )
38+ get_property ("${_el_return_variable} " GLOBAL PROPERTY ENABLED_LANGUAGES)
39+
40+ # CMake apparently doesn't remove NONE from the list if other languages are
41+ # also in the list...
42+ list (LENGTH "${_el_return_variable} " _el_length)
43+ if ("${_el_length} " GREATER 1)
44+ list (REMOVE_ITEM "${_el_return_variable} " "NONE" )
45+ endif ()
46+
47+ cpp_return ("${_el_return_variable} " )
48+ endfunction ()
0 commit comments