From ea9b197d361d8e3cd95ce72706278646c33d1b71 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 7 Jan 2026 19:13:41 +0300 Subject: [PATCH] build: improve FindMagic.cmake module (#2610) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now it properly fails if libmagic is not installed in the system. The error message would look like: ``` CMake Error at cmake/modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find Magic (missing: LIBMAGIC_LIBRARY LIBMAGIC_INCLUDE_DIR) (Required is at least version "5.39") Call Stack (most recent call first): cmake/modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE) cmake/modules/FindMagic.cmake:5 (find_package_handle_standard_args) cmake/build_helpers.cmake:971 (find_package) CMakeLists.txt:81 (addBundledLibraries) ``` ### Problem description The current `FindMagic.cmake` module doesn't properly report failure about absent libmagic libs and #includes. This behavior leads to the compile errors on the build stage (possibly after some time, which will be simply wasted). This Find module should set the `Magic_FOUND` variable and handle all required variables( LIBMAGIC_INCLUDE_DIR and LIBMAGIC_LIBRARY) to present. But the current module sets the `libmagic_FOUND` variable, so the CMake assumes that it is found something. This behaviour should also be handled by `find_package_handle_standard_args()` ("FPHSA"), and it is actually handled, but as we requested the `Magic` package to be required, the former function ("FPHSA") didn't stop the configure process. ### Implementation description - Clean up the unused ifs, as "FPHSA" already done it better. - Use the proper name for "FPHSA" so it could set the proper `Magic_FOUND` and could make sure that the requested package is `REQUIRED`. ### Screenshots Before: ``` -- Could NOT find libmagic (missing: LIBMAGIC_LIBRARY LIBMAGIC_INCLUDE_DIR) ``` изображение After: ``` CMake Error at cmake/modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find Magic (missing: LIBMAGIC_LIBRARY LIBMAGIC_INCLUDE_DIR) (Required is at least version "5.39") Call Stack (most recent call first): cmake/modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE) cmake/modules/FindMagic.cmake:5 (find_package_handle_standard_args) cmake/build_helpers.cmake:971 (find_package) CMakeLists.txt:81 (addBundledLibraries) ``` ### Additional things Closes #2244 . --- cmake/modules/FindMagic.cmake | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/cmake/modules/FindMagic.cmake b/cmake/modules/FindMagic.cmake index 936701be7..c2f699df5 100644 --- a/cmake/modules/FindMagic.cmake +++ b/cmake/modules/FindMagic.cmake @@ -2,11 +2,7 @@ find_path(LIBMAGIC_INCLUDE_DIR magic.h) find_library(LIBMAGIC_LIBRARY NAMES magic) -if (LIBMAGIC_INCLUDE_DIR AND LIBMAGIC_LIBRARY) - set(LIBMAGIC_FOUND TRUE) -endif (LIBMAGIC_INCLUDE_DIR AND LIBMAGIC_LIBRARY) - -find_package_handle_standard_args("libmagic" DEFAULT_MSG +find_package_handle_standard_args(Magic DEFAULT_MSG LIBMAGIC_LIBRARY LIBMAGIC_INCLUDE_DIR ) @@ -14,5 +10,5 @@ find_package_handle_standard_args("libmagic" DEFAULT_MSG mark_as_advanced( LIBMAGIC_INCLUDE_DIR LIBMAGIC_LIBRARY - LIBMAGIC_FOUND -) \ No newline at end of file + Magic_FOUND +)