mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 01:34:25 +00:00 
			
		
		
		
	Refactor the lua dependency checking.
This is in preparation for the next step, which is to find a suitable lua interpreter, rather than just erroring when an interpreter is found but doesn't have the necessary dependencies. Helped-by: John Szakmeister <john@szakmeister.net>
This commit is contained in:
		
				
					committed by
					
						
						John Szakmeister
					
				
			
			
				
	
			
			
			
						parent
						
							e47968537c
						
					
				
				
					commit
					6f0d3c0e77
				
			@@ -98,29 +98,15 @@ if(NOT EXISTS ${LUA_PRG})
 | 
				
			|||||||
  find_program(LUA_PRG lua)
 | 
					  find_program(LUA_PRG lua)
 | 
				
			||||||
endif()
 | 
					endif()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if(EXISTS ${LUA_PRG})
 | 
					include(LuaHelpers)
 | 
				
			||||||
  message(STATUS "Using the lua interpreter ${LUA_PRG}")
 | 
					set(LUA_DEPENDENCIES lpeg cmsgpack)
 | 
				
			||||||
else()
 | 
					check_lua_deps(${LUA_PRG} "${LUA_DEPENDENCIES}" LUA_PRG_WORKS)
 | 
				
			||||||
  message(FATAL_ERROR "A lua interpreter is required for building the Neovim")
 | 
					
 | 
				
			||||||
 | 
					if(NOT LUA_PRG_WORKS)
 | 
				
			||||||
 | 
					  message(FATAL_ERROR "A suitable Lua interpreter was not found")
 | 
				
			||||||
endif()
 | 
					endif()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
execute_process(COMMAND ${LUA_PRG} -e "require('lpeg')"
 | 
					message(STATUS "Using the Lua interpreter ${LUA_PRG}")
 | 
				
			||||||
                RESULT_VARIABLE LUA_LPEG_MISSING
 | 
					 | 
				
			||||||
                ERROR_QUIET)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if(${LUA_LPEG_MISSING})
 | 
					 | 
				
			||||||
  message(FATAL_ERROR
 | 
					 | 
				
			||||||
          "The 'lpeg' lua package is required for building Neovim")
 | 
					 | 
				
			||||||
endif()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
execute_process(COMMAND ${LUA_PRG} -e "require('cmsgpack')"
 | 
					 | 
				
			||||||
                RESULT_VARIABLE LUA_MSGPACK_MISSING
 | 
					 | 
				
			||||||
                ERROR_QUIET)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
if(${LUA_MSGPACK_MISSING})
 | 
					 | 
				
			||||||
  message(FATAL_ERROR
 | 
					 | 
				
			||||||
         "The 'cmsgpack' lua package is required for building Neovim")
 | 
					 | 
				
			||||||
endif()
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
add_subdirectory(config)
 | 
					add_subdirectory(config)
 | 
				
			||||||
add_subdirectory(src/nvim)
 | 
					add_subdirectory(src/nvim)
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										38
									
								
								cmake/LuaHelpers.cmake
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								cmake/LuaHelpers.cmake
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
				
			|||||||
 | 
					#
 | 
				
			||||||
 | 
					# Functions to help checking for a Lua interpreter
 | 
				
			||||||
 | 
					#
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Check if a module is available in Lua
 | 
				
			||||||
 | 
					function(check_lua_module LUA_PRG_PATH MODULE RESULT_VAR)
 | 
				
			||||||
 | 
					  execute_process(COMMAND ${LUA_PRG_PATH} -e "require('${MODULE}')"
 | 
				
			||||||
 | 
					    RESULT_VARIABLE module_missing
 | 
				
			||||||
 | 
					    ERROR_QUIET)
 | 
				
			||||||
 | 
					  if(module_missing)
 | 
				
			||||||
 | 
					    message(STATUS
 | 
				
			||||||
 | 
					      "[${LUA_PRG_PATH}] The '${MODULE}' lua package is required for building Neovim")
 | 
				
			||||||
 | 
					    set(${RESULT_VAR} False PARENT_SCOPE)
 | 
				
			||||||
 | 
					  else()
 | 
				
			||||||
 | 
					    set(${RESULT_VAR} True PARENT_SCOPE)
 | 
				
			||||||
 | 
					  endif()
 | 
				
			||||||
 | 
					endfunction()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Check Lua interpreter for dependencies
 | 
				
			||||||
 | 
					function(check_lua_deps LUA_PRG_PATH MODULES RESULT_VAR)
 | 
				
			||||||
 | 
					  # Check if the lua interpreter at the given path
 | 
				
			||||||
 | 
					  # satisfies all Neovim dependencies
 | 
				
			||||||
 | 
					  message(STATUS "Checking Lua interpreter ${LUA_PRG_PATH}")
 | 
				
			||||||
 | 
					  if(NOT EXISTS ${LUA_PRG_PATH})
 | 
				
			||||||
 | 
					    message(STATUS
 | 
				
			||||||
 | 
					      "[${LUA_PRG_PATH}] file not found")
 | 
				
			||||||
 | 
					  endif()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  foreach(module ${MODULES})
 | 
				
			||||||
 | 
					    check_lua_module(${LUA_PRG_PATH} ${module} has_module)
 | 
				
			||||||
 | 
					    if(NOT has_module)
 | 
				
			||||||
 | 
					      set(${RESULT_VAR} False PARENT_SCOPE)
 | 
				
			||||||
 | 
					      return()
 | 
				
			||||||
 | 
					    endif()
 | 
				
			||||||
 | 
					  endforeach()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  set(${RESULT_VAR} True PARENT_SCOPE)
 | 
				
			||||||
 | 
					endfunction()
 | 
				
			||||||
		Reference in New Issue
	
	Block a user