Skip to content

Add option to disable library installation to avoid GNUInstallDirs warning in submodule usage #218

@vpetrigo

Description

@vpetrigo

When using this library as a submodule in a parent CMake project, the unconditional inclusion of GNUInstallDirs generates a warning during project configuration if no language has been enabled yet in the parent project:

CMake Warning (dev) at /tools/cmake/share/cmake-4.2/Modules/GNUInstallDirs.cmake:433 (message):
  Unable to determine default CMAKE_INSTALL_LIBDIR directory because no
  target architecture is known.  Please enable at least one language before
  including GNUInstallDirs.
Call Stack (most recent call first):
  C:/Users/vladi/tools/cmake/share/cmake-4.2/Modules/GNUInstallDirs.cmake:276 (_GNUInstallDirs_LIBDIR_get_default)
  C:/Users/vladi/tools/cmake/share/cmake-4.2/Modules/GNUInstallDirs.cmake:276 (cmake_language)
  C:/Users/vladi/tools/cmake/share/cmake-4.2/Modules/GNUInstallDirs.cmake:525 (_GNUInstallDirs_cache_path)
  cmake-build/_deps/printf_library-src/CMakeLists.txt:168 (include)

Additionally, when using the library as a submodule, the installation commands are often unnecessary since the library is built directly as part of the parent project.

Proposed Solution:

Introduce a CMake option to control whether installation commands should be processed:

option(PRINTF_INSTALL_LIBRARY "Install printf library" OFF)

if (PRINTF_INSTALL_LIBRARY)
    include(GNUInstallDirs)
    # ... the rest of the installation commands ...
endif ()

Those changes are:

  • Eliminates the warning when using the library as a submodule
  • Allows users to opt-in to installation when needed
  • Follows common CMake practices for libraries that support both standalone and embedded usage
  • Slightly improves configuration time for projects that don't need installation

If this change is acceptable, I'm happy to prepare a pull request implementing it. 😊

Metadata

Metadata

Assignees

Labels

resolved-on-developA changeset fixing this issue has been commiutted to the development branch

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions