CMake: how to generate self-package?

I have implemented myself package, and I want to distribute the dll/lib.

Currently, I can generate dll/lib with install. How can I generate the variable Self_LIBRARIES just like ITK_LIBRARIES?

With Self_LIBRARIES, user can include all modules by target_link_libraries(pro ${Self_LIBRARIES}). Without it, user can only use the dll by target_link_libraries(pro xx1module xx2module). It is hard for user to learn which module includes the needed function.

So, I wonder how to implement the Self_LIBRARIES? Any suggestion is appreciated~~~

You’ll need to generate a CMake package config file and set that variable yourself in some way. See this part of the tutorial to get started.

1 Like

Finally, I find the solution.

Two steps is needed for my question.

  1. In the CMakeLists.txt, I need to define the exported dll by:
install(TARGETS ${modules}
  1. In set(STK_LIBRARIES "@modules@")

Then, after find_package(STK), we can use STK_LIBRARIES: target_link_libraries(Pro ${STK_LIBRARIES}).