<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Sun, Oct 21, 2018 at 3:41 AM Илья Шипицин <<a href="mailto:chipitsine@gmail.com">chipitsine@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">сб, 20 окт. 2018 г. в 18:31, Eric Noulard <<a href="mailto:eric.noulard@gmail.com" target="_blank">eric.noulard@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div class="gmail_quote"><br></div><div>And the content is:</div><div>$ rpm -qpl softether-vpnserver-5.1.9660-1.x86_64.rpm<br></div><div><div>/lib</div><div>/lib/systemd</div><div>/lib/systemd/system</div><div>/lib/systemd/system/softether-vpnserver.service</div><div>/usr/libexec</div><div>/usr/libexec/softether</div><div>/usr/libexec/softether/vpnserver</div><div>/usr/libexec/softether/vpnserver/hamcore.se2</div><div>/usr/libexec/softether/vpnserver/vpnserver</div><div>/usr/local</div><div>/usr/local/bin</div><div>/usr/local/bin/vpnserver</div></div><div><br></div><div>the content of the .deb is similar:</div><div>$ dpkg-deb -c softether-vpnserver_5.1.9660_amd64.deb<br></div><div><div>drwxr-xr-x root/root         0 2018-10-20 14:45 ./lib/</div><div>drwxr-xr-x root/root         0 2018-10-20 14:45 ./lib/systemd/</div><div>drwxr-xr-x root/root         0 2018-10-20 14:45 ./lib/systemd/system/</div><div>-rw-r--r-- root/root       700 2018-10-20 14:45 ./lib/systemd/system/softether-vpnserver.service</div><div>drwxr-xr-x root/root         0 2018-10-20 14:45 ./usr/</div><div>drwxr-xr-x root/root         0 2018-10-20 14:45 ./usr/libexec/</div><div>drwxr-xr-x root/root         0 2018-10-20 14:45 ./usr/libexec/softether/</div><div>drwxr-xr-x root/root         0 2018-10-20 14:45 ./usr/libexec/softether/vpnserver/</div><div>-rw-r--r-- root/root   1770716 2018-10-20 14:45 ./usr/libexec/softether/vpnserver/hamcore.se2</div><div>-rwxr-xr-x root/root   2088960 2018-10-20 14:45 ./usr/libexec/softether/vpnserver/vpnserver</div><div>drwxr-xr-x root/root         0 2018-10-20 14:45 ./usr/local/</div><div>drwxr-xr-x root/root         0 2018-10-20 14:45 ./usr/local/bin/</div><div>-rwxr-xr-x root/root        72 2018-10-20 14:45 ./usr/local/bin/vpnserver</div></div><div><br></div><div>The main question is, what filesystem layout do you expect for those files?</div><div><br></div></div></div></div></div></div></div></div></div></div></div></blockquote><div> </div><div>Now I think I get it.</div><div>IN vpnserver CMakeLists.txt you do:</div><div><br></div><div>install_systemd_service("vpnserver" "${CMAKE_SOURCE_DIR}/systemd/softether-vpnserver.service" "${CMAKE_INSTALL_FULL_LIBEXECDIR}/softether/vpnserver/vpnserver")<br></div><div><br></div><div>So at this point (during CMake config step) "${CMAKE_INSTALL_FULL_LIBEXECDIR}/softether/vpnserver/vpnserver"</div><div>is /usr/local/softether/vpnserver/vpnserver</div><div><br></div><div>In your install_systemd_service CMake macro wrapper you do:</div><div><br></div><div><div>macro(install_systemd_service component file_path binary_path)</div><div>    get_filename_component(file_name ${file_path} NAME)</div><div>    get_filename_component(binary_directory ${binary_path} DIRECTORY)</div><div><br></div><div>    file(READ ${file_path} FILE_CONTENT)</div><div>    string(REPLACE "[DIRECTORY]" ${binary_directory} FILE_CONTENT ${FILE_CONTENT})</div><div>    string(REPLACE "[BINARY]" ${binary_path} FILE_CONTENT ${FILE_CONTENT})</div><div>    file(WRITE ${CMAKE_SOURCE_DIR}/tmp/systemd/${file_name} ${FILE_CONTENT})</div></div><div>...</div></div><div><br></div><div>So you generate a systemd service file which contains /usr/local prefix because this is the one which</div><div>is know during "CMake configuration step".</div><div><br></div><div>You cannot do that this way with .deb or .rpm because you don't know the "actual" prefix that will be in the package</div><div>because it is controlby CPACK_PACKAGING_INSTALL_PREFIX  "at CPack time", i.e. when CPack runs.</div><div><br></div><div>It's even worse because .deb or .rpm may be relocated see e.g.:</div><div><a href="https://www.cyberciti.biz/faq/howto-install-rpm-package-into-another-directory/" target="_blank">https://www.cyberciti.biz/faq/howto-install-rpm-package-into-another-directory/</a><br></div><div><br></div><div>When you want to install script that should know where things get installed you have 3 options:</div><div><br></div><div>1) Assume the binary executable is installed in the path</div><div>    thus call the executable as-is "vpnserver" without absolute path</div><div><br></div><div>2) Put a pre- or post- install script that will compute the appropriate path </div><div>   **during package installation** when you are sure what the real path will be.</div><div>   Have a look at CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA in <a href="https://cmake.org/cmake/help/latest/cpack_gen/deb.html" target="_blank">https://cmake.org/cmake/help/latest/cpack_gen/deb.html</a></div><div>or <a href="https://cmake.org/cmake/help/latest/cpack_gen/rpm.html#variable:CPACK_RPM_SPEC_MORE_DEFINE" target="_blank">https://cmake.org/cmake/help/latest/cpack_gen/rpm.html#variable:CPACK_RPM_SPEC_MORE_DEFINE</a></div><div>   </div><div>3) Ensure that you generate package with </div><div>   CMAKE_INSTALL_PREFIX == CPACK_PACKAGING_INSTALL_PREFIX</div><div>   This is ok but will break if the installation of the package is relocated.</div></div></div></div></div></div></div></div></div></div></div></div></div></div></blockquote><div><br></div><div>this is good.</div><div>is there a way to install shared libs to system location ? (in order to avoid ld manipulation)</div></div></div></blockquote></div><div><br></div><div>If your app isn't part of the Linux distribution itself, you shouldn't install it to /usr. You should be looking to install to somewhere like /opt instead (or maybe /usr/local, but /opt is generally better). You should be able to use RPATH to avoid needing to mess with the library search path - search the CMake docs for INSTALL_RPATH, it has pretty good support for RPATH these days. Just be sure to use relative RPATHs (i.e. start each path with $ORIGIN for Linux) to ensure your package remains relocatable.</div><div><br></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr">Craig Scott<br><div>Melbourne, Australia</div><div><a href="https://crascit.com" target="_blank">https://crascit.com</a><br></div><div><br></div><div>New book released: <a href="https://crascit.com/professional-cmake/" target="_blank">Professional CMake: A Practical Guide</a><br></div></div></div></div></div></div></div></div>