add_custom_command(POST_BUILD) runs only for one configuration with Ninja Multi-Config
Project:
cmake_minimum_required(VERSION 3.18)
set(CMAKE_CROSS_CONFIGS "all" CACHE STRING "" FORCE)
set(CMAKE_DEFAULT_CONFIGS "all" CACHE STRING "" FORCE)
project(proj CXX)
set(source_file "${CMAKE_CURRENT_BINARY_DIR}/lib.cpp")
file(WRITE "${source_file}" "int main(int argc, char** argv) {return 0;}")
set(CMAKE_DEBUG_POSTFIX "_debug")
add_executable(app "${source_file}")
add_custom_command(
TARGET app
POST_BUILD
COMMAND ${CMAKE_STRIP} -S $<TARGET_FILE:app>
COMMAND ${CMAKE_COMMAND} -E echo "Running custom command"
Configure and output:
$ cmake .. -G'Ninja Multi-Config' -DCMAKE_CONFIGURATION_TYPES='RelWithDebInfo;Debug'
$ ninja -v
[1/4] /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DCMAKE_INTDIR=\"Debug\" -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -MD -MT CMakeFiles/app.dir/Debug/lib.cpp.o -MF CMakeFiles/app.dir/Debug/lib.cpp.o.d -o CMakeFiles/app.dir/Debug/lib.cpp.o -c lib.cpp
[2/4] /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DCMAKE_INTDIR=\"RelWithDebInfo\" -O2 -g -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -MD -MT CMakeFiles/app.dir/RelWithDebInfo/lib.cpp.o -MF CMakeFiles/app.dir/RelWithDebInfo/lib.cpp.o.d -o CMakeFiles/app.dir/RelWithDebInfo/lib.cpp.o -c lib.cpp
[3/4] : && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/app.dir/Debug/lib.cpp.o -o Debug/app && :
[4/4] : && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -O2 -g -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/app.dir/RelWithDebInfo/lib.cpp.o -o RelWithDebInfo/app && cd /Volumes/T3/Dev/projects/cmake/general/nmc_post_build/build && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip -S /Volumes/T3/Dev/projects/cmake/general/nmc_post_build/build/RelWithDebInfo/app && /Users/alex/Dev/cmake/build/bin/cmake -E echo Running\ custom\ command
Running custom command
Note the post build command runs only for the RelWithDebInfo
configuration.
Is the behaviour intended?
Is there a workaround to run the commands for multiple commands on POST_BUILD
?
Does this tie into #12877 (closed) ?