Help with component packaging

Hi,

I’m a beginner with CMake mainly learning by reading Craig Scott’s “Professional CMake: A Practical Guide”.

I have successfully created a simple project and am now ready to move on to more complicated stuff. I have a few libraries to build and package so I’ve decided to practice with Howard Hinnant’s date library. This library is an ideal candidate for practice because it contains interface and shared library targets which depends on libcurl. The targets can also be divided into runtime and development components.

Firstly, I created a project to build, install, package and export the above library without components. It seems that I was successful with it because I’m able to successfully do a find_package() on the installed project. FYI, this complete project can be found in attachment hh_date.zip. I won’t mind any comments for improvement.

Next, I created a project to build, install, package and export the above library with “Runtime” and “Development” components. There seems to be a problem with this project because I get a failure when I do a find_package() on the resulting installed packages. The failure appears to indicate that some imported targets are missing. FYI, this complete project can be found in attachment hh_date_comp.zip. It seems that I have some misunderstandings in putting together the code snippets provided in Chapters 25 & 26 of the book.

I would appreciate it if someone could point me to what is wrong in the project files.

Kind regards,
Leo

hh_date.zip (74 KB)

hh_date_comp.zip (74.7 KB)

The install components, if intended to be usable separately, also requires that the separable targets be in different export sets (i.e., install(TARGETS ${tgt} EXPORT ${name})) so that the targets can be included separately. I suspect that is what is going wrong here (not having looked at the examples yet).