I need to call the findstr Windows command (grep on Linux) from my CMakeList.txt.
If I do this, it is working :
execute_process(
COMMAND findstr "NABO_VERSION " nabo\\nabo.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE FINDSTR_RESULT
ERROR_VARIABLE FINDSTR_ERROR
OUTPUT_VARIABLE FINDSTR_OUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
I get the output:
FINDSTR_ERROR =
FINDSTR_OUT =
#define NABO_VERSION "1.0.7"
#define NABO_VERSION_INT 10007
FINDSTR_RESULT = 0
However, the space at the end of "NABO_VERSION "
is not taken into account. I have to add /c:
before my string.
So I get this following code :
execute_process(
COMMAND findstr /c:"NABO_VERSION " nabo\\nabo.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE FINDSTR_RESULT
ERROR_VARIABLE FINDSTR_ERROR
OUTPUT_VARIABLE FINDSTR_OUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
But now it doesn't work and I get this:
FINDSTR_ERROR =
FINDSTR_OUT =
FINDSTR_RESULT = 1
The command works well in PowerShell or CMD, but not from CMake. I think that CMake modify the command, but in what way ?