Skip to content

CMakeSetCLocale: helper to turn off localization for parsing program output

chuck cranor requested to merge chuck/cmake:setclocale into master

New file Modules/CMakeSetCLocale.cmake provides helper functions to save, clear, and restore localization environment variables for cmake code that wants to parse program output that may normally be localized. For example, when parsing verbose compiler output (e.g. to determine the implicit include directories) if LANG=de_DE the compiler output may be in German rather than English and that may confuse the parser.

To use it: include(${CMAKE_ROOT}/Modules/CMakeSetCLocale.cmake)

cmake_set_c_locale(save)    # saves old ENV values in ${save_*}
  execute_process(...)      # or maybe try_compile()
cmake_restore_locale(save)  # restores old ENV values

Tests for CMakeSetCLocale are in Tests/RunCMake/SetCLocale/SetCLocale.cmake

For further info, see discussion the related discussion with Alexander Grund in merge request !2716 (merged) ...

Merge request reports