# cmake generated package cause bug while the source code is correct

**URL:** https://discourse.cmake.org/t/cmake-generated-package-cause-bug-while-the-source-code-is-correct/5876
**Category:** Code
**Created:** [June 16, 2022, 8:18am UTC](https://discourse.cmake.org/t/cmake-generated-package-cause-bug-while-the-source-code-is-correct/5876 "2022-06-16T08:18:08Z")
**Posts on this page:** 3
**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 16, 2022, 8:18am UTC](https://discourse.cmake.org/t/cmake-generated-package-cause-bug-while-the-source-code-is-correct/5876/1 "2022-06-16T08:18:08Z")

</div>

I have implement some code, and want to generate myself package.

My CMakeLists.txt looks like:

```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)

```

I can sucessfully generate myself package. However, bug is reported when I use it.

I use it by:

```auto
find_package(SustaoBasic)
target_link_libraries(Pro SustaoBasic::DataObject)

```

After building, vs reported: `can not open VTK::GUISupportQtSQL.lib`. It really make me confuzed.

1. I think the original `SustaoBasic::DataObject` do not link to `VTK::GUISupportQtSQL.lib`, because my built `VTK` package do not open `VTK_GUISupportQtSQL`:  

2. The project has no bug when I use the source code of `SustaoBasic`. Where is this bug from when I use `find_package()` to load `SustaoBasic::DataObject`?

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 16, 2022, 7:49pm UTC](https://discourse.cmake.org/t/cmake-generated-package-cause-bug-while-the-source-code-is-correct/5876/2 "2022-06-16T19:49:30Z")

</div>

I suspect that your `SustaoBasicConfig.cmake` file needs to do `find_package(VTK)` itself to make VTK’s imported targets available to consumers of your targets as well.

---

<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 17, 2022, 1:07am UTC](https://discourse.cmake.org/t/cmake-generated-package-cause-bug-while-the-source-code-is-correct/5876/3 "2022-06-17T01:07:32Z")

</div>

The `VTK::GUISupportQtSQL.lib` may be caused because I use `find_package(VTK REQUIRED)` in my `SustaoBasic` package. I have modified all `find_package(VTK REQUIRED)` to `find_package(VTK COMPONENTS CommonCore ...)`, and the bug is fixed.
