diff --git a/cmake/cmakepp_lang/cmakepp_lang.cmake b/cmake/cmakepp_lang/cmakepp_lang.cmake index 9741c8d..c7dbb85 100644 --- a/cmake/cmakepp_lang/cmakepp_lang.cmake +++ b/cmake/cmakepp_lang/cmakepp_lang.cmake @@ -24,6 +24,7 @@ include_guard() include(cmakepp_lang/algorithm/algorithm) include(cmakepp_lang/asserts/asserts) include(cmakepp_lang/class/class) +include(cmakepp_lang/detection/detection) include(cmakepp_lang/exceptions/exceptions) include(cmakepp_lang/map/map) include(cmakepp_lang/object/object) diff --git a/cmake/cmakepp_lang/detection/detection.cmake b/cmake/cmakepp_lang/detection/detection.cmake new file mode 100644 index 0000000..eb1b242 --- /dev/null +++ b/cmake/cmakepp_lang/detection/detection.cmake @@ -0,0 +1,20 @@ +# Copyright 2025 CMakePP +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#[[[ @module +# Provides functions for detecting the state of CMake and/or the runtime. +#]] + +include_guard() +include(cmakepp_lang/detection/languages) \ No newline at end of file diff --git a/cmake/cmakepp_lang/detection/languages.cmake b/cmake/cmakepp_lang/detection/languages.cmake new file mode 100644 index 0000000..0e9f81f --- /dev/null +++ b/cmake/cmakepp_lang/detection/languages.cmake @@ -0,0 +1,48 @@ +# Copyright 2025 CMakePP +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +include_guard() +include(cmakepp_lang/utilities/return) + +#[[[ +# Wraps the process of retrieving a list of enabled languages. +# +# CMake sets a global property +# :ref:`ENABLED_LANGUAGES ` +# to be a list of coding +# languages which have been enabled either via +# :ref:`project() ` or +# the +# :ref:`enable_language() ` +# commands. CMake's documentation is a bit dodgy in +# discussing what variables the aforementioned commands set, so we wrote this +# function as a wrapper around the logic in the event that CMake changes how +# they do things. At the very least, this function should be more user- +# friendly. +# +# :param: return_variable A variable to hold the resulting list. +# :type: list* +#]] +function(cpp_enabled_languages _el_return_variable) + get_property("${_el_return_variable}" GLOBAL PROPERTY ENABLED_LANGUAGES) + + # CMake apparently doesn't remove NONE from the list if other languages are + # also in the list... + list(LENGTH "${_el_return_variable}" _el_length) + if("${_el_length}" GREATER 1) + list(REMOVE_ITEM "${_el_return_variable}" "NONE") + endif() + + cpp_return("${_el_return_variable}") +endfunction() \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 19dbd68..851b741 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -20,14 +20,15 @@ FetchContent_Declare( set(build_testing_old "${BUILD_TESTING}") set(BUILD_TESTING OFF CACHE BOOL "" FORCE) FetchContent_MakeAvailable(cmake_test) + include(cmake_test/cmake_test) set(BUILD_TESTING "${build_testing_old}" CACHE BOOL "" FORCE) - ct_add_dir(algorithm) ct_add_dir(asserts) ct_add_dir(class) +ct_add_dir(detection) ct_add_dir(docs) ct_add_dir(examples) ct_add_dir(exceptions) diff --git a/tests/detection/languages.cmake b/tests/detection/languages.cmake new file mode 100644 index 0000000..8445005 --- /dev/null +++ b/tests/detection/languages.cmake @@ -0,0 +1,19 @@ +ct_add_test(NAME test_cpp_enabled_languages) +function(${test_cpp_enabled_languages}) + include(cmakepp_lang/detection/languages) + + #cpp_enabled_languages(the_languages) + #set(correct "NONE") + #ct_assert_equal(the_languages "${correct}") + + enable_language(C) + cpp_enabled_languages(the_languages) + set(correct "C") + ct_assert_equal(the_languages "${correct}") + + enable_language(CXX) + cpp_enabled_languages(the_languages) + set(correct "C" "CXX") + ct_assert_equal(the_languages "${correct}") +endfunction() +