GNUInutallDirs: Suppress LIBDIR warning for LANGUAGES NONE projects

Projects that explicitly use LANGUAGES NONE, e.g. to install only
data files, have no target architecture, which is intentional.
Default to `lib` without warning.

Fixes: #23461
This commit is contained in:
rewine
2026-08-26 09:38:33 -04:00
committed by Brad King
parent 8b38a5696c
commit 78b4ffa0a7
6 changed files with 28 additions and 6 deletions
+11 -4
View File
@@ -90,6 +90,10 @@ where ``<dir>`` is one of:
:variable:`CMAKE_INSTALL_PREFIX` is ``/usr``.
When cross-compiling, the default is ``lib``.
In projects that enable no languages, e.g.,
``project(... LANGUAGES NONE)``, no target architecture information
is available, so the default is ``lib``.
.. note::
When an alternative installation prefix is specified with the
@@ -444,10 +448,13 @@ set(_GNUInstallDirs_DATAROOTDIR_DEFAULT "share")
function(_GNUInstallDirs_LIBDIR_get_default out_var install_prefix)
set(${out_var} "${_GNUInstallDirs_LIBDIR_DEFAULT}")
if (NOT DEFINED CMAKE_SYSTEM_NAME OR NOT DEFINED CMAKE_SIZEOF_VOID_P)
message(AUTHOR_WARNING
"Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target architecture is known. "
"Please enable at least one language before including GNUInstallDirs.")
if(NOT DEFINED CMAKE_SYSTEM_NAME)
message(AUTHOR_WARNING "Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target platform is known.")
elseif(NOT DEFINED CMAKE_SIZEOF_VOID_P)
get_property(_enabled_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
if(NOT _enabled_languages STREQUAL "NONE")
message(AUTHOR_WARNING "Unable to determine default CMAKE_INSTALL_LIBDIR directory because no target architecture is known.")
endif()
endif()
# When not cross-compiling, detect the host distro's arch-specific 'lib'.
@@ -0,0 +1,10 @@
^CMake Warning \(author\) at .*/Modules/GNUInstallDirs\.cmake:[0-9]+ \(message\):
Unable to determine default CMAKE_INSTALL_LIBDIR directory because no
target architecture is known\.
Call Stack \(most recent call first\):
.*GNUInstallDirs\.cmake:[0-9]+ \(_GNUInstallDirs_LIBDIR_get_default\)
.*GNUInstallDirs\.cmake:[0-9]+ \(cmake_language\)
.*GNUInstallDirs\.cmake:[0-9]+ \(_GNUInstallDirs_cache_path\)
NoArch\.cmake:[0-9]+ \(include\)
CMakeLists\.txt:[0-9]+ \(include\)
This warning is for project developers\. Use -Wno-author to suppress it\.$
@@ -0,0 +1,3 @@
enable_language(C)
unset(CMAKE_SIZEOF_VOID_P)
include(GNUInstallDirs)
@@ -0,0 +1 @@
include(GNUInstallDirs)
@@ -1,7 +1,6 @@
^CMake Warning \(author\) at .*/Modules/GNUInstallDirs\.cmake:[0-9]+ \(message\):
Unable to determine default CMAKE_INSTALL_LIBDIR directory because no
target architecture is known\. Please enable at least one language before
including GNUInstallDirs\.
target platform is known\.
Call Stack \(most recent call first\):
.*GNUInstallDirs\.cmake:[0-9]+ \(_GNUInstallDirs_LIBDIR_get_default\)
.*GNUInstallDirs\.cmake:[0-9]+ \(cmake_language\)
@@ -38,6 +38,8 @@ block()
endblock()
run_cmake(GetAbs)
run_cmake(NoArch)
run_cmake(NoLanguages)
run_cmake(NoSystem)
foreach(case