Skip to contentSkip to conversation

CMakeLists.txt: Remove custom `LIB_INSTALL_DIR` handling

PATCH Applied Paul Menzel 2 participants 3 messages Apr 20, 2025 – May 30, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 CMakeLists.txt: Remove custom `LIB_INSTALL_DIR` handling

There is no need to explicitly set LIB_INSTALL_DIR, as CMake’s module GNUInstallDirs sets it itself from CMAKE_INSTALL_LIBDIR, and takes care of everything, so the line below is enough.

cmake -DLIBBPF_EMBEDDED=OFF -DCMAKE_INSTALL_LIBDIR=lib ..

Note, it’s common to set it to a relative path, but absolute paths are allowed too.

cmake -DLIBBPF_EMBEDDED=OFF -DCMAKE_INSTALL_LIBDIR=/opt/usr/lib64 ..

From the [CMake documentation][1]:

Quoted 7 lines

CMAKE_INSTALL_<dir>

Destination for files of a given type. This value may be passed to the DESTINATION options of install() commands for the corresponding file type. It should be a path relative to the installation prefix so that it can be converted to an absolute path in a relocatable way.

Quoted 5 lines

While absolute paths are allowed, they are not recommended as they do not work with the cmake --install command's --prefix option, or with the cpack installer generators. In particular, there is no need to make paths absolute by prepending CMAKE_INSTALL_PREFIX; this prefix is used by default if the DESTINATION is a relative path.

So, remove the custom handling from CMakeLists.txt. Also, update README and mention the option.

[1]: https://cmake.org/cmake/help/v3.31/module/GNUInstallDirs.html

Fixes a2abd9482162 ("CMakeList.txt: Respect CMAKE_INSTALL_LIBDIR")
---
 CMakeLists.txt | 5 -----
 README         | 4 ++++
 2 files changed, 4 insertions(+), 5 deletions(-)
CMakeLists.txt +0 -5
index eb87300..844ab61 100644
@@ -23,7 +23,6 @@ endif()
 
 # 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
@@ -75,10 +74,6 @@ 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()
 
-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
 # COMPACT_NEED_REALLOCARRAY to be set
README +4 -0
index a938266..fb92d68 100644
@@ -18,6 +18,10 @@ cmake Options:
     Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
     when invoking cmake to specify another install location.
 
+  -DCMAKE_INSTALL_LIBDIR
+    Default is to install to lib or lib64, use -DCMAKE_INSTALL_LIBDIR=
+    when invoking cmake to specify another install location.
+
 You may need to update the libbpf git submodule:
 
 git submodule update --init --recursive
Signature · 1 line
2.49.0
#1 lore raw
Quoted 26 lines · Paul Menzel

There is no need to explicitly set LIB_INSTALL_DIR, as CMake’s module GNUInstallDirs sets it itself from CMAKE_INSTALL_LIBDIR, and takes care of everything, so the line below is enough.

cmake -DLIBBPF_EMBEDDED=OFF -DCMAKE_INSTALL_LIBDIR=lib ..

Note, it’s common to set it to a relative path, but absolute paths are allowed too.

cmake -DLIBBPF_EMBEDDED=OFF -DCMAKE_INSTALL_LIBDIR=/opt/usr/lib64 ..

From the [CMake documentation][1]:

Quoted 7 lines

CMAKE_INSTALL_<dir>

Destination for files of a given type. This value may be passed to the DESTINATION options of install() commands for the corresponding file type. It should be a path relative to the installation prefix so that it can be converted to an absolute path in a relocatable way.

Quoted 5 lines

While absolute paths are allowed, they are not recommended as they do not work with the cmake --install command's --prefix option, or with the cpack installer generators. In particular, there is no need to make paths absolute by prepending CMAKE_INSTALL_PREFIX; this prefix is used by default if the DESTINATION is a relative path.

Quoted 8 lines

So, remove the custom handling from CMakeLists.txt. Also, update README and mention the option.

