Skip to content

add_custom_command: keep empty arguments when expanding list arguments.

This fixes a crash in case the command is (or, in case of the presence of generator expressions) evaluates to the empty string while COMMAND_EXPAND_LISTS is provided.

To reproduce the crash, consider the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.9)

project(test CXX)

if(NOT EXISTS foo.cpp)
  file(WRITE foo.cpp "")
endif()

add_library(foo STATIC foo.cpp)
add_custom_command(
  # In real life, the empty string on the next line would be a generator expression that evaluates to the empty string for some configurations.
  TARGET foo POST_BUILD COMMAND ""
  COMMAND_EXPAND_LISTS
  )

Next, configure using a single-configuration generator (e.g., "Unix Makefiles" on Linux or 'NMake Makefiles" on Windows). This will crash with a segmentation fault during the generation phase. It seems that the "Visual Studio" generator does not have this problem.

Merge request reports

Loading