Broken build.ninja on FreeBSD

Hi guys,

I compiled CMake (cloned from GitLab) on FreeBSD-12.1-RELEASE and got a broken ninja file. Here is the CMakeLists.txt:

cmake_minimum_required(VERSION 3.16)
project(NinjaOmitLocalOutputTest)
add_library(foo foo.cpp)

The command cmake -G ninja --debug-trycompile produces the following output:

debug trycompile on
-- The C compiler identification is Clang 8.0.1
-- The CXX compiler identification is Clang 8.0.1
-- Detecting C compiler ABI info
CMake Error:
  Running

   '/home/hsebert/local/bin/ninja' '-C' '/usr/home/hsebert/Documents/cmake_test/build.broken/CMakeFiles/CMakeTmp' '-t' 'cleandead'

  failed with:

   ninja: error: build.ninja:120: unknown target 'all'

  default all

             ^ near here
<snip>

Looking into the respective build.ninja file, I found this:

#############################################
# Folder: /home/hsebert/Documents/cmake_test/build.broken/CMakeFiles/CMakeTmp

build /home/hsebert/Documents/cmake_test/build.broken/CMakeFiles/CMakeTmp/all: phony /home/hsebert/Documents/cmake_test/build.broken/CMakeFiles/CMakeTmp/cmTC_91198

which should rather be (I suppose)

#############################################
# Folder: /home/hsebert/Documents/cmake_test/build.broken/CMakeFiles/CMakeTmp

build all: phony /home/hsebert/Documents/cmake_test/build.broken/CMakeFiles/CMakeTmp/cmTC_91198

(without the path before all).

What do you think?

Looks to me like a problem with your home directory being symlinked (/home -> /usr/home.) This line in particular is interesting:

'/home/hsebert/local/bin/ninja' '-C' '/usr/home/hsebert/Documents/cmake_test/build.broken/CMakeFiles/CMakeTmp' '-t' 'cleandead'

In most cases, CMake preserves symlinks, but for the try-compile it seems to be going into the real path.

@brad.king @ben.boeckel any ideas?

Please open an issue at https://gitlab.kitware.com/cmake/cmake/-/issues.

@kyle.edwards The problem also occurs when omitting the --debug-trycompile option.

I see CMake Issue 20900, thanks.