Confusing error messages when attempting Linux build

What can be going on here?

I have a CMake project which runs flawlessly on Windows, and I’m now trying to get it to build on Linux. To start with, it defines several custom targets (i.e. targets defined with add_custom_target) which later targets depend upon.

On Linux, my whole project configures cleanly, but some odd things happen when I then attempt the build…

My first custom target builds cleanly.

The next one tells me:

CMake Warning:
  No source or binary directory provided.  Both will be assumed to be the
  same as the current working directory, but note that this warning will
  become a fatal error in future CMake releases.

CMake Error: The source directory "/build/name/git/build/solutions/product/debug" does not appear to contain CMakeLists.txt.

What does this mean? The second part of it is particularly confusing, since the directory named is my build directory (i.e. the one specified with -B when I invoked CMake at configuration time), so whyever would it contain a CMakeLists.txt file?

If I actually go to that directory, find the .cmake file that represents the custom target, and invoke it directly using ‘cmake -P’:

cmake -P /build/name/git/build/solutions/product/debug/GENERATED/bisonparse.cmake

…then it runs exactly as it should.

Hi, it’s difficult to say anything without seeing the definition of the custom target(s) in question. Can you perhaps provide an SSCCE of your CMake code?

Thank you. To cut a long story short, even an SSCCE proved to be quite large, but in the process of working through things I’ve found the ‘smoking gun’ that causes the failure.

I mentioned in my original question that I was able to run the .cmake script that represents my custom target correctly if I went to its directory and invoked it, viz.

cmake -P /build/name/git/build/solutions/product/debug/GENERATED/bisonparse.cmake

…but in my actual use case, when I invoke the .cmake script from within an add_custom_target definition, I also need to pass in some additional variables, which I do like this:

add_custom_target(bisonparse ALL
                  COMMAND ${CMAKE_COMMAND} "-DFLAG_NAMES=${PROJECT_FB_FLAG_NAMES}"
                                           "-DFLAGS=${PROJECT_FB_FLAGS}"
                                           -P /build/name/git/apps/product/bisonparse.cmake

It’s those two “-DFLAG…” elements that are the problem. With the custom target defined as above, the code fails to compile. All I need to do is to comment them out:

add_custom_target(bisonparse ALL
                  COMMAND ${CMAKE_COMMAND} #"-DFLAG_NAMES=${PROJECT_FB_FLAG_NAMES}"
                                           #"-DFLAGS=${PROJECT_FB_FLAGS}"
                                           -P /build/name/git/apps/product/bisonparse.cmake

…and the code compiles (though it lacks the functionality that the additional variables provide).

I emphasise that on Windows this all works exactly as intended. It’s only on Linux that this is an issue.

Now that I’ve identified the root cause, I have raised a new, simpler question here.