mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Refactor declaration generation
- Call compiler from CMake instead of lua script to generate a preprocessor file - allows for better/early error detection if the compiler fails - Preprocessor files are saved along with the headers as .i files - Accept preprocessor lines with trailing chars after # as is the case in Clang/Windows - The fourth argument to gendeclarations.lua is now the path to the proprocessor output file
This commit is contained in:
parent
75524dbf9a
commit
05d72e9826
@ -3,9 +3,8 @@
|
|||||||
local fname = arg[1]
|
local fname = arg[1]
|
||||||
local static_fname = arg[2]
|
local static_fname = arg[2]
|
||||||
local non_static_fname = arg[3]
|
local non_static_fname = arg[3]
|
||||||
local cpp = arg[4]
|
local preproc_fname = arg[4]
|
||||||
|
|
||||||
cpp = cpp:gsub(' %-DINCLUDE_GENERATED_DECLARATIONS ', ' ')
|
|
||||||
|
|
||||||
local lpeg = require('lpeg')
|
local lpeg = require('lpeg')
|
||||||
|
|
||||||
@ -156,15 +155,14 @@ local pattern = concat(
|
|||||||
if fname == '--help' then
|
if fname == '--help' then
|
||||||
print'Usage:'
|
print'Usage:'
|
||||||
print()
|
print()
|
||||||
print' gendeclarations.lua definitions.c static.h non-static.h "cc -E …"'
|
print' gendeclarations.lua definitions.c static.h non-static.h preprocessor.i'
|
||||||
os.exit()
|
os.exit()
|
||||||
end
|
end
|
||||||
|
|
||||||
local pipe = io.popen(cpp .. ' -DDO_NOT_DEFINE_EMPTY_ATTRIBUTES ' .. fname, 'r')
|
local preproc_f = io.open(preproc_fname)
|
||||||
local text = pipe:read('*a')
|
local text = preproc_f:read("*all")
|
||||||
if not pipe:close() then
|
preproc_f:close()
|
||||||
os.exit(2)
|
|
||||||
end
|
|
||||||
|
|
||||||
local header = [[
|
local header = [[
|
||||||
#ifndef DEFINE_FUNC_ATTRIBUTES
|
#ifndef DEFINE_FUNC_ATTRIBUTES
|
||||||
@ -181,7 +179,7 @@ local footer = [[
|
|||||||
local non_static = header
|
local non_static = header
|
||||||
local static = header
|
local static = header
|
||||||
|
|
||||||
local filepattern = '^# %d+ "[^"]-/?([^"/]+)"'
|
local filepattern = '^#%a* %d+ "[^"]-/?([^"/]+)"'
|
||||||
local curfile
|
local curfile
|
||||||
|
|
||||||
init = 0
|
init = 0
|
||||||
|
@ -109,13 +109,15 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
get_directory_property(gen_cdefs COMPILE_DEFINITIONS)
|
get_directory_property(gen_cdefs COMPILE_DEFINITIONS)
|
||||||
foreach(gen_cdef ${gen_cdefs})
|
foreach(gen_cdef ${gen_cdefs} DO_NOT_DEFINE_EMPTY_ATTRIBUTES)
|
||||||
set(gen_cflags "${gen_cflags} -D${gen_cdef}")
|
if(NOT "${gen_cdef}" MATCHES "INCLUDE_GENERATED_DECLARATIONS")
|
||||||
|
list(APPEND gen_cflags "-D${gen_cdef}")
|
||||||
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
get_directory_property(gen_includes INCLUDE_DIRECTORIES)
|
get_directory_property(gen_includes INCLUDE_DIRECTORIES)
|
||||||
foreach(gen_include ${gen_includes})
|
foreach(gen_include ${gen_includes})
|
||||||
set(gen_cflags "${gen_cflags} -I${gen_include}")
|
list(APPEND gen_cflags "-I${gen_include}")
|
||||||
endforeach()
|
endforeach()
|
||||||
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
|
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
|
||||||
set(gen_cflags "${gen_cflags} ${CMAKE_C_FLAGS_${build_type}} ${CMAKE_C_FLAGS}")
|
set(gen_cflags "${gen_cflags} ${CMAKE_C_FLAGS_${build_type}} ${CMAKE_C_FLAGS}")
|
||||||
@ -132,11 +134,12 @@ foreach(sfile ${NEOVIM_SOURCES}
|
|||||||
endif()
|
endif()
|
||||||
set(gf1 "${GENERATED_DIR}/${r}.c.generated.h")
|
set(gf1 "${GENERATED_DIR}/${r}.c.generated.h")
|
||||||
set(gf2 "${GENERATED_INCLUDES_DIR}/${r}.h.generated.h")
|
set(gf2 "${GENERATED_INCLUDES_DIR}/${r}.h.generated.h")
|
||||||
|
set(gf3 "${GENERATED_DIR}/${r}.i")
|
||||||
|
separate_arguments(C_FLAGS_ARRAY UNIX_COMMAND ${CMAKE_C_FLAGS})
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT "${gf1}" "${gf2}"
|
OUTPUT "${gf1}" "${gf2}"
|
||||||
COMMAND "${LUA_PRG}" "${HEADER_GENERATOR}"
|
COMMAND ${CMAKE_C_COMPILER} ${sfile} -o ${gf3} ${gen_cflags} -E ${C_FLAGS_ARRAY}
|
||||||
"${sfile}" "${gf1}" "${gf2}"
|
COMMAND "${LUA_PRG}" "${HEADER_GENERATOR}" "${sfile}" "${gf1}" "${gf2}" "${gf3}"
|
||||||
"${CMAKE_C_COMPILER} ${gen_cflags} -E"
|
|
||||||
DEPENDS "${HEADER_GENERATOR}" "${sfile}"
|
DEPENDS "${HEADER_GENERATOR}" "${sfile}"
|
||||||
)
|
)
|
||||||
list(APPEND NEOVIM_GENERATED_SOURCES "${gf1}")
|
list(APPEND NEOVIM_GENERATED_SOURCES "${gf1}")
|
||||||
|
Loading…
Reference in New Issue
Block a user