From bbfffc8ce49b9afe854f0799513ab6b7891d6dab Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Wed, 21 Oct 2026 08:10:34 +0800 Subject: [CMake] Add RCC platform configuration checks --- rcc/cmake/modules/GetErrcMessages.cmake | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 rcc/cmake/modules/GetErrcMessages.cmake (limited to 'rcc/cmake/modules/GetErrcMessages.cmake') diff --git a/rcc/cmake/modules/GetErrcMessages.cmake b/rcc/cmake/modules/GetErrcMessages.cmake new file mode 100644 index 0000000..ad94f6a --- /dev/null +++ b/rcc/cmake/modules/GetErrcMessages.cmake @@ -0,0 +1,45 @@ +# This function returns the messages of various POSIX error codes as they are returned by std::error_code. +# The purpose of this function is to supply those error messages to rcc-lit using the errc_messages config. +# Currently supplied and needed error codes: ENOENT, EISDIR, EINVAL and EACCES. +# Messages are semi colon separated. +# Keep amount, order and tested error codes in sync with rcc/utils/lit/lit/rcc/config.py. +function(get_errc_messages outvar) + if(CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR AND NOT DEFINED errc_exit_code) + set(${outvar} "" PARENT_SCOPE) + message(STATUS "Can't get errc messages in cross-compilation mode") + return() + endif() + + set(errc_test_code ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/getErrc.cpp) + + file(WRITE ${errc_test_code} " + #include + #include + #include + #include + + std::string getMessageFor(int err) { + return std::make_error_code(static_cast(err)).message(); + } + + int main() { + std::cout << getMessageFor(ENOENT) << ';' << getMessageFor(EISDIR); + std::cout << ';' << getMessageFor(EINVAL) << ';' << getMessageFor(EACCES); + return 0; + } + ") + + try_run(errc_exit_code + errc_compiled + ${CMAKE_BINARY_DIR} + ${errc_test_code} + RUN_OUTPUT_VARIABLE errc_result + COMPILE_OUTPUT_VARIABLE errc_compile_errors) + if (errc_compiled AND "${errc_exit_code}" STREQUAL "0") + set(${outvar} ${errc_result} PARENT_SCOPE) + else() + set(${outvar} "" PARENT_SCOPE) + message(NOTICE "${errc_compile_errors}") + message(STATUS "Failed to get errc messages") + endif () +endfunction() -- cgit v1.2.3