Makefiles: Odd behavior with rebuild_cache attached to stdout
Consider the following CMakeLists.txt:
$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
project(p)
execute_process(COMMAND ${CMAKE_COMMAND}
-P ${CMAKE_CURRENT_SOURCE_DIR}/demo.cmake
ERROR_VARIABLE my_VERSION)
message("1: ${my_VERSION}")
string(REPLACE "." ";" my_VERSION_LIST "${my_VERSION}")
list(GET my_VERSION_LIST 0 my_VERSION_MAJOR)
list(GET my_VERSION_LIST 1 my_VERSION_MINOR)
list(GET my_VERSION_LIST 2 my_VERSION_PATCH)
message("2: ${my_VERSION_MAJOR}")
where:
$ cat demo.cmake
set(GIT_VERSION 1.2.3)
message("${GIT_VERSION}")
Here is what I see from my Ubuntu system:
$ cmake .. && echo "-- done ---" && make rebuild_cache
1: 1.2.3
2: 1
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/demo/bin
-- done ---
Running CMake to regenerate build system...
1: 1.2.3
CMake Error at CMakeLists.txt:9 (list):
list index: 1 out of range (-1, 0)
CMake Error at CMakeLists.txt:10 (list):
list index: 2 out of range (-1, 0)
2: 1;2;3
-- Configuring incomplete, errors occurred!
See also "/tmp/demo/bin/CMakeFiles/CMakeOutput.log".
make: *** [Makefile:81: rebuild_cache] Error 1
However using a file output:
$ cmake .. && echo "-- done ---" && make rebuild_cache >& /tmp/my.log && echo "this time ok"
1: 1.2.3
2: 1
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/demo/bin
-- done ---
this time ok
Using:
$ cmake --version
cmake version 3.22.1
CMake suite maintained and supported by Kitware (kitware.com/cmake).
and
$ make --version
GNU Make 4.3
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Edited by Mathieu Malaterre