Skip to content

Commit f649f3e

Browse files
authored
Adds function for getting enabled languages (#136)
* adds function for getting enabled languages * suggested review changes
1 parent eeed29a commit f649f3e

5 files changed

Lines changed: 90 additions & 1 deletion

File tree

cmake/cmakepp_lang/cmakepp_lang.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ include_guard()
2424
include(cmakepp_lang/algorithm/algorithm)
2525
include(cmakepp_lang/asserts/asserts)
2626
include(cmakepp_lang/class/class)
27+
include(cmakepp_lang/detection/detection)
2728
include(cmakepp_lang/exceptions/exceptions)
2829
include(cmakepp_lang/map/map)
2930
include(cmakepp_lang/object/object)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
#[[[ @module
16+
# Provides functions for detecting the state of CMake and/or the runtime.
17+
#]]
18+
19+
include_guard()
20+
include(cmakepp_lang/detection/languages)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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()

tests/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ FetchContent_Declare(
2020
set(build_testing_old "${BUILD_TESTING}")
2121
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
2222
FetchContent_MakeAvailable(cmake_test)
23+
2324
include(cmake_test/cmake_test)
2425

2526
set(BUILD_TESTING "${build_testing_old}" CACHE BOOL "" FORCE)
2627

27-
2828
ct_add_dir(algorithm)
2929
ct_add_dir(asserts)
3030
ct_add_dir(class)
31+
ct_add_dir(detection)
3132
ct_add_dir(docs)
3233
ct_add_dir(examples)
3334
ct_add_dir(exceptions)

tests/detection/languages.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
ct_add_test(NAME test_cpp_enabled_languages)
2+
function(${test_cpp_enabled_languages})
3+
include(cmakepp_lang/detection/languages)
4+
5+
#cpp_enabled_languages(the_languages)
6+
#set(correct "NONE")
7+
#ct_assert_equal(the_languages "${correct}")
8+
9+
enable_language(C)
10+
cpp_enabled_languages(the_languages)
11+
set(correct "C")
12+
ct_assert_equal(the_languages "${correct}")
13+
14+
enable_language(CXX)
15+
cpp_enabled_languages(the_languages)
16+
set(correct "C" "CXX")
17+
ct_assert_equal(the_languages "${correct}")
18+
endfunction()
19+

0 commit comments

Comments
 (0)