diff options
| author | Richard Qin <richard.qin.x@gmail.com> | 2026-10-21 08:10:34 +0800 |
|---|---|---|
| committer | Richard Qin <richard.qin.x@gmail.com> | 2026-10-21 08:10:34 +0800 |
| commit | bbfffc8ce49b9afe854f0799513ab6b7891d6dab (patch) | |
| tree | d1b2a1cc8166270764b627960fa193b60e9b3271 /rcc/cmake/modules/GetErrcMessages.cmake | |
| parent | 49de843452f161ee42cb8f4ff4780ccc02ae3a7a (diff) | |
| download | rcc-project-bbfffc8ce49b9afe854f0799513ab6b7891d6dab.tar.gz rcc-project-bbfffc8ce49b9afe854f0799513ab6b7891d6dab.tar.xz | |
[CMake] Add RCC platform configuration checks
Diffstat (limited to 'rcc/cmake/modules/GetErrcMessages.cmake')
| -rw-r--r-- | rcc/cmake/modules/GetErrcMessages.cmake | 45 |
1 files changed, 45 insertions, 0 deletions
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 <cerrno> + #include <iostream> + #include <string> + #include <system_error> + + std::string getMessageFor(int err) { + return std::make_error_code(static_cast<std::errc>(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() |
