]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: add find_make() function
authorKefu Chai <kchai@redhat.com>
Fri, 3 Apr 2020 04:39:16 +0000 (12:39 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 3 Apr 2020 05:07:51 +0000 (13:07 +0800)
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 <kchai@redhat.com>
cmake/modules/BuildDPDK.cmake
cmake/modules/BuildSPDK.cmake
cmake/modules/FindMake.cmake [new file with mode: 0644]

index a830a99a4b184c297dca5257b50af4c609ae05c5..e9d16d0709b488889533ccede44d5b631a89ef10 100644 (file)
@@ -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=<arch> 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")
index 2e9b31b8d0d2e7c83adb4521d27006538411d1d5..2d78fc917bf2b04799a025eb99ad8d6ec9d7bc2c 100644 (file)
@@ -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 (file)
index 0000000..2a57a8d
--- /dev/null
@@ -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()