# Confusing error messages when attempting Linux build

**URL:** https://discourse.cmake.org/t/confusing-error-messages-when-attempting-linux-build/9869
**Category:** Usage
**Created:** [January 17, 2024, 2:48pm UTC](https://discourse.cmake.org/t/confusing-error-messages-when-attempting-linux-build/9869 "2024-01-17T14:48:35Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![EosPengwern](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eospengwern/32/3904_2.png) [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)
#### Post date: [January 17, 2024, 2:48pm UTC](https://discourse.cmake.org/t/confusing-error-messages-when-attempting-linux-build/9869/1 "2024-01-17T14:48:35Z")

</div>

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:

```auto
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’:

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

```

…then it runs exactly as it should.

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [January 17, 2024, 3:07pm UTC](https://discourse.cmake.org/t/confusing-error-messages-when-attempting-linux-build/9869/2 "2024-01-17T15:07:25Z")

</div>

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

---

<div class="post-metadata">

### Author: ![EosPengwern](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eospengwern/32/3904_2.png) [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)
#### Post date: [January 25, 2024, 5:44pm UTC](https://discourse.cmake.org/t/confusing-error-messages-when-attempting-linux-build/9869/3 "2024-01-25T17:44:14Z")

</div>

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.

```auto
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:

```auto
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:

```auto
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.

---

<div class="post-metadata">

### Author: ![EosPengwern](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eospengwern/32/3904_2.png) [@EosPengwern](https://discourse.cmake.org/u/EosPengwern)
#### Post date: [January 27, 2024, 2:31pm UTC](https://discourse.cmake.org/t/confusing-error-messages-when-attempting-linux-build/9869/4 "2024-01-27T14:31:12Z")

</div>

Now that I’ve identified the root cause, I have raised a new, simpler question [here](https://discourse.cmake.org/t/build-failure-in-linux-when-passing-flags-in-add-custom-target/9948).