[1]: https://cmake.org/cmake/help/v3.31/module/GNUInstallDirs.html

Fixes a2abd9482162 ("CMakeList.txt: Respect CMAKE_INSTALL_LIBDIR")

Sorry Paul, left you hanging here. Above seems reasonable - any issues with this from anyone (I've cc'ed Ben who made changes in this area before)?

If not I'll apply early next week. Thanks!

Alan

Quoted 43 lines
---
 CMakeLists.txt | 5 -----
 README         | 4 ++++
 2 files changed, 4 insertions(+), 5 deletions(-)
CMakeLists.txt +0 -5
index eb87300..844ab61 100644
@@ -23,7 +23,6 @@ endif()
 
 # 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
@@ -75,10 +74,6 @@ 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()
 
-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
 # COMPACT_NEED_REALLOCARRAY to be set
README +4 -0
index a938266..fb92d68 100644
@@ -18,6 +18,10 @@ cmake Options:
     Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
     when invoking cmake to specify another install location.
 
+  -DCMAKE_INSTALL_LIBDIR
+    Default is to install to lib or lib64, use -DCMAKE_INSTALL_LIBDIR=
+    when invoking cmake to specify another install location.
+
 You may need to update the libbpf git submodule:
 
 git submodule update --init --recursive
Applied
#2 lore raw
In reply to Paul Menzel
Quoted 26 lines · Paul Menzel

There is no need to explicitly set LIB_INSTALL_DIR, as CMake’s module GNUInstallDirs sets it itself from CMAKE_INSTALL_LIBDIR, and takes care of everything, so the line below is enough.

cmake -DLIBBPF_EMBEDDED=OFF -DCMAKE_INSTALL_LIBDIR=lib ..

Note, it’s common to set it to a relative path, but absolute paths are allowed too.

cmake -DLIBBPF_EMBEDDED=OFF -DCMAKE_INSTALL_LIBDIR=/opt/usr/lib64 ..

From the [CMake documentation][1]:

Quoted 7 lines

CMAKE_INSTALL_<dir>

Destination for files of a given type. This value may be passed to the DESTINATION options of install() commands for the corresponding file type. It should be a path relative to the installation prefix so that it can be converted to an absolute path in a relocatable way.

Quoted 5 lines

While absolute paths are allowed, they are not recommended as they do not work with the cmake --install command's --prefix option, or with the cpack installer generators. In particular, there is no need to make paths absolute by prepending CMAKE_INSTALL_PREFIX; this prefix is used by default if the DESTINATION is a relative path.

Quoted 8 lines

So, remove the custom handling from CMakeLists.txt. Also, update README and mention the option.

[1]: https://cmake.org/cmake/help/v3.31/module/GNUInstallDirs.html

Fixes a2abd9482162 ("CMakeList.txt: Respect CMAKE_INSTALL_LIBDIR")

Applied to the next branch of

https://git.kernel.org/pub/scm/devel/pahole/pahole.git/

Thank you!

Quoted 43 lines
---
 CMakeLists.txt | 5 -----
 README         | 4 ++++
 2 files changed, 4 insertions(+), 5 deletions(-)
CMakeLists.txt +0 -5
index eb87300..844ab61 100644
@@ -23,7 +23,6 @@ endif()
 
 # 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
@@ -75,10 +74,6 @@ 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()
 
-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
 # COMPACT_NEED_REALLOCARRAY to be set
README +4 -0
index a938266..fb92d68 100644
@@ -18,6 +18,10 @@ cmake Options:
     Default is to install to /usr/local, use -DCMAKE_INSTALL_PREFIX=
     when invoking cmake to specify another install location.
 
+  -DCMAKE_INSTALL_LIBDIR
+    Default is to install to lib or lib64, use -DCMAKE_INSTALL_LIBDIR=
+    when invoking cmake to specify another install location.
+
 You may need to update the libbpf git submodule:
 
 git submodule update --init --recursive