Skip to contentSkip to conversation

Respect CMAKE_INSTALL_LIBDIR

PATCH Superseded Ben Olson 3 participants 5 messages Nov 25, 2024

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Ben Olson

author
#0 lore raw

PATCH v3 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 v3:
- Added additional change in README

Changes in v2:
- Included the proper built-in CMake module
- Made commit message distro-agnostic

 CMakeLists.txt | 19 ++++++-------------
 README         |  5 ++---
 2 files changed, 8 insertions(+), 16 deletions(-)
CMakeLists.txt +6 -13
index 8ca1bf2..1d0dadf 100644
@@ -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 +2 -3
index f9aeef7..e9f860a 100644
@@ -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
@@ -12,7 +11,7 @@ cmake Options:
     Use -DBUILD_SHARED_LIBS=OFF while invoking cmake to create STATIC libraries
     and link applications to it.
 
-    Ex. cmake -D__LIB=lib -DBUILD_SHARED_LIBS=OFF ..
+    Ex. cmake -DBUILD_SHARED_LIBS=OFF ..
 
   -DCMAKE_INSTALL_PREFIX
     Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
Signature · 1 line
2.47.0
#1 lore raw
Quoted 9 lines · Ben Olson

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.

feel free to retain reviewed-by/tested-by for small changes - I noticed one problem below..

Quoted 56 lines

---

Changes in v3:
- Added additional change in README

Changes in v2:
- Included the proper built-in CMake module
- Made commit message distro-agnostic

 CMakeLists.txt | 19 ++++++-------------
 README         |  5 ++---
 2 files changed, 8 insertions(+), 16 deletions(-)
CMakeLists.txt +6 -13
index 8ca1bf2..1d0dadf 100644
@@ -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 +0 -0
index f9aeef7..e9f860a 100644

README Build instructions: · line 7

Quoted 7 lines
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
 

Last thing I promise! This should instead be

4. cmake ..
5. make install

i.e. we still want the cmake line, just not to include the -D__LIB=lib

Quoted 11 lines
README +1 -1
 cmake Options:
   -DBUILD_SHARED_LIBS
@@ -12,7 +11,7 @@ cmake Options:
     Use -DBUILD_SHARED_LIBS=OFF while invoking cmake to create STATIC libraries
     and link applications to it.
 
-    Ex. cmake -D__LIB=lib -DBUILD_SHARED_LIBS=OFF ..
+    Ex. cmake -DBUILD_SHARED_LIBS=OFF ..
 
   -DCMAKE_INSTALL_PREFIX
     Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
#2 lore raw
Quoted 81 lines · Alan Maguire
Quoted 9 lines · Ben Olson

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.

feel free to retain reviewed-by/tested-by for small changes - I noticed one problem below..

Quoted 56 lines

---

Changes in v3:
- Added additional change in README

Changes in v2:
- Included the proper built-in CMake module
- Made commit message distro-agnostic

 CMakeLists.txt | 19 ++++++-------------
 README         |  5 ++---
 2 files changed, 8 insertions(+), 16 deletions(-)
CMakeLists.txt +6 -13
index 8ca1bf2..1d0dadf 100644
@@ -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 +0 -0
index f9aeef7..e9f860a 100644

README Build instructions: · line 7

Quoted 7 lines
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
 

Last thing I promise! This should instead be

Quoted 4 lines

4. cmake ..
5. make install

i.e. we still want the cmake line, just not to include the -D__LIB=lib

Ach, both Brandon and I missed that!

Quoted 14 lines
Quoted 13 lines
README +1 -1
 cmake Options:
   -DBUILD_SHARED_LIBS
@@ -12,7 +11,7 @@ cmake Options:
     Use -DBUILD_SHARED_LIBS=OFF while invoking cmake to create STATIC libraries
     and link applications to it.
 
-    Ex. cmake -D__LIB=lib -DBUILD_SHARED_LIBS=OFF ..
+    Ex. cmake -DBUILD_SHARED_LIBS=OFF ..
 
   -DCMAKE_INSTALL_PREFIX
     Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
#3 lore raw
In reply to Ben Olson
Quoted 9 lines · Ben Olson

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.

Alan, can I keep your tags?

- Arnaldo

Quoted 76 lines

---

Changes in v3:
- Added additional change in README

Changes in v2:
- Included the proper built-in CMake module
- Made commit message distro-agnostic

 CMakeLists.txt | 19 ++++++-------------
 README         |  5 ++---
 2 files changed, 8 insertions(+), 16 deletions(-)
CMakeLists.txt +6 -13
index 8ca1bf2..1d0dadf 100644
@@ -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 +2 -3
index f9aeef7..e9f860a 100644
@@ -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
@@ -12,7 +11,7 @@ cmake Options:
     Use -DBUILD_SHARED_LIBS=OFF while invoking cmake to create STATIC libraries
     and link applications to it.
 
-    Ex. cmake -D__LIB=lib -DBUILD_SHARED_LIBS=OFF ..
+    Ex. cmake -DBUILD_SHARED_LIBS=OFF ..
 
   -DCMAKE_INSTALL_PREFIX
     Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
Signature · 1 line
2.47.0
#4 lore raw
Quoted 7 lines · Arnaldo Carvalho de Melo
Quoted 6 lines · Ben Olson

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.

Quoted 6 lines
Quoted 3 lines

Alan, can I keep your tags?

sure, I think we need a small fixup to ensure we keep the step 4 (cmake ..) in the instructions though; otherwise looks perfect!

Quoted 78 lines

- Arnaldo

Quoted 76 lines

---

Changes in v3:
- Added additional change in README

Changes in v2:
- Included the proper built-in CMake module
- Made commit message distro-agnostic

 CMakeLists.txt | 19 ++++++-------------
 README         |  5 ++---
 2 files changed, 8 insertions(+), 16 deletions(-)
CMakeLists.txt +6 -13
index 8ca1bf2..1d0dadf 100644
@@ -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 +2 -3
index f9aeef7..e9f860a 100644
@@ -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
@@ -12,7 +11,7 @@ cmake Options:
     Use -DBUILD_SHARED_LIBS=OFF while invoking cmake to create STATIC libraries
     and link applications to it.
 
-    Ex. cmake -D__LIB=lib -DBUILD_SHARED_LIBS=OFF ..
+    Ex. cmake -DBUILD_SHARED_LIBS=OFF ..
 
   -DCMAKE_INSTALL_PREFIX
     Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
Signature · 1 line
2.47.0