# Possible issue with BUILD\_INTERFACE

**URL:** <https://discourse.cmake.org/t/possible-issue-with-build-interface/659>\
**Category:** Code\
**Created:** [February 20, 2020, 8:32am UTC](https://discourse.cmake.org/t/possible-issue-with-build-interface/659 "2020-02-20T08:32:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![apaolillo](https://discourse.cmake.org/user_avatar/discourse.cmake.org/apaolillo/32/373_2.png) [@apaolillo](https://discourse.cmake.org/u/apaolillo)\
**Post date:** [February 20, 2020, 8:32am UTC](https://discourse.cmake.org/t/possible-issue-with-build-interface/659/1 "2020-02-20T08:32:49Z")

</div>

Hello dear CMake community,

I’m very new to this forum, so I don’t really know if this is the right place to post such a message.

I may have accidentally found an issue in CMake, so I’ll post it here in order to discuss with more experienced user.

My setup is a x86\_64 machine with Ubuntu 18.04, I reproduced the issue on both CMake 3.10.2 and 3.15.3.  
It looks like when using several paths in the BUILD\_INTERFACE macro, CMake is adding an extra absolute path (pointing to the root of the cmake application source directory).

Using this syntax, and installing & exporting the `testlib` target creates the faulty path:

```auto
target_include_directories(testlib
    PUBLIC
        $<BUILD_INTERFACE:
            ${CMAKE_SOURCE_DIR}/include1
            ${CMAKE_SOURCE_DIR}/include2
        >
        $<INSTALL_INTERFACE:include2>
    PRIVATE
        include
)

```

While the following does not:

```auto
target_include_directories(testlib
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include1>
        $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include2>
        $<INSTALL_INTERFACE:include2>
    PRIVATE
        include
)

```

It may also be me using the wrong syntax, but in any case I found that this extra path should not be added.  
I created a repository on github to reproduce the issue with a minimal working example:

> **[apaolillo/misc](https://github.com/apaolillo/misc/tree/master/cmake/builditf-issue)**
>
> Miscellaneous piece of code. Contribute to apaolillo/misc development by creating an account on GitHub.

  
More information are available in the readme file.

Thank you in advance,  
Kind regards,  
Antonio

---

<div class="post-metadata">

**Author:** ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)\
**Post date:** [February 21, 2020, 11:40am UTC](https://discourse.cmake.org/t/possible-issue-with-build-interface/659/2 "2020-02-21T11:40:24Z")

</div>

`$<BUILD_INTERFACE:...>` expects a list as argument. For that purpose, use a`;` as separator of the arguments or, better, use genex `$<SEMICOLON>`. So the correct expression is:

```cmake
target_include_directories(testlib
    PUBLIC
        $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include1$<SEMICOLON>${CMAKE_SOURCE_DIR}/include2>
        $<INSTALL_INTERFACE:include2>
    PRIVATE
        include
)

```

---

<div class="post-metadata">

**Author:** ![apaolillo](https://discourse.cmake.org/user_avatar/discourse.cmake.org/apaolillo/32/373_2.png) [@apaolillo](https://discourse.cmake.org/u/apaolillo)\
**Post date:** [February 21, 2020, 12:02pm UTC](https://discourse.cmake.org/t/possible-issue-with-build-interface/659/3 "2020-02-21T12:02:07Z")

</div>

Thank you for your response.  
Any idea why this absolute path is inserted?

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [February 22, 2020, 1:09am UTC](https://discourse.cmake.org/t/possible-issue-with-build-interface/659/4 "2020-02-22T01:09:54Z")

</div>

The problem is that you split the generator expression across multiple lines, which creates whitespace that CMake then interprets as a separator between arguments. What CMake sees is the following four separate arguments, not a single argument with a valid generator expression:

```auto
"$<BUILD_INTERFACE:"
"${CMAKE_SOURCE_DIR}/include1"
"${CMAKE_SOURCE_DIR}/include2"
">"

```

Unfortunately, CMake doesn’t warn when an argument looks like the beginning of a generator expression but is not in fact a valid generator expression (i.e. it is missing the closing `>`).

---

<div class="post-metadata">

**Author:** ![apaolillo](https://discourse.cmake.org/user_avatar/discourse.cmake.org/apaolillo/32/373_2.png) [@apaolillo](https://discourse.cmake.org/u/apaolillo)\
**Post date:** [February 24, 2020, 8:48pm UTC](https://discourse.cmake.org/t/possible-issue-with-build-interface/659/5 "2020-02-24T20:48:42Z")

</div>

thank you very much for the clarifications!
