From 8f7fae7a78dbdd416d068a60588d7c2aa93c5586 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 3 Apr 2020 12:39:16 +0800 Subject: [PATCH] cmake: add find_make() function it's a shorthand for finding "make" or "gmake" (for FreeBSD), and set the path to the executable and the command to use in the generated "Makefile" or whatever build script generated by cmake. Signed-off-by: Kefu Chai --- cmake/modules/BuildDPDK.cmake | 13 ++----------- cmake/modules/BuildSPDK.cmake | 13 ++----------- cmake/modules/FindMake.cmake | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 22 deletions(-) create mode 100644 cmake/modules/FindMake.cmake diff --git a/cmake/modules/BuildDPDK.cmake b/cmake/modules/BuildDPDK.cmake index a830a99a4b184..e9d16d0709b48 100644 --- a/cmake/modules/BuildDPDK.cmake +++ b/cmake/modules/BuildDPDK.cmake @@ -1,8 +1,4 @@ function(do_build_dpdk dpdk_dir) - find_program(MAKE_EXECUTABLE NAMES gmake make) - if(NOT MAKE_EXECUTABLE) - message(FATAL_ERROR "Can't find make") - endif() # mk/machine/native/rte.vars.mk # rte_cflags are extracted from mk/machine/${machine}/rte.vars.mk # only 3 of them have -march= defined, so copying them here. @@ -62,6 +58,8 @@ function(do_build_dpdk dpdk_dir) set(target "${arch}-${machine_tmpl}-${execenv}-${toolchain}") + include(FindMake) + find_make("MAKE_EXECUTABLE" "make_cmd") execute_process( COMMAND ${MAKE_EXECUTABLE} showconfigs WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/src/spdk/dpdk @@ -75,13 +73,6 @@ function(do_build_dpdk dpdk_dir) "\"${target}\" not listed in ${supported_targets}") endif() - if(CMAKE_MAKE_PROGRAM MATCHES "make") - # try to inherit command line arguments passed by parent "make" job - set(make_cmd "$(MAKE)") - else() - set(make_cmd "${MAKE_EXECUTABLE}") - endif() - if(Seastar_DPDK AND WITH_SPDK) message(FATAL_ERROR "not able to build DPDK with " "both Seastar_DPDK and WITH_SPDK enabled") diff --git a/cmake/modules/BuildSPDK.cmake b/cmake/modules/BuildSPDK.cmake index 2e9b31b8d0d2e..2d78fc917bf2b 100644 --- a/cmake/modules/BuildSPDK.cmake +++ b/cmake/modules/BuildSPDK.cmake @@ -9,17 +9,8 @@ macro(build_spdk) find_package(aio REQUIRED) find_package(uuid REQUIRED) endif() - - find_program(MAKE_EXECUTABLE NAMES gmake make) - if(NOT MAKE_EXECUTABLE) - message(FATAL_ERROR "Can't find make") - endif() - if(CMAKE_MAKE_PROGRAM MATCHES "make") - # try to inherit command line arguments passed by parent "make" job - set(make_cmd "$(MAKE)") - else() - set(make_cmd "${MAKE_EXECUTABLE}") - endif() + include(FindMake) + find_make("MAKE_EXECUTABLE" "make_cmd") set(spdk_CFLAGS "-fPIC") include(CheckCCompilerFlag) diff --git a/cmake/modules/FindMake.cmake b/cmake/modules/FindMake.cmake new file mode 100644 index 0000000000000..2a57a8df7f45e --- /dev/null +++ b/cmake/modules/FindMake.cmake @@ -0,0 +1,17 @@ +function(find_make make_exe make_cmd) + # make_exe the name of the variable whose value will be the path to "make" + # 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() + set(${make_exe} "${MAKE_EXECUTABLE}" PARENT_SCOPE) + if(CMAKE_MAKE_PROGRAM MATCHES "make") + # try to inherit command line arguments passed by parent "make" job + set(${make_cmd} "$(MAKE)" PARENT_SCOPE) + else() + set(${make_cmd} "${MAKE_EXECUTABLE}" PARENT_SCOPE) + endif() +endfunction() -- 2.39.5