@@ -962,14 +962,52 @@ def build_env(generator):
962962 return build_env
963963
964964
965+ # Find path to cmake executable, as one of the activated tools, in PATH, or from installed tools.
966+ def find_cmake ():
967+ def locate_cmake_from_tool (tool ):
968+ tool_path = get_required_path ([tool ])
969+ tool_path = tool_path [- 1 ]
970+ cmake_exe = 'cmake.exe' if WINDOWS else 'cmake'
971+ cmake_exe = os .path .join (tool_path , cmake_exe )
972+ if os .path .isfile (cmake_exe ):
973+ return cmake_exe
974+
975+ # 1. If user has activated a specific cmake tool, then use that tool to configure the build.
976+ for tool in reversed (tools ):
977+ if tool .id == 'cmake' and tool .is_active ():
978+ cmake_exe = locate_cmake_from_tool (tool )
979+ if cmake_exe :
980+ info ('Found installed+activated CMake tool at "' + cmake_exe + '"' )
981+ return cmake_exe
982+
983+ # 2. If cmake already exists in PATH, then use that cmake to configure the build.
984+ cmake_exe = which ('cmake' )
985+ if cmake_exe :
986+ info ('Found CMake from PATH at "' + cmake_exe + '"' )
987+ return cmake_exe
988+
989+ # 3. Finally, if user has installed a cmake tool, but has not activated that, then use
990+ # that tool. This enables a single-liner directive
991+ # "emsdk install cmake-4.2.0-rc3-64bit llvm-git-main-64bit" to first install CMake, and
992+ # then use it to configure to build LLVM.
993+ for tool in reversed (tools ):
994+ if tool .id == 'cmake' and tool .is_installed ():
995+ cmake_exe = locate_cmake_from_tool (tool )
996+ if cmake_exe :
997+ info ('Found installed CMake tool at "' + cmake_exe + '"' )
998+ return cmake_exe
999+
1000+ exit_with_error ('Unable to find "cmake" in PATH, or as installed/activated tool! Please install CMake first' )
1001+
1002+
9651003def make_build (build_root , build_type ):
9661004 debug_print ('make_build(build_root=' + build_root + ', build_type=' + build_type + ')' )
9671005 if CPU_CORES > 1 :
9681006 print ('Performing a parallel build with ' + str (CPU_CORES ) + ' cores.' )
9691007 else :
9701008 print ('Performing a singlethreaded build.' )
9711009
972- make = ['cmake' , '--build' , '.' , '--config' , build_type ]
1010+ make = [find_cmake () , '--build' , '.' , '--config' , build_type ]
9731011 if 'Visual Studio' in CMAKE_GENERATOR :
9741012 # Visual Studio historically has had a two-tier problem in its build system design. A single MSBuild.exe instance only governs
9751013 # the build of a single project (.exe/.lib/.dll) in a solution. Passing the -j parameter above will only enable multiple MSBuild.exe
@@ -1011,7 +1049,7 @@ def cmake_configure(generator, build_root, src_root, build_type, extra_cmake_arg
10111049 else :
10121050 generator = []
10131051
1014- cmdline = ['cmake' ] + generator + ['-DCMAKE_BUILD_TYPE=' + build_type , '-DPYTHON_EXECUTABLE=' + sys .executable ]
1052+ cmdline = [find_cmake () ] + generator + ['-DCMAKE_BUILD_TYPE=' + build_type , '-DPYTHON_EXECUTABLE=' + sys .executable ]
10151053 # Target macOS 11.0 Big Sur at minimum, to support older Mac devices.
10161054 # See https://en.wikipedia.org/wiki/MacOS#Hardware_compatibility for min-spec details.
10171055 cmdline += ['-DCMAKE_OSX_DEPLOYMENT_TARGET=11.0' ]
0 commit comments