aboutsummaryrefslogtreecommitdiff
path: root/rcc/cmake/modules/GetErrcMessages.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'rcc/cmake/modules/GetErrcMessages.cmake')
-rw-r--r--rcc/cmake/modules/GetErrcMessages.cmake45
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()