From 05a8d589e75650066b1fce64d069a140231a16e0 Mon Sep 17 00:00:00 2001 From: Micah Snyder Date: Mon, 8 Feb 2021 09:39:06 -0800 Subject: [PATCH] CMake: improve multiarch support In testing on Alpine, I found that most libs were installing to /lib while libclamav installed to /lib64. Those who like multiarch will advocate for lib64, though I only actually noticed it because clamscan failed to find libclamav.so! Anyways, they should all install to lib64 by default if that's what how the system is set up. Using ${CMAKE_INSTALL_FULL_LIBDIR} instead of /lib will do that. --- CMakeLists.txt | 17 +++++++++++------ clamd/CMakeLists.txt | 2 +- clamdscan/CMakeLists.txt | 2 +- clamdtop/CMakeLists.txt | 2 +- clamonacc/CMakeLists.txt | 2 +- clamscan/CMakeLists.txt | 2 +- clamsubmit/CMakeLists.txt | 2 +- docs/CMakeLists.txt | 14 +++++++------- freshclam/CMakeLists.txt | 2 +- libclammspack/CMakeLists.txt | 2 +- libclamunrar/CMakeLists.txt | 2 +- libclamunrar_iface/CMakeLists.txt | 2 +- libfreshclam/CMakeLists.txt | 4 ++-- sigtool/CMakeLists.txt | 2 +- test/CMakeLists.txt | 1 - unit_tests/CMakeLists.txt | 1 - 16 files changed, 31 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bbe15d5f2..24ad05517 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -159,7 +159,14 @@ endif() if(APPLE) set(CMAKE_MACOSX_RPATH 1) endif() -set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") + +include(GNUInstallDirs) + +if(CMAKE_INSTALL_FULL_LIBDIR) + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_LIBDIR}") +else() + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") +endif() if(C_LINUX) if(CMAKE_COMPILER_IS_GNUCXX) @@ -348,8 +355,6 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) "None" "Debug" "Release" "MinSizeRel" "RelWithDebInfo") endif() -include(GNUInstallDirs) - # Always use '-fPIC'/'-fPIE' option. set(CMAKE_POSITION_INDEPENDENT_CODE ON) @@ -714,7 +719,7 @@ else() ${CMAKE_CURRENT_BINARY_DIR}/clamav-config @ONLY) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/clamav-config" - DESTINATION "${CMAKE_INSTALL_BINDIR}" + DESTINATION "${CMAKE_INSTALL_BINDIR}" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE @@ -814,8 +819,8 @@ endif() if(WIN32) # Include the license(s) in the installation - install(FILES ${CMAKE_SOURCE_DIR}/COPYING.txt DESTINATION ".") - install(DIRECTORY ${CMAKE_SOURCE_DIR}/COPYING DESTINATION ".") + install(FILES ${CMAKE_SOURCE_DIR}/COPYING.txt DESTINATION .) + install(DIRECTORY ${CMAKE_SOURCE_DIR}/COPYING DESTINATION .) endif() # diff --git a/clamd/CMakeLists.txt b/clamd/CMakeLists.txt index a1c2c3491..87e130172 100644 --- a/clamd/CMakeLists.txt +++ b/clamd/CMakeLists.txt @@ -45,7 +45,7 @@ target_link_libraries( clamd if(WIN32) install(TARGETS clamd DESTINATION .) else() - install(TARGETS clamd DESTINATION sbin) + install(TARGETS clamd DESTINATION ${CMAKE_INSTALL_SBINDIR}) endif() if(SYSTEMD_FOUND) diff --git a/clamdscan/CMakeLists.txt b/clamdscan/CMakeLists.txt index fb382fb2a..b67a98546 100644 --- a/clamdscan/CMakeLists.txt +++ b/clamdscan/CMakeLists.txt @@ -34,5 +34,5 @@ target_link_libraries( clamdscan if(WIN32) install(TARGETS clamdscan DESTINATION .) else() - install(TARGETS clamdscan DESTINATION bin) + install(TARGETS clamdscan DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/clamdtop/CMakeLists.txt b/clamdtop/CMakeLists.txt index 0eec636d9..cc2bd76e6 100644 --- a/clamdtop/CMakeLists.txt +++ b/clamdtop/CMakeLists.txt @@ -54,5 +54,5 @@ if(WIN32) #message("UNRESOLVED_DEPENDENCIES_VAR: ${_u_deps}") ]]) else() - install(TARGETS clamdtop DESTINATION bin) + install(TARGETS clamdtop DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/clamonacc/CMakeLists.txt b/clamonacc/CMakeLists.txt index 2086e4992..13caf8d7a 100644 --- a/clamonacc/CMakeLists.txt +++ b/clamonacc/CMakeLists.txt @@ -49,7 +49,7 @@ target_link_libraries( clamonacc ClamAV::libclamav ClamAV::shared CURL::libcurl ) -install(TARGETS clamonacc DESTINATION sbin) +install(TARGETS clamonacc DESTINATION ${CMAKE_INSTALL_SBINDIR}) if(SYSTEMD_FOUND) configure_file( diff --git a/clamscan/CMakeLists.txt b/clamscan/CMakeLists.txt index 86a5d5977..345c155f9 100644 --- a/clamscan/CMakeLists.txt +++ b/clamscan/CMakeLists.txt @@ -33,5 +33,5 @@ target_link_libraries( clamscan if(WIN32) install(TARGETS clamscan DESTINATION .) else() - install(TARGETS clamscan DESTINATION bin) + install(TARGETS clamscan DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/clamsubmit/CMakeLists.txt b/clamsubmit/CMakeLists.txt index e0a4cf445..5929ab57c 100644 --- a/clamsubmit/CMakeLists.txt +++ b/clamsubmit/CMakeLists.txt @@ -62,5 +62,5 @@ if(WIN32) #message("UNRESOLVED_DEPENDENCIES_VAR: ${_u_deps}") ]]) else() - install(TARGETS clamsubmit DESTINATION bin) + install(TARGETS clamsubmit DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 2f1592c54..cd3c0f733 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -21,7 +21,7 @@ if(ENABLE_MAN_PAGES) configure_file(man/clamd.8.in man/clamd.8) configure_file(man/clamav-milter.8.in man/clamav-milter.8) if(C_LINUX) - configure_file(man/clamonacc.8.in man/clamonacc.8) + configure_file(man/clamonacc.8.in man/clamonacc.8) endif() set(MAN1_FILES @@ -38,7 +38,7 @@ if(ENABLE_MAN_PAGES) FILES ${CMAKE_CURRENT_BINARY_DIR}/${m} DESTINATION - ${CMAKE_INSTALL_PREFIX}/share/man/man1) + ${CMAKE_INSTALL_MANDIR}/man1) endforeach() set(MAN5_FILES @@ -50,7 +50,7 @@ if(ENABLE_MAN_PAGES) FILES ${CMAKE_CURRENT_BINARY_DIR}/${m} DESTINATION - ${CMAKE_INSTALL_PREFIX}/share/man/man5) + ${CMAKE_INSTALL_MANDIR}/man5) endforeach() set(MAN8_FILES @@ -61,7 +61,7 @@ if(ENABLE_MAN_PAGES) FILES ${CMAKE_CURRENT_BINARY_DIR}/${m} DESTINATION - ${CMAKE_INSTALL_PREFIX}/share/man/man8) + ${CMAKE_INSTALL_MANDIR}/man8) endforeach() if(C_LINUX) @@ -70,7 +70,7 @@ if(ENABLE_MAN_PAGES) FILES ${CMAKE_CURRENT_BINARY_DIR}/man/clamonacc.8 DESTINATION - ${CMAKE_INSTALL_PREFIX}/share/man/man8) + ${CMAKE_INSTALL_MANDIR}/man8) endif() endif() @@ -105,7 +105,7 @@ if(WIN32) # When built from the release tarball, this includes the user manual # which is exported from the clamav-faq repo. if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/html/UserManual.html) - install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/html/UserManual.html DESTINATION ".") - install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/html/UserManual DESTINATION ".") + install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/html/UserManual.html DESTINATION .) + install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/html/UserManual DESTINATION .) endif() endif() diff --git a/freshclam/CMakeLists.txt b/freshclam/CMakeLists.txt index cf282cf2a..e3d0383de 100644 --- a/freshclam/CMakeLists.txt +++ b/freshclam/CMakeLists.txt @@ -32,7 +32,7 @@ target_link_libraries(freshclam-bin if(WIN32) install(TARGETS freshclam-bin DESTINATION .) else() - install(TARGETS freshclam-bin DESTINATION bin) + install(TARGETS freshclam-bin DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() # Install an empty database directory diff --git a/libclammspack/CMakeLists.txt b/libclammspack/CMakeLists.txt index 2f0403fc5..d34d10c4a 100644 --- a/libclammspack/CMakeLists.txt +++ b/libclammspack/CMakeLists.txt @@ -72,7 +72,7 @@ if(ENABLE_SHARED_LIB) if(WIN32) install(TARGETS mspack DESTINATION .) else() - install(TARGETS mspack DESTINATION lib) + install(TARGETS mspack DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() # Public (forwarded) dependencies. diff --git a/libclamunrar/CMakeLists.txt b/libclamunrar/CMakeLists.txt index 5d28e3352..a4651b9dd 100644 --- a/libclamunrar/CMakeLists.txt +++ b/libclamunrar/CMakeLists.txt @@ -92,7 +92,7 @@ if(ENABLE_SHARED_LIB) if(WIN32) install(TARGETS clamunrar DESTINATION .) else() - install(TARGETS clamunrar DESTINATION lib) + install(TARGETS clamunrar DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() add_library( ClamAV::libunrar ALIAS clamunrar ) diff --git a/libclamunrar_iface/CMakeLists.txt b/libclamunrar_iface/CMakeLists.txt index 302e7d5e7..219db4b7e 100644 --- a/libclamunrar_iface/CMakeLists.txt +++ b/libclamunrar_iface/CMakeLists.txt @@ -66,7 +66,7 @@ if(ENABLE_UNRAR) if(WIN32) install(TARGETS clamunrar_iface DESTINATION .) else() - install(TARGETS clamunrar_iface DESTINATION lib) + install(TARGETS clamunrar_iface DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() add_library( ClamAV::libunrar_iface ALIAS clamunrar_iface ) diff --git a/libfreshclam/CMakeLists.txt b/libfreshclam/CMakeLists.txt index 3a7e55f68..e38987f46 100644 --- a/libfreshclam/CMakeLists.txt +++ b/libfreshclam/CMakeLists.txt @@ -94,7 +94,7 @@ if(ENABLE_SHARED_LIB) #message("UNRESOLVED_DEPENDENCIES_VAR: ${_u_deps}") ]]) else() - install(TARGETS freshclam DESTINATION lib) + install(TARGETS freshclam DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() add_library( ClamAV::libfreshclam ALIAS freshclam ) @@ -117,7 +117,7 @@ if(ENABLE_STATIC_LIB) if(WIN32) install(TARGETS freshclam_static DESTINATION .) else() - install(TARGETS freshclam_static DESTINATION lib) + install(TARGETS freshclam_static DESTINATION ${CMAKE_INSTALL_LIBDIR}) endif() add_library( ClamAV::libfreshclam_static ALIAS freshclam_static ) diff --git a/sigtool/CMakeLists.txt b/sigtool/CMakeLists.txt index 50d773c67..56e9d2321 100644 --- a/sigtool/CMakeLists.txt +++ b/sigtool/CMakeLists.txt @@ -32,5 +32,5 @@ target_link_libraries( sigtool if(WIN32) install(TARGETS sigtool DESTINATION .) else() - install(TARGETS sigtool DESTINATION bin) + install(TARGETS sigtool DESTINATION ${CMAKE_INSTALL_BINDIR}) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 600d3b681..ce5726a9c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -68,7 +68,6 @@ function(assemble_testfile test_file) --split_dir ${CMAKE_CURRENT_SOURCE_DIR}/.split COMMENT "Assembling test file ${test_file} of ${original}") add_custom_target(tgt_${test_file} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${test_file}) - #install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${test_file} DESTINATION ${CMAKE_INSTALL_BINDIR}) endfunction() foreach(TESTFILE ${TESTFILES}) diff --git a/unit_tests/CMakeLists.txt b/unit_tests/CMakeLists.txt index 333dc94f9..eb5e9c8f3 100644 --- a/unit_tests/CMakeLists.txt +++ b/unit_tests/CMakeLists.txt @@ -17,7 +17,6 @@ function(assemble_testfile test_file) --split_dir ${CMAKE_CURRENT_SOURCE_DIR}/.split COMMENT "Assembling test file ${test_file} of ${original}") add_custom_target(tgt_${test_file} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${test_file}) - #install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${test_file} DESTINATION ${CMAKE_INSTALL_BINDIR}) endfunction() foreach(TESTFILE ${TESTFILES})