Skip to content

Commit 448633e

Browse files
committed
cmake: use find_program(REQUIRED) to fail early on missing programs
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 <[email protected]>
1 parent edf8b22 commit 448633e

File tree

4 files changed

+21
-34
lines changed

4 files changed

+21
-34
lines changed

CMakeLists.txt

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ if(WITH_CCACHE)
7676
if(CMAKE_C_COMPILER_LAUNCHER OR CMAKE_CXX_COMPILER_LAUNCHER)
7777
message(WARNING "Compiler launcher already set. stop configuring ccache")
7878
else()
79-
find_program(CCACHE_EXECUTABLE ccache)
80-
if(NOT CCACHE_EXECUTABLE)
81-
message(FATAL_ERROR "Can't find ccache. Is it installed?")
82-
endif()
79+
find_program(CCACHE_EXECUTABLE ccache
80+
REQUIRED)
8381
message(STATUS "Building with ccache: ${CCACHE_EXECUTABLE}, CCACHE_DIR=$ENV{CCACHE_DIR}")
8482
set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
8583
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE})
@@ -88,10 +86,8 @@ endif(WITH_CCACHE)
8886

8987
option(WITH_SCCACHE "Build with sccache.")
9088
if(WITH_SCCACHE)
91-
find_program(SCCACHE_EXECUTABLE sccache)
92-
if(NOT SCCACHE_EXECUTABLE)
93-
message(FATAL_ERROR "Can't find sccache. Is it installed?")
94-
endif()
89+
find_program(SCCACHE_EXECUTABLE sccache
90+
REQUIRED)
9591
if(NOT NINJA_MAX_COMPILE_JOBS)
9692
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.19")
9793
execute_process(
@@ -123,10 +119,8 @@ endif(WITH_SCCACHE)
123119
option(WITH_MANPAGE "Build man pages." ON)
124120
if(WITH_MANPAGE)
125121
find_program(SPHINX_BUILD
126-
NAMES sphinx-build sphinx-build-3)
127-
if(NOT SPHINX_BUILD)
128-
message(FATAL_ERROR "Can't find sphinx-build.")
129-
endif(NOT SPHINX_BUILD)
122+
NAMES sphinx-build sphinx-build-3
123+
REQUIRED)
130124
endif(WITH_MANPAGE)
131125

132126
include_directories(
@@ -670,10 +664,8 @@ option(WITH_LTTNG "LTTng tracing is enabled" ON)
670664
if(${WITH_LTTNG})
671665
find_package(LTTngUST REQUIRED)
672666
find_program(LTTNG_GEN_TP
673-
lttng-gen-tp)
674-
if(NOT LTTNG_GEN_TP)
675-
message(FATAL_ERROR "Can't find lttng-gen-tp.")
676-
endif()
667+
lttng-gen-tp
668+
REQUIRED)
677669
endif(${WITH_LTTNG})
678670

679671
option(WITH_OSD_INSTRUMENT_FUNCTIONS OFF)
@@ -808,10 +800,8 @@ include_directories(BEFORE SYSTEM ${Boost_INCLUDE_DIRS})
808800
option(WITH_MGR_DASHBOARD_FRONTEND "Build the mgr/dashboard frontend using `npm`" ON)
809801
option(WITH_SYSTEM_NPM "Assume that dashboard build tools already installed through packages" OFF)
810802
if(WITH_SYSTEM_NPM)
811-
find_program(NPM_EXECUTABLE npm)
812-
if(NOT NPM_EXECUTABLE)
813-
message(FATAL_ERROR "Can't find npm.")
814-
endif()
803+
find_program(NPM_EXECUTABLE npm
804+
REQUIRED)
815805
endif()
816806
set(DASHBOARD_FRONTEND_LANGS "ALL" CACHE STRING
817807
"List of comma separated ceph-dashboard frontend languages to build. \

cmake/modules/FindMake.cmake

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ function(find_make make_exe make_cmd)
33
# executable
44
# make_cmd the name of the variable whose value will be the command to
55
# used in the generated build script executed by the cmake generator
6-
find_program(MAKE_EXECUTABLE NAMES gmake make)
7-
if(NOT MAKE_EXECUTABLE)
8-
message(FATAL_ERROR "Can't find make")
9-
endif()
6+
find_program(MAKE_EXECUTABLE
7+
NAMES gmake make
8+
REQUIRED)
109
set(${make_exe} "${MAKE_EXECUTABLE}" PARENT_SCOPE)
1110
if(CMAKE_MAKE_PROGRAM MATCHES "make")
1211
# try to inherit command line arguments passed by parent "make" job

src/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,8 @@ endif()
290290

291291
option(ENABLE_COVERAGE "Coverage is enabled" OFF)
292292
if(${ENABLE_COVERAGE})
293-
find_program(HAVE_GCOV gcov)
294-
if(NOT HAVE_GCOV)
295-
message(FATAL_ERROR "Coverage Enabled but gcov Not Found")
296-
endif()
293+
find_program(HAVE_GCOV gcov
294+
REQUIRED)
297295
add_compile_options(
298296
--coverage
299297
-O0)
@@ -1000,7 +998,8 @@ if(WITH_NVMEOF_GATEWAY_MONITOR_CLIENT)
1000998

1001999
set(_REFLECTION grpc++_reflection)
10021000
if(CMAKE_CROSSCOMPILING)
1003-
find_program(_PROTOBUF_PROTOC protoc)
1001+
find_program(_PROTOBUF_PROTOC protoc
1002+
REQUIRED)
10041003
else()
10051004
set(_PROTOBUF_PROTOC $<TARGET_FILE:protobuf::protoc>)
10061005
endif()
@@ -1011,7 +1010,8 @@ if(WITH_NVMEOF_GATEWAY_MONITOR_CLIENT)
10111010
message(STATUS "Using gRPC ${gRPC_VERSION}")
10121011
set(_GRPC_GRPCPP gRPC::grpc++)
10131012
if(CMAKE_CROSSCOMPILING)
1014-
find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin)
1013+
find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin
1014+
REQUIRED)
10151015
else()
10161016
set(_GRPC_CPP_PLUGIN_EXECUTABLE $<TARGET_FILE:gRPC::grpc_cpp_plugin>)
10171017
endif()

src/rgw/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
find_program(GPERF gperf)
2-
if(NOT GPERF)
3-
message(FATAL_ERROR "Can't find gperf")
4-
endif()
1+
find_program(GPERF gperf
2+
REQUIRED)
53

64
if(WITH_RADOSGW_BACKTRACE_LOGGING)
75
add_definitions(-D_BACKTRACE_LOGGING)

0 commit comments

Comments
 (0)