I have a problem with CMake versions 3.23.1...3.27.7 (I've used the latest available major release on each).
After the configure step is run, cmake -S . -B b -DCMAKE_BUILD_TYPE=Release -G Ninja, the build directory will lack the first (second to last) argument specified in the add_custom_command used to call a COMMAND. If I immedlaly run the same configure lines as above again, then my script will be called with both arguments specified in the CMakeLists.txt file.
Example, file entrylevel/CMakeLists.txt
cmake_minimum_required(VERSION 3.23..3.25)
project(EntryLevelProject
VERSION 0.1.0
DESCRIPTION ""
HOMEPAGE_URL ""
LANGUAGES C CXX ASM
)
add_executable(foo hello.m.cpp)
target_link_libraries(foo
PRIVATE
special::branch
)
add_custom_command(TARGET foo
POST_BUILD
COMMAND
"${CMAKE_CURRENT_SOURCE_DIR}/my_script.sh"
"${SpecialFilesProject_BINARY_DIR}/mango"
"${EntryLevelProject_BINARY_DIR}/apple"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
So in my example the script will only be called with .../my_script.sh .../apple and not .../my_script.sh .../mango .../apple.
Trying a minimal example (like the above) does not produce this error.
Also trying a structure closer the real project files like this:
├── CMakeLists.txt
├── entrylevel
│ ├── CMakeLists.txt
│ ├── hello.m.cpp
│ └── my_script.sh
└── specialfiles
├── CMakeLists.txt
├── inc
│ └── specialbranch.h
├── one.cpp
└── two.cpp
Also does not produce the error. I've also tried to use generator -G "Unix Makefiles" and this gives the same result as with -G Ninja.
So, any ides as to what could be the cause of my problem that I can't reproduce in a simple fashon?
I should add that I'm using the --toolchain options with my cmake invocation but calling it without still has the same problem with lost argument first time cmake is called.