Respect CMAKE_INSTALL_LIBDIR
PATCH v2 1/1 Respect CMAKE_INSTALL_LIBDIR
This patch changes the cmake configuration to honor CMAKE_INSTALL_LIBDIR and use either lib or lib64 by default so that installations match the conventional placement of libraries.
For example, it will now install libdwarves.so into ${PREFIX}/lib or ${PREFIX}/lib64, depending on the distribution.
---
Changes in v2:
- Included the proper built-in CMake module
- Made commit message distro-agnostic
CMakeLists.txt | 19 ++++++------------- README | 3 +-- 2 files changed, 7 insertions(+), 15 deletions(-)
CMakeLists.txt +6 -13
@@ -21,18 +21,9 @@ else() LINK_DIRECTORIES(${LIBBPF_LIBRARY_DIRS}) endif() -# Try to parse this later, Helio just showed me a KDE4 example to support -# x86-64 builds. -# the following are directories where stuff will be installed to -set(__LIB "" CACHE STRING "Define suffix of directory name (32/64)" ) - -macro(_set_fancy _var _value _comment) - if (NOT DEFINED ${_var}) - set(${_var} ${_value}) - else (NOT DEFINED ${_var}) - set(${_var} "${${_var}}" CACHE PATH "${_comment}") - endif (NOT DEFINED ${_var}) -endmacro(_set_fancy) +# Use the standard library installation directory +include(GNUInstallDirs) +set(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "libdir name") # where to look first for cmake modules, # before ${CMAKE_ROOT}/Modules/ is checked
@@ -84,7 +75,9 @@ if(NOT LIBBPF_FOUND AND NOT EXISTS "${PROJECT_SOURCE_DIR}/lib/bpf/src/btf.h") message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") endif() -_set_fancy(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${__LIB}" "libdir") +if (NOT DEFINED LIB_INSTALL_DIR) + set(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") +endif() # libbpf uses reallocarray, which is not available in all versions of glibc # libbpf's include/tools/libc_compat.h provides implementation, but needs
README +1 -2
@@ -3,8 +3,7 @@ Build instructions: 1. install cmake 2. mkdir build 3. cd build -4. cmake -D__LIB=lib .. -5. make install +4. make install cmake Options: -DBUILD_SHARED_LIBS
Signature · 1 line
2.47.0
Quoted 9 lines · Ben Olson
This patch changes the
cmakeconfiguration to honorCMAKE_INSTALL_LIBDIRand use eitherliborlib64by default so that installations match the conventional placement of libraries.
For example, it will now installlibdwarves.sointo${PREFIX}/libor${PREFIX}/lib64, depending on the distribution.Signed-off-by Brandon Kammerdiener <[email protected]>Signed-off-by Ben Olson <[email protected]>Cc Alan Maguire <[email protected]>
(tested on Oracle Linux which uses lib64 for libraries; specifying cmake with no arguments did the right thing and "make install" installed into /usr/local/lib64 as expected; nice!)
One small nit I noticed, sorry missed this last time - the README has another reference to -D__LIB:
" Ex. cmake -D__LIB=lib -DBUILD_SHARED_LIBS=OFF .."
I think we should probably remove that reference also, right?
Quoted 61 lines
---
Changes in v2:
- Included the proper built-in CMake module
- Made commit message distro-agnosticCMakeLists.txt | 19 ++++++------------- README | 3 +-- 2 files changed, 7 insertions(+), 15 deletions(-)CMakeLists.txt +6
-13@@ -21,18 +21,9 @@ else() LINK_DIRECTORIES(${LIBBPF_LIBRARY_DIRS}) endif() -# Try to parse this later, Helio just showed me a KDE4 example to support -# x86-64 builds. -# the following are directories where stuff will be installed to -set(__LIB "" CACHE STRING "Define suffix of directory name (32/64)" ) - -macro(_set_fancy _var _value _comment) - if (NOT DEFINED ${_var}) - set(${_var} ${_value}) - else (NOT DEFINED ${_var}) - set(${_var} "${${_var}}" CACHE PATH "${_comment}") - endif (NOT DEFINED ${_var}) -endmacro(_set_fancy) +# Use the standard library installation directory +include(GNUInstallDirs) +set(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "libdir name") # where to look first for cmake modules, # before ${CMAKE_ROOT}/Modules/ is checked@@ -84,7 +75,9 @@ if(NOT LIBBPF_FOUND AND NOT EXISTS "${PROJECT_SOURCE_DIR}/lib/bpf/src/btf.h") message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") endif() -_set_fancy(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${__LIB}" "libdir") +if (NOT DEFINED LIB_INSTALL_DIR) + set(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") +endif() # libbpf uses reallocarray, which is not available in all versions of glibc # libbpf's include/tools/libc_compat.h provides implementation, but needsREADME +1
-2@@ -3,8 +3,7 @@ Build instructions: 1. install cmake 2. mkdir build 3. cd build -4. cmake -D__LIB=lib .. -5. make install +4. make install cmake Options: -DBUILD_SHARED_LIBS
Quoted 18 lines · Alan Maguire
Quoted 9 lines · Ben Olson
This patch changes the
cmakeconfiguration to honorCMAKE_INSTALL_LIBDIRand use eitherliborlib64by default so that installations match the conventional placement of libraries.
For example, it will now installlibdwarves.sointo${PREFIX}/libor${PREFIX}/lib64, depending on the distribution.Signed-off-by Brandon Kammerdiener <[email protected]>Signed-off-by Ben Olson <[email protected]>Cc Alan Maguire <[email protected]>Reviewed-by Alan Maguire <[email protected]>Tested-by Alan Maguire <[email protected]>(tested on Oracle Linux which uses lib64 for libraries; specifying cmake with no arguments did the right thing and "make install" installed into
/usr/local/lib64as expected; nice!)
Quoted 6 lines
One small nit I noticed, sorry missed this last time - the README has another reference to -D__LIB:
" Ex. cmake -D__LIB=lib -DBUILD_SHARED_LIBS=OFF .."
I think we should probably remove that reference also, right?
Ach, you're right! Missed that. I'll add that in a v3.
Quoted 63 lines
Quoted 62 lines
---
Changes in v2:
- Included the proper built-in CMake module
- Made commit message distro-agnosticCMakeLists.txt | 19 ++++++------------- README | 3 +-- 2 files changed, 7 insertions(+), 15 deletions(-)CMakeLists.txt +6
-13@@ -21,18 +21,9 @@ else() LINK_DIRECTORIES(${LIBBPF_LIBRARY_DIRS}) endif() -# Try to parse this later, Helio just showed me a KDE4 example to support -# x86-64 builds. -# the following are directories where stuff will be installed to -set(__LIB "" CACHE STRING "Define suffix of directory name (32/64)" ) - -macro(_set_fancy _var _value _comment) - if (NOT DEFINED ${_var}) - set(${_var} ${_value}) - else (NOT DEFINED ${_var}) - set(${_var} "${${_var}}" CACHE PATH "${_comment}") - endif (NOT DEFINED ${_var}) -endmacro(_set_fancy) +# Use the standard library installation directory +include(GNUInstallDirs) +set(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "libdir name") # where to look first for cmake modules, # before ${CMAKE_ROOT}/Modules/ is checked@@ -84,7 +75,9 @@ if(NOT LIBBPF_FOUND AND NOT EXISTS "${PROJECT_SOURCE_DIR}/lib/bpf/src/btf.h") message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") endif() -_set_fancy(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${__LIB}" "libdir") +if (NOT DEFINED LIB_INSTALL_DIR) + set(LIB_INSTALL_DIR "${EXEC_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}") +endif() # libbpf uses reallocarray, which is not available in all versions of glibc # libbpf's include/tools/libc_compat.h provides implementation, but needsREADME +1
-2@@ -3,8 +3,7 @@ Build instructions: 1. install cmake 2. mkdir build 3. cd build -4. cmake -D__LIB=lib .. -5. make install +4. make install cmake Options: -DBUILD_SHARED_LIBS