We are trying to improve the makefiles produced by CMake. For Clang, GCC and ICC, we want to add -march=native
. The block to do so looks like:
#
Adding dollar sign and curly braces, ${UNAME_MACHINE}, results in the same original problem (the newline is still present).
If you use curly braces you also need quote marks. EG:
string(STRIP "${UNAME_MACHINE}" UNAME_MACHINE)
This strips terminating newline in the variable <varname>:
string(REGEX REPLACE "\n$" "" <varname> "${<varname>}")
Works for one of the project I involved to since CMake 2.8.
execute_process
has a flag for stripping trailing whitespace on either standard out or standard error (or both)
[OUTPUT_STRIP_TRAILING_WHITESPACE]
[ERROR_STRIP_TRAILING_WHITESPACE]
https://cmake.org/cmake/help/v3.0/command/execute_process.html
You can also use CMake's string STRIP command which will remove leading and trailing spaces (and the trailing newline).
string(STRIP <string> <output variable>)