Problems with find_package

Hello,

I have troubles with the find_package() command.

I am doing a tutorial which should be known on this forum (hi @retif !), and I am now at this step :

I adapted the CMakeLists.txt to my project, but it is very similar (I had to change te library names, the path…).

Here are the troubles :

  1. When calling the target_link_libraries, I don’t understand where the some namespace comes from. It doesn’t seems related to the install() command above in the tutorial. Anyway, if I want my CMakeLists.txt doesn’t generate error during the configure step, I have to remove any workspace

  2. I use a Visual Studio generator, and in the generated VS solution, the debug configuration is linked to the release configuration of my library, whereas the debug version is also among the install files

  3. The include directories are not set at all, so I can’t use my library. When running CMake, I have a log stating by -- CMAKE_INSTALL_INCLUDEDIR, and it does point to the good location.

where the some namespace comes from

If the target name had namespace defined for its installation, then this is where it would come from. If you open that library’s *Targets.cmake file, you’ll see it there (or not, if it wasn’t set).

in the generated VS solution, the debug configuration is linked to the release configuration of my library

If the library was built and installed in both Debug and Release configurations, then you should have both of those, and there should also be *Targets-debug.cmake and *Targets-release.cmake files, so Debug should definitely link to Debug.

If the binary file name doesn’t have a postfix though, then I guess installing Release configuration after Debug would overwrite the binary, and then consuming project would only have one binary available to link to (the last one that was installed).

the include directories are not set at all

Sounds like something is wrong with the library installation. If the installation was done correctly, then consuming project would only need to do find_package() and target_link_libraries().

1 Like

Thanks for your replies.

If the target name had namespace defined for its installation, then this is where it would come from. If you open that library’s *Targets.cmake file, you’ll see it there (or not, if it wasn’t set).

Actually, I copied your code about the install command, and I left the variable ${namespace}, and I forgot to set/replace it. That was the problem. What is surprising now is the use of my lib seems identical (same includes paths, same namespace access from the code) if I use namespace or not in install/tarhet_link_libraries. I just have to make sure they’re consistent. The documentation is very light about this parameter.

If the library was built and installed in both Debug and Release configurations…
Sounds like something is wrong with the library installation. If the installation was done correctly…

Both pointd are resolved. It seems taht all the problems came from the same cause.

But the .h from the libray are not listed in the dependencies.

I am going to search how to do that…