3

I am trying an install script for a shared library with cmake. While I found out that I want to use install, I am not sure what's the best practice to set the destinations.

This comment* and various bugreports refer to LIB_INSTALL_DIR.

However I find hardly any documentation of the LIB_INSTALL_DIR

My best guess for a library install would be:

add_library(mylib SHARED ${sources})
install(TARGET mylib LIBRARY DESTINATION ${LIB_INSTALL_DIR})
install(FILES ${libheaders} DESTINATION ${??})

My questions regarding this are:

  1. How do I set LIB_INSTALL_DIR in a way that the user can overwrite it if requires (set LIB_INSTALL_DIR lib) does not allow this, does it?)
  2. What is the correct variable for the header directory? (Should I try to default it (set it to that if it is undefined) to CMAKE_SYSTEM_INCLUDE_PATH, and if so how do I do that?)
  3. install(TARGET has a INCLUDES DESTINATION, is there a better way than using manual install(FILES ${libheaders} DESTINATION ${??}) for a bunch of headers?

*first comment, by Fraser, could not find a way to link directly to the comment, only to the answer.

ted
  • 4,791
  • 5
  • 38
  • 84
  • One question per question post, please. It is OK to ask related questions in the one post, but your questions have a little common aside from being CMake-related. – Tsyvarev Apr 19 '16 at 21:10
  • 1
    @Tsyvarev the way I see it, the question list clarifies my actual problems with the main question which is "What is the best practice for installing a shared library (library and headers) with cmake". But I will keep this in mind and doublecheck if I can split my questions before I post another one. – ted Apr 20 '16 at 08:37
  • 1
    Actually, your first question has nothing common with "best practice for installing...". It is just technical and can be answered as `Use CACHE keyword for make variable overwritable by the user`. Your third question is also technical: `INCLUDE DESTINATION` doesn't install anything but add interface for possibly exported target. For install many files in similar scenario you may use `foreach` loop over list of files. Only the second question is related to "best practice" about choosing destination paths. Having many questions in the one post contradicts **Question/Answer** nature of SO. – Tsyvarev Apr 20 '16 at 09:04
  • I highly recommend you read https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html – starball Jul 18 '22 at 11:05

0 Answers0