0

I have a static library A that depends on other shared libraries B and C. When I build my application D, I need to find and link with A, B and C. Is there a way to tell CMake to link only with A and to get from it that it needs to link with B and C?

Note that the application A is a different project with it's own CMake files and directories and that all of the libraries and the application are for Linux.

  • 1
    There is a way to do it, its called "modern CMake" https://schneide.wordpress.com/2016/04/08/modern-cmake-with-target_link_libraries/ – R2RT Feb 12 '18 at 09:43
  • @R2RT I read this solution before but a far as I understand it will work only within the same project. If the application is a complete separate project with it's own CMake files and directories I think that this will not work. I will modify my question to make it more clear – وليد تاج الدين Feb 12 '18 at 09:50
  • 1
    As long as A's CMakeLists.txt follows modern CMake it will work. If it does not follow them it will make you link its dependencies (B and C) anyway via compiler flags. – R2RT Feb 12 '18 at 10:19
  • 1
    Unlike to shared libraries, static libraries don't contain information about their linkage: https://stackoverflow.com/questions/40789518/how-to-list-dependencies-of-c-c-static-library. So, if CMake knows nothing aside from the static library *A*, then it is unable to get *B* and *C* as its dependencies. – Tsyvarev Feb 12 '18 at 13:36
  • @R2RT I tried it and it's not sufficient by it's own. It need project `A` to be exported and imported from project `D` for this solution to work. The other solution I am trying now is to create a package for this library. – وليد تاج الدين Feb 14 '18 at 05:45
  • @Tsyvarev yes this is correct. I search for a solution in which CMake can store some extra information to be used by the application project CMake. Creating a package do this and seems to be a good solution for me. – وليد تاج الدين Feb 14 '18 at 05:47

0 Answers0