2019-03-12 14:37:57 +00:00
|
|
|
cmake_minimum_required(VERSION 3.5)
|
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(NOT INCLUDES_SOURCE_FILE)
|
2019-03-12 14:37:57 +00:00
|
|
|
message(FATAL_ERROR "Script needs INCLUDES_SOURCE_FILE defined")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if(NOT INCLUDES_BINARY_FILE)
|
2019-03-12 14:37:57 +00:00
|
|
|
message(FATAL_ERROR "Script needs INCLUDES_BINARY_FILE defined")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if(NOT APILC)
|
2019-03-12 14:37:57 +00:00
|
|
|
message(FATAL_ERROR "Script needs APILC defined")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
|
|
|
if(NOT APIUC)
|
2019-03-12 14:37:57 +00:00
|
|
|
message(FATAL_ERROR "Script needs APIUC defined")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
set(ARGC 1)
|
|
|
|
set(ARG_READ NO)
|
|
|
|
|
2021-02-22 18:02:48 +00:00
|
|
|
# For MSVC CMake runs this script from a batch file using || to detect errors,
|
|
|
|
# depending on source path it may quote args, and cause cmd to not understand ||
|
|
|
|
# and pass it as argument to ourself.
|
2019-03-12 14:37:57 +00:00
|
|
|
# Read all the arguments given to CMake; we are looking for -- and everything
|
2021-02-22 18:02:48 +00:00
|
|
|
# that follows, until ||. Those are our api files.
|
2019-03-12 14:37:57 +00:00
|
|
|
while(ARGC LESS CMAKE_ARGC)
|
|
|
|
set(ARG ${CMAKE_ARGV${ARGC}})
|
|
|
|
|
2021-02-22 18:02:48 +00:00
|
|
|
if(ARG STREQUAL "||")
|
|
|
|
set(ARG_READ NO)
|
|
|
|
endif()
|
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(ARG_READ)
|
2019-03-12 14:37:57 +00:00
|
|
|
list(APPEND SCRIPT_API_BINARY_FILES "${ARG}")
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
2020-09-25 11:55:25 +00:00
|
|
|
if(ARG STREQUAL "--")
|
2019-03-12 14:37:57 +00:00
|
|
|
set(ARG_READ YES)
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
math(EXPR ARGC "${ARGC} + 1")
|
|
|
|
endwhile()
|
|
|
|
|
|
|
|
foreach(FILE IN LISTS SCRIPT_API_BINARY_FILES)
|
|
|
|
file(STRINGS "${FILE}" LINES REGEX "^void SQ${APIUC}.*_Register\\(Squirrel \\*engine\\)$")
|
2020-09-25 11:55:25 +00:00
|
|
|
if(LINES)
|
2019-03-12 14:37:57 +00:00
|
|
|
string(REGEX REPLACE ".*api/${APILC}/(.*)" "#include \"\\1\"" FILE "${FILE}")
|
|
|
|
list(APPEND SQUIRREL_INCLUDES "${FILE}")
|
|
|
|
foreach(LINE IN LISTS LINES)
|
2020-09-25 11:55:25 +00:00
|
|
|
if("${LINE}" MATCHES "SQ${APIUC}(List|Controller)_Register")
|
2019-03-12 14:37:57 +00:00
|
|
|
continue()
|
2020-09-25 11:55:25 +00:00
|
|
|
endif()
|
2019-03-12 14:37:57 +00:00
|
|
|
string(REGEX REPLACE "^.*void " " " LINE "${LINE}")
|
|
|
|
string(REGEX REPLACE "Squirrel \\*" "" LINE "${LINE}")
|
|
|
|
list(APPEND SQUIRREL_REGISTER "${LINE}")
|
2020-09-25 11:55:25 +00:00
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2019-03-12 14:37:57 +00:00
|
|
|
|
|
|
|
list(SORT SQUIRREL_INCLUDES)
|
|
|
|
string(REPLACE ";" "\n" SQUIRREL_INCLUDES "${SQUIRREL_INCLUDES}")
|
|
|
|
|
|
|
|
string(REGEX REPLACE "_Register" "0000Register" SQUIRREL_REGISTER "${SQUIRREL_REGISTER}")
|
|
|
|
list(SORT SQUIRREL_REGISTER)
|
|
|
|
string(REGEX REPLACE "0000Register" "_Register" SQUIRREL_REGISTER "${SQUIRREL_REGISTER}")
|
|
|
|
string(REPLACE ";" ";\n" SQUIRREL_REGISTER "${SQUIRREL_REGISTER}")
|
|
|
|
set(SQUIRREL_REGISTER " SQ${APIUC}List_Register(engine);\n${SQUIRREL_REGISTER};")
|
|
|
|
|
|
|
|
configure_file(${INCLUDES_SOURCE_FILE} ${INCLUDES_BINARY_FILE})
|