# how to generate ITK\_INCLUDE\_DIRS when packaging myself module?

**URL:** https://discourse.cmake.org/t/how-to-generate-itk-include-dirs-when-packaging-myself-module/5865
**Category:** Code
**Created:** [June 14, 2022, 10:18am UTC](https://discourse.cmake.org/t/how-to-generate-itk-include-dirs-when-packaging-myself-module/5865 "2022-06-14T10:18:58Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [June 14, 2022, 10:18am UTC](https://discourse.cmake.org/t/how-to-generate-itk-include-dirs-when-packaging-myself-module/5865/1 "2022-06-14T10:18:58Z")

</div>

I am packaging myself module by cmake.

My CMakeLists.txt is:

```auto

install( TARGETS pA pB
	EXPORT SustaoBasic
	RUNTIME DESTINATION bin
	LIBRARY DESTINATION lib
	ARCHIVE DESTINATION lib
)

install(DIRECTORY package/ DESTINATION include
	FILES_MATCHING PATTERN "*.h"
)

install(EXPORT SustaoBasic
	FILE SustaoBasic.cmake
	NAMESPACE SustaoBasic::
	DESTINATION lib/cmake
)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
	SustaoBasicConfigVersion.cmake
	VERSION V1.0
	COMPATIBILITY AnyNewerVersion # 表示该函数库向下兼容
)

configure_package_config_file(
	SustaoBasicConfig.cmake.in ${PROJECT_BINARY_DIR}/SustaoBasicConfig.cmake
	INSTALL_DESTINATION lib/cmake
)

install(FILES "${PROJECT_BINARY_DIR}/SustaoBasicConfig.cmake"
              "${PROJECT_BINARY_DIR}/SustaoBasicConfigVersion.cmake"
        DESTINATION lib/cmake)

```

Then, I can package it in installation path.

In additional project, the `find_package(SustaoBasic)` is OK.

When I `#include "pA.h"`, vs reports bug:

```auto
“pA.h”: No such file or directory

```

But, I am sure `pA.h` is included in `install\include`, and my `install\include` is:

```auto
install
    include 
        pA
            pA.h
        pB
            pB.h

```

Then, I want to find solution from `ITK` project. I find `ITK` generates a `ITK_INCLUDED_DIRS` variable. How can I generate the similar variable in my project?

Any suggestion is appreciated~~~

---

<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: [June 14, 2022, 11:21am UTC](https://discourse.cmake.org/t/how-to-generate-itk-include-dirs-when-packaging-myself-module/5865/2 "2022-06-14T11:21:44Z")

</div>

> [@zhang-qiang-github](#):
>
> `ITK_INCLUDED_DIRS` variable. How can I generate the similar variable in my project?

This is historical. There is no need for such a variable anymore. Instead, `target_include_directories(pA PUBLIC "$<INSTALL_INTERFACE:include/pA>")` is probably what you want.

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [June 14, 2022, 12:47pm UTC](https://discourse.cmake.org/t/how-to-generate-itk-include-dirs-when-packaging-myself-module/5865/3 "2022-06-14T12:47:55Z")

</div>

Thank you for you kindly suggestion.

But I feel some confuzed about how to use `target_include_directories(pA PUBLIC "$<INSTALL_INTERFACE:include/pA>")`.

In following description, `packagePro` is the project I need to generate package. 'packageTest`is the project where I want to use`packagePro` package.

I have tried two experiments:

1. I add `target_include_directories(pA PUBLIC "$<INSTALL_INTERFACE:include/pA>")` in the CMakeLists.txt of `packagePro`, which is:

```auto
...
install(DIRECTORY package/ DESTINATION include
	FILES_MATCHING PATTERN "*.h"
)

install(EXPORT SustaoBasic
	FILE SustaoBasic.cmake
	NAMESPACE SustaoBasic::
	DESTINATION lib/cmake
)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
	SustaoBasicConfigVersion.cmake
	VERSION V1.0
	COMPATIBILITY AnyNewerVersion # 表示该函数库向下兼容
)

configure_package_config_file(
	SustaoBasicConfig.cmake.in ${PROJECT_BINARY_DIR}/SustaoBasicConfig.cmake
	INSTALL_DESTINATION lib/cmake
)

install(FILES "${PROJECT_BINARY_DIR}/SustaoBasicConfig.cmake"
              "${PROJECT_BINARY_DIR}/SustaoBasicConfigVersion.cmake"
        DESTINATION lib/cmake)

# add -------------------------------------------------------------------------------------
target_include_directories(pA PUBLIC "$<INSTALL_INTERFACE:include/pA>")

```

The CMakeLists.txt of `packageTest` is:

```auto
project(PackageTest)
find_package(SustaoBasic)
add_executable(PackageTest main.cpp)

```

After building, the vs still reports `“pA.h”: No such file or directory`.

1. I add `target_include_directories(pA PUBLIC "$<INSTALL_INTERFACE:include/pA>")` in the CMakeLists.txt of `packageTest`:

```auto
project(PackageTest)

find_package(SustaoBasic)
add_executable(PackageTest main.cpp)

target_include_directories(PackageTest PUBLIC "$<INSTALL_INTERFACE:include/pA>")

```

But, it still report `“pA.h”: No such file or directory`.

Where should I add `target_include_directories(pA PUBLIC "$<INSTALL_INTERFACE:include/pA>")`?  
In addition, what path is `INSTALL_INTERFACE`? Is the `SustaoBasic_DIR` set in CMake?

---

<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: [June 14, 2022, 2:12pm UTC](https://discourse.cmake.org/t/how-to-generate-itk-include-dirs-when-packaging-myself-module/5865/4 "2022-06-14T14:12:47Z")

</div>

> [@zhang-qiang-github](#):
>
> ```auto
> project(PackageTest)
> find_package(SustaoBasic)
> add_executable(PackageTest main.cpp)
> 
> ```

You need to link to the `pA` target.

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [June 15, 2022, 2:17am UTC](https://discourse.cmake.org/t/how-to-generate-itk-include-dirs-when-packaging-myself-module/5865/5 "2022-06-15T02:17:27Z")

</div>

@ben.boeckel Thank you for you kindly reply, and I finally solve my problem.

The solution is:

1. add `target_include_directories(PackageTest PUBLIC "$<INSTALL_INTERFACE:include/pA>")` in CMakeLists.txt of `packagePro`.
2. link to `pA` target in CMakeLists.txt of `packageTest`:

```auto
project(PackageTest)

find_package(SustaoBasic)

add_executable(PackageTest main.cpp)
target_link_libraries(PackageTest SustaoBasic::pA)

```

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zhang-qiang-github/32/1913_2.png) [@zhang-qiang-github](https://discourse.cmake.org/u/zhang-qiang-github)
#### Post date: [June 16, 2022, 5:57am UTC](https://discourse.cmake.org/t/how-to-generate-itk-include-dirs-when-packaging-myself-module/5865/6 "2022-06-16T05:57:38Z")

</div>

@ben.boeckel

`target_include_directories(pA PUBLIC "$<INSTALL_INTERFACE:include/pA>")` can solve current problem.

The include folder is:

```auto
Package
  pA
  pB

```

Is it possible to include `Package` directory when `find_package()` or `target_link_libraries(PackageTest SustaoBasic)`?

Currently, I must `target_link_libraries(PackageTest SustaoBasic::pA)` to specify the `pA`. Can I link all libraries, just link `target_link_libraries(Pro ${ITK_LIBRARIES})`?

---

<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: [June 16, 2022, 7:46pm UTC](https://discourse.cmake.org/t/how-to-generate-itk-include-dirs-when-packaging-myself-module/5865/7 "2022-06-16T19:46:04Z")

</div>

> [@zhang-qiang-github](#):
>
> Can I link all libraries, just link `target_link_libraries(Pro ${ITK_LIBRARIES})`?

I find it better to link to the targets directly rather than through some variable. Fewer moving parts.
