# Need to find/replace all #include with new path which doesn't fit with old path

**URL:** https://discourse.cmake.org/t/need-to-find-replace-all-include-with-new-path-which-doesnt-fit-with-old-path/2661
**Category:** Usage
**Created:** [January 30, 2021, 9:25pm UTC](https://discourse.cmake.org/t/need-to-find-replace-all-include-with-new-path-which-doesnt-fit-with-old-path/2661 "2021-01-30T21:25:34Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![al-sabr](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/ec9cab/32.png) [@al-sabr](https://discourse.cmake.org/u/al-sabr)
#### Post date: [January 30, 2021, 9:25pm UTC](https://discourse.cmake.org/t/need-to-find-replace-all-include-with-new-path-which-doesnt-fit-with-old-path/2661/1 "2021-01-30T21:25:34Z")

</div>

Hi I am having a problem… I took 2 external projects in another project which compile without any problem. The only problem in my code is that the old #include which are in thousands are not working anymore. I give an example:

This is the old #include style and it cannot be found the way KWSys and VNL are actually compiled and recognized by VS2019.

# include \<vcl\_msvc\_warnings.h\>

it is recognized only when replaced by

# include \<src/vxl/vcl/vcl\_msvc\_warnings.h\>

#include “itksys/SystemTools.hxx”

it is recognized only when replaced by

#include “src/itksys/SystemTools.hxx”

I don’t want to find and replace all the files so that it can compile…  
How can I fix this bug? Did I forgot something in CMake like a command?

---

<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: [January 31, 2021, 3:03pm UTC](https://discourse.cmake.org/t/need-to-find-replace-all-include-with-new-path-which-doesnt-fit-with-old-path/2661/2 "2021-01-31T15:03:03Z")

</div>

It sounds like either some imported targets are missing interface include directories or you forgot a `target_include_directories()` with some variable from the project.

Cc: @jcfr

---

<div class="post-metadata">

### Author: ![al-sabr](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/ec9cab/32.png) [@al-sabr](https://discourse.cmake.org/u/al-sabr)
#### Post date: [January 31, 2021, 3:12pm UTC](https://discourse.cmake.org/t/need-to-find-replace-all-include-with-new-path-which-doesnt-fit-with-old-path/2661/3 "2021-01-31T15:12:56Z")

</div>

Can you elaborate more about what you said. I kind a not understanding what are interface include directories or target\_include\_directories…

Here are the CMakeLists.txt files I am talking about :

> <https://github.com/al-sabr/CTK/blob/ctk-blueberry-port-from-mitk/External/KWSys/CMakeLists.txt>

> <https://github.com/al-sabr/CTK/blob/ctk-blueberry-port-from-mitk/External/KWSys/src/CMakeLists.txt>

---

<div class="post-metadata">

### Author: ![al-sabr](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/ec9cab/32.png) [@al-sabr](https://discourse.cmake.org/u/al-sabr)
#### Post date: [January 31, 2021, 3:27pm UTC](https://discourse.cmake.org/t/need-to-find-replace-all-include-with-new-path-which-doesnt-fit-with-old-path/2661/4 "2021-01-31T15:27:15Z")

</div>

Also this project:

> <https://github.com/al-sabr/CTK/blob/ctk-blueberry-port-from-mitk/External/VNL/CMakeLists.txt>

These are not in my project but are required by my project.

This is the sub-library which is using the 2 former external projects…

> <https://github.com/al-sabr/CTK/blob/ctk-blueberry-port-from-mitk/Libs/mbilog/target_libraries.cmake>

---

<div class="post-metadata">

### Author: ![al-sabr](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/ec9cab/32.png) [@al-sabr](https://discourse.cmake.org/u/al-sabr)
#### Post date: [January 31, 2021, 3:52pm UTC](https://discourse.cmake.org/t/need-to-find-replace-all-include-with-new-path-which-doesnt-fit-with-old-path/2661/5 "2021-01-31T15:52:25Z")

</div>

Here is the compilation log which shows clearly that many sub-targets are created by CMake and that’s why the #include paths have to be all changed…

> **[1\>------ Rebuild All started: Project: ZERO\_CHECK, Configuration: Debug...](https://pastebin.com/e7kraahr)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dzenanz/32/83_2.png) [@dzenanz](https://discourse.cmake.org/u/dzenanz)
#### Post date: [February 1, 2021, 4:55pm UTC](https://discourse.cmake.org/t/need-to-find-replace-all-include-with-new-path-which-doesnt-fit-with-old-path/2661/6 "2021-02-01T16:55:30Z")

</div>

I don’t think your approach can work. If you only put part of ITK (part you need) into a [folder in your project](https://github.com/al-sabr/CTK/tree/ctk-blueberry-port-from-mitk/Libs/mbilog), there are always going to be some compile errors. To make that work, you would need to significantly alter ITK, which is harder to do than to properly incorporate it via [ExternalProject\_Add](https://cmake.org/cmake/help/latest/module/ExternalProject.html) or some other common mechanism.

---

<div class="post-metadata">

### Author: ![al-sabr](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/ec9cab/32.png) [@al-sabr](https://discourse.cmake.org/u/al-sabr)
#### Post date: [February 1, 2021, 5:00pm UTC](https://discourse.cmake.org/t/need-to-find-replace-all-include-with-new-path-which-doesnt-fit-with-old-path/2661/7 "2021-02-01T17:00:45Z")

</div>

Actually if you look at this folder I was able to extract all the features (which are minimal from ITK) and was able to make almost a full compilation.

> **[al-sabr/CTK](https://github.com/al-sabr/CTK/tree/ctk-blueberry-port-from-mitk/Libs/mbilog)**
>
> A set of common support code for medical imaging, surgical navigation, and related purposes. - al-sabr/CTK

You think that it is not possible? I think my approach is better to learn which part to modularize instead of making things monolith… what do you think?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.cmake.org/user_avatar/discourse.cmake.org/dzenanz/32/83_2.png) [@dzenanz](https://discourse.cmake.org/u/dzenanz)
#### Post date: [February 1, 2021, 5:05pm UTC](https://discourse.cmake.org/t/need-to-find-replace-all-include-with-new-path-which-doesnt-fit-with-old-path/2661/8 "2021-02-01T17:05:50Z")

</div>

As ITK incorporates KWSys as part of its source code, `include`'s reflect that in the path. If you don’t put KWSys in the same relative path that ITK expects, than you will most likely need to edit those files to put a different path, or no path, depending on what you set as `include_directories` in CMake code.

---

<div class="post-metadata">

### Author: ![al-sabr](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/ec9cab/32.png) [@al-sabr](https://discourse.cmake.org/u/al-sabr)
#### Post date: [February 1, 2021, 5:22pm UTC](https://discourse.cmake.org/t/need-to-find-replace-all-include-with-new-path-which-doesnt-fit-with-old-path/2661/9 "2021-02-01T17:22:20Z")

</div>

As you can see the output of folder structure is the following:

 ![image](https://discourse.cmake.org/uploads/default/original/2X/4/44fdab1f41f2a117f6ccfd925f5b3774f2e26a78.png)

How come that ITK gets the same output but can use simply the #includes and not me?

I would not like to use this kind of file path **#include “src/itksys/SystemTools.hxx”**  
How can I remove the src and all the other subfolders in a more elegant way? It is worst with VNL which is **#include \<src/vxl/vcl/vcl\_msvc\_warnings.h\>**

I am not as expert as you in CMake that’s why I don’t know which direction I could go to bypass the default folder structure.
