]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: use find_program(REQUIRED) to fail early on missing programs 63975/head
authorKefu Chai <tchaikov@gmail.com>
Tue, 17 Jun 2025 09:22:16 +0000 (17:22 +0800)
committerKefu Chai <tchaikov@gmail.com>
Tue, 17 Jun 2025 09:30:10 +0000 (17:30 +0800)
Since upgrading minimum CMake version to 3.22.1 (commit 469d82a1), we can
now use find_program(REQUIRED) which was introduced in CMake 3.18.

This change replaces manual FATAL_ERROR checks with the REQUIRED option
and adds it to programs that are actually needed during the build. This
ensures the build fails early during configuration rather than later
during compilation when missing programs are invoked.

Changes:
- Replace find_program() + message(FATAL_ERROR) patterns with REQUIRED
- Add REQUIRED to programs that are used during build but previously
  had no error checking

Reference: https://cmake.org/cmake/help/latest/command/find_program.html

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
CMakeLists.txt
cmake/modules/FindMake.cmake
src/CMakeLists.txt
src/rgw/CMakeLists.txt

index fde3fed781a375b7aca7842790f03d6accdb27ad..4fcb87c631f7ebc3639afe936fe02ec85cf35737 100644 (file)
@@ -76,10 +76,8 @@ if(WITH_CCACHE)
   if(CMAKE_C_COMPILER_LAUNCHER OR CMAKE_CXX_COMPILER_LAUNCHER)
     message(WARNING "Compiler launcher already set. stop configuring ccache")
   else()
-    find_program(CCACHE_EXECUTABLE ccache)
-    if(NOT CCACHE_EXECUTABLE)
-      message(FATAL_ERROR "Can't find ccache. Is it installed?")
-    endif()
+    find_program(CCACHE_EXECUTABLE ccache
+      REQUIRED)
     message(STATUS "Building with ccache: ${CCACHE_EXECUTABLE}, CCACHE_DIR=$ENV{CCACHE_DIR}")
     set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
     set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
@@ -88,10 +86,8 @@ endif(WITH_CCACHE)
 
 option(WITH_SCCACHE "Build with sccache.")
 if(WITH_SCCACHE)
-  find_program(SCCACHE_EXECUTABLE sccache)
-  if(NOT SCCACHE_EXECUTABLE)
-    message(FATAL_ERROR "Can't find sccache. Is it installed?")
-  endif()
+  find_program(SCCACHE_EXECUTABLE sccache
+    REQUIRED)
   if(NOT NINJA_MAX_COMPILE_JOBS)
     if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.19")
       execute_process(
@@ -123,10 +119,8 @@ endif(WITH_SCCACHE)
 option(WITH_MANPAGE "Build man pages." ON)
 if(WITH_MANPAGE)
   find_program(SPHINX_BUILD
-    NAMES sphinx-build sphinx-build-3)
-  if(NOT SPHINX_BUILD)
-    message(FATAL_ERROR "Can't find sphinx-build.")
-  endif(NOT SPHINX_BUILD)
+    NAMES sphinx-build sphinx-build-3
+    REQUIRED)
 endif(WITH_MANPAGE)
 
 include_directories(
@@ -670,10 +664,8 @@ option(WITH_LTTNG "LTTng tracing is enabled" ON)
 if(${WITH_LTTNG})
   find_package(LTTngUST REQUIRED)
   find_program(LTTNG_GEN_TP
-    lttng-gen-tp)
-  if(NOT LTTNG_GEN_TP)
-    message(FATAL_ERROR "Can't find lttng-gen-tp.")
-  endif()
+    lttng-gen-tp
+    REQUIRED)
 endif(${WITH_LTTNG})
 
 option(WITH_OSD_INSTRUMENT_FUNCTIONS OFF)
@@ -808,10 +800,8 @@ include_directories(BEFORE SYSTEM ${Boost_INCLUDE_DIRS})
 option(WITH_MGR_DASHBOARD_FRONTEND "Build the mgr/dashboard frontend using `npm`" ON)
 option(WITH_SYSTEM_NPM "Assume that dashboard build tools already installed through packages" OFF)
 if(WITH_SYSTEM_NPM)
-  find_program(NPM_EXECUTABLE npm)
-  if(NOT NPM_EXECUTABLE)
-    message(FATAL_ERROR "Can't find npm.")
-  endif()
+  find_program(NPM_EXECUTABLE npm
+    REQUIRED)
 endif()
 set(DASHBOARD_FRONTEND_LANGS "ALL" CACHE STRING
   "List of comma separated ceph-dashboard frontend languages to build. \
index 2a57a8df7f45e9370028213dd7cee6c462dc459f..755e127a30ba8c61237f93ed7c96b164f2f6867c 100644 (file)
@@ -3,10 +3,9 @@ function(find_make make_exe make_cmd)
   #          executable
   # make_cmd the name of the variable whose value will be the command to
   #          used in the generated build script executed by the cmake generator
-  find_program(MAKE_EXECUTABLE NAMES gmake make)
-  if(NOT MAKE_EXECUTABLE)
-    message(FATAL_ERROR "Can't find make")
-  endif()
+  find_program(MAKE_EXECUTABLE
+    NAMES gmake make
+    REQUIRED)
   set(${make_exe} "${MAKE_EXECUTABLE}" PARENT_SCOPE)
   if(CMAKE_MAKE_PROGRAM MATCHES "make")
     # try to inherit command line arguments passed by parent "make" job
index 99b1456a592656d20ad513df3ab6137df999257e..3b6dfc473ded4a572b1ff24dbad02a8f945e72d6 100644 (file)
@@ -290,10 +290,8 @@ endif()
 
 option(ENABLE_COVERAGE "Coverage is enabled" OFF)
 if(${ENABLE_COVERAGE})
-  find_program(HAVE_GCOV gcov)
-  if(NOT HAVE_GCOV)
-    message(FATAL_ERROR "Coverage Enabled but gcov Not Found")
-  endif()
+  find_program(HAVE_GCOV gcov
+    REQUIRED)
   add_compile_options(
     --coverage
     -O0)
@@ -1000,7 +998,8 @@ if(WITH_NVMEOF_GATEWAY_MONITOR_CLIENT)
 
   set(_REFLECTION grpc++_reflection)
   if(CMAKE_CROSSCOMPILING)
-    find_program(_PROTOBUF_PROTOC protoc)
+    find_program(_PROTOBUF_PROTOC protoc
+      REQUIRED)
   else()
     set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
   endif()
@@ -1011,7 +1010,8 @@ if(WITH_NVMEOF_GATEWAY_MONITOR_CLIENT)
   message(STATUS "Using gRPC ${gRPC_VERSION}")
   set(_GRPC_GRPCPP gRPC::grpc++)
   if(CMAKE_CROSSCOMPILING)
-    find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
+    find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin
+      REQUIRED)
   else()
     set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
   endif()
index f235f18793698d05cb56067f1101d13f04381375..ba8c259869342dab6bdbbb419ac97521b6aa00ca 100644 (file)
@@ -1,7 +1,5 @@
-find_program(GPERF gperf)
-if(NOT GPERF)
-  message(FATAL_ERROR "Can't find gperf")
-endif()
+find_program(GPERF gperf
+  REQUIRED)
 
 if(WITH_RADOSGW_BACKTRACE_LOGGING)
   add_definitions(-D_BACKTRACE_LOGGING)