# How to remove BASE\_DIRS of FILE\_SET from INTERFACE\_INCLUDE\_DIRECTORIES property

**URL:** https://discourse.cmake.org/t/how-to-remove-base-dirs-of-file-set-from-interface-include-directories-property/6505
**Category:** Usage
**Created:** [September 19, 2022, 10:00am UTC](https://discourse.cmake.org/t/how-to-remove-base-dirs-of-file-set-from-interface-include-directories-property/6505 "2022-09-19T10:00:57Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Pei\_Wang](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pei_wang/32/2777_2.png) [@Pei\_Wang](https://discourse.cmake.org/u/Pei_Wang)
#### Post date: [September 19, 2022, 10:00am UTC](https://discourse.cmake.org/t/how-to-remove-base-dirs-of-file-set-from-interface-include-directories-property/6505/1 "2022-09-19T10:00:57Z")

</div>

I’m using CMake 3.23.0 to enjoy the FILE\_SET feature.

However, I don’t want to add BASE\_DIRS of FILE\_SET into INTERFACE\_INCLUDE\_DIRECTORIES property.

I can remove it from BUILD\_INTERFACE, but how to remove from INSTALL\_INTERFACE?

```auto
add_library(Math SHARED)
file(GLOB_RECURSE MathHeader ${MathRoot}/*.h ${MathRoot}/*.hpp)
target_sources(Math INTERFACE FILE_SET HEADERS FILES ${MathHeader})

# it's ok for me , to remove the BASE_DIRS from INTERFACE_INCLUDE_DIRECTORIES under this scope
# Remove the relative FILE_SET HEADERS BASE_DIRS from INTERFACE_INCLUDE_DIRECTORIES property
get_target_property(include_dirs Math INTERFACE_INCLUDE_DIRECTORIES)
list(REMOVE_ITEM include_dirs "$<BUILD_INTERFACE:${MathRoot}>")
set_target_properties(Math PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${include_dirs}")

# but, how to remove BASE_DIRS from INTERFACE_INCLUDE_DIRECTORIES property of EXPORT install target?

install(TARGETS Math
EXPORT MathTargets
RUNTIME DESTINATION bin # Executables & DLLs 
LIBRARY DESTINATION lib # Shared libraries, except DLLs
ARCHIVE DESTINATION lib # DLL import libraries & Static libraries .lib
FILE_SET HEADERS DESTINATION math/# FILE_SET
)

```

after installing Math target (install with EXPORT), I will get an automatically generated MathTargets.cmake file which contains this statements:

```auto
if(NOT CMAKE_VERSION VERSION_LESS "3.23.0")
  target_sources(Math
    INTERFACE
      FILE_SET "HEADERS"
      TYPE "HEADERS"
      BASE_DIRS "${_IMPORT_PREFIX}/xx/math"
      FILES "${_IMPORT_PREFIX}/xx/math/Common.h" "${_IMPORT_PREFIX}/xx/math/Constants.h" "${_IMPORT_PREFIX}/xx/math/Operator.h" 
  )
endif()

```

then linking Math will bring the BASE\_DIRS into INTERFACE\_INCLUDE\_DIRECTORIES property.

How to remove BASE\_DIRS from INTERFACE\_INCLUDE\_DIRECTORIES property?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 28, 2022, 6:20pm UTC](https://discourse.cmake.org/t/how-to-remove-base-dirs-of-file-set-from-interface-include-directories-property/6505/2 "2022-09-28T18:20:25Z")

</div>

What if you use `PRIVATE` instead of `INTERFACE` for the visibility of the header sources?

---

<div class="post-metadata">

### Author: ![Pei\_Wang](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pei_wang/32/2777_2.png) [@Pei\_Wang](https://discourse.cmake.org/u/Pei_Wang)
#### Post date: [October 8, 2022, 5:17am UTC](https://discourse.cmake.org/t/how-to-remove-base-dirs-of-file-set-from-interface-include-directories-property/6505/3 "2022-10-08T05:17:14Z")

</div>

Thanks for your reply.

It works for me after changing INTERFACE to PRIVATE

---

<div class="post-metadata">

### Author: ![Pei\_Wang](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pei_wang/32/2777_2.png) [@Pei\_Wang](https://discourse.cmake.org/u/Pei_Wang)
#### Post date: [October 10, 2022, 10:02am UTC](https://discourse.cmake.org/t/how-to-remove-base-dirs-of-file-set-from-interface-include-directories-property/6505/5 "2022-10-10T10:02:29Z")

</div>

Actually, the header files would not be installed if I set the FILE\_SET as PRIVATE.

So, If I want to install the FILE\_SET and not to add BASE\_DIRS into INTERFACE\_INCLUDE\_DIRECTORIES.

How to achieve this goal?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 10, 2022, 1:20pm UTC](https://discourse.cmake.org/t/how-to-remove-base-dirs-of-file-set-from-interface-include-directories-property/6505/6 "2022-10-10T13:20:10Z")

</div>

Non-`PRIVATE` `FILE_SET`s will add their `BASE_DIRS` to the interface include directories. It’s how they work. I guess let’s back up: why do you not want this include interface?

---

<div class="post-metadata">

### Author: ![Pei\_Wang](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pei_wang/32/2777_2.png) [@Pei\_Wang](https://discourse.cmake.org/u/Pei_Wang)
#### Post date: [October 12, 2022, 5:30am UTC](https://discourse.cmake.org/t/how-to-remove-base-dirs-of-file-set-from-interface-include-directories-property/6505/7 "2022-10-12T05:30:54Z")

</div>

Ok. Let me explain this by more details.

I have two folders like these:

> projectRoot/math/extension/  
> Common.h  
> Math.h
> 
> * * *
> 
> projectRoot/solver/extension/  
> Common.h  
> Solver.h
> 
> * * *

Actually, if I want to explicitly include math/Common.h, I have to write like this:

```auto
#include "math/extension/Common.h"

```

Otherwise, it would bring ambiguity into my project if I have the “math/extension” and “solver/extension/” in INCLUDE\_DIRECTORIES.

For example, the math library will be integrated by other host project, which contains it own Common.h.  
Some of the host’s project might have this:

```auto
#include "Common.h"

```

If the Math library contains “math/extension” and “solver/extension/” in INCLUDE\_DIRECTORIES.

Compiler will complain \<#include “Common.h”: Common.h is ambiguous path. math/extension/Common.h or solver/extension/Common.h ?\>

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [October 12, 2022, 1:15pm UTC](https://discourse.cmake.org/t/how-to-remove-base-dirs-of-file-set-from-interface-include-directories-property/6505/8 "2022-10-12T13:15:17Z")

</div>

I think what you want here is the `BASE_DIRS` to be high up so that the file’s paths relative to it are `math/common/Math.h` and the like.

---

<div class="post-metadata">

### Author: ![Pei\_Wang](https://discourse.cmake.org/user_avatar/discourse.cmake.org/pei_wang/32/2777_2.png) [@Pei\_Wang](https://discourse.cmake.org/u/Pei_Wang)
#### Post date: [October 18, 2022, 6:37am UTC](https://discourse.cmake.org/t/how-to-remove-base-dirs-of-file-set-from-interface-include-directories-property/6505/9 "2022-10-18T06:37:39Z")

</div>

Thanks for your help.

After setting the BASE\_DIR to be the higher folder path, the FILE\_SET relative paths does NOT change.

It does NOT work for me.

---

<div class="post-metadata">

### Author: ![Hilton\_Marques\_Santa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hilton_marques_santa/32/4447_2.png) [@Hilton\_Marques\_Santa](https://discourse.cmake.org/u/Hilton_Marques_Santa)
#### Post date: [March 28, 2024, 12:12pm UTC](https://discourse.cmake.org/t/how-to-remove-base-dirs-of-file-set-from-interface-include-directories-property/6505/10 "2024-03-28T12:12:12Z")

</div>

Hi, could you solve this? I am facing the same problem

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [March 29, 2024, 12:15pm UTC](https://discourse.cmake.org/t/how-to-remove-base-dirs-of-file-set-from-interface-include-directories-property/6505/11 "2024-03-29T12:15:02Z")

</div>

Posting a complete example that demonstrates the problem would help.
