Skip to content

Commit

Permalink
Sync with 1c77f4f
Browse files Browse the repository at this point in the history
  • Loading branch information
Vano committed Oct 2, 2024
1 parent 3e239e2 commit d4ae03a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 65 deletions.
108 changes: 43 additions & 65 deletions godot_cppscript.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.6)
# THIS FILE IS AUTO-GENERATED
# See `https://github.com/IvanInventor/godot-cppscript/tree/next` for proper source
cmake_minimum_required(VERSION 3.12.4)

find_package(Python3 3.4 REQUIRED)
find_package(Python3 3.10 REQUIRED)

if(CMAKE_SCRIPT_MODE_FILE)
# Ran as configure script
Expand Down Expand Up @@ -182,16 +184,15 @@ exit(0)
list(APPEND ARGS "${CMAKE_ARGV${i}}")
endforeach()

set(SCRIPT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/.configure_script.py.tmp")
file(WRITE ${SCRIPT_PATH} "${PY_CONFIGURE_SCRIPT}")
execute_process(
COMMAND
"${Python3_EXECUTABLE}"
"${SCRIPT_PATH}"
"-c"
"${PY_CONFIGURE_SCRIPT}"
${ARGS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
file(REMOVE ${SCRIPT_PATH})


else()

Expand Down Expand Up @@ -1577,11 +1578,7 @@ if __name__ == \"__main__\":
'gen_dir' : args.gen_dir[0],
'compile_defs' : set(args.definitions),
'include_paths' : set(args.include_paths),
'auto_methods' : args.auto_methods,
'code_format' : code_format_godot_cpp()
if os.getenv(\"CPPSCRIPT_NO_CONSTEXPR_CHECKS\", False)
else code_format_cppscript_constexr_checks()
'auto_methods' : args.auto_methods
}
sys.exit(generate_header_cmake(args.sources, env))
Expand All @@ -1590,88 +1587,69 @@ if __name__ == \"__main__\":
)


#TODO: make it work in parallel
function(create_cppscript_target)
set(options AUTO_METHODS)
set(oneValueArgs HEADER_NAME HEADERS_DIR GEN_DIR OUTPUT_SOURCES)
set(multiValueArgs HEADERS_LIST COMPILE_DEFS INCLUDE_PATHS)
cmake_parse_arguments(CPPS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

# Handle required args and empty/NOTFOUND lists
if(NOT CPPS_HEADER_NAME)
message(FATAL_ERROR "Header name is required argument (for example: `HEADER_NAME project_name.h`)")
endif()
#TODO: script path is changed to generated one
set(CMAKE_CURRENT_FUNCTION_LIST_DIR ${CMAKE_CURRENT_LIST_DIR})

if(NOT CPPS_HEADERS_DIR)
message(FATAL_ERROR "Headers directory is required argument (for example: `HEADERS_DIR \${CMAKE_CURRENT_SOURCE_DIR}/include`)")
#TODO: make it work in parallel
function(create_cppscript_target TARGET_NAME HEADERS_LIST HEADER_NAME HEADERS_DIR GEN_DIR AUTO_METHODS COMPILE_DEFS INCLUDE_PATHS)
#TODO: cmake_parse_args
# Handle empty/NOTFOUND lists
if(NOT INCLUDE_PATHS)
set(INCLUDE_PATHS "")
endif()

if(NOT CPPS_OUTPUT_SOURCES)
message(FATAL_ERROR "Output sources is required argument (for example: `OUTPUT_SOURCES GEN_SOURCES`)")
if(NOT COMPILE_DEFS)
set(COMPILE_DEFS "")
endif()

if(NOT CPPS_GEN_DIR)
set(CPPS_GEN_DIR "${CMAKE_CURRENT_BINARY_DIR}/.cppscript.gen")
endif()

if(NOT CPPS_HEADERS_LIST)
set(CPPS_HEADERS_LIST "")
endif()

if(NOT CPPS_COMPILE_DEFS)
set(CPPS_COMPILE_DEFS "")
endif()

if(NOT CPPS_INCLUDE_PATHS)
set(CPPS_INCLUDE_PATHS "")
endif()

if(CPPS_AUTO_METHODS)
if(${AUTO_METHODS})
set(AUTO_METHODS_STR "True")
else()
set(AUTO_METHODS_STR "False")
endif()

# Generate python script and headers
set(GODOT_CPPSCRIPT_PY_SCRIPT_PATH "${CMAKE_CURRENT_BINARY_DIR}/cppscript.py")
set(GODOT_CPPSCRIPT_DEFS_H_PATH "${CPPS_HEADERS_DIR}/cppscript_defs.h")
set(GODOT_CPPSCRIPT_BINDINGS_H_PATH "${CPPS_HEADERS_DIR}/cppscript_bindings.h")
set(GODOT_CPPSCRIPT_DEFS_H_PATH "${HEADERS_DIR}/cppscript_defs.h")
set(GODOT_CPPSCRIPT_BINDINGS_H_PATH "${HEADERS_DIR}/cppscript_bindings.h")

file(WRITE "${GODOT_CPPSCRIPT_PY_SCRIPT_PATH}" "${CPPSCRIPT_EMBED_PY_SCRIPT}")
file(WRITE "${GODOT_CPPSCRIPT_DEFS_H_PATH}" "${CPPSCRIPT_DEFS_H}")
file(WRITE "${GODOT_CPPSCRIPT_BINDINGS_H_PATH}" "${CPPSCRIPT_BINDINGS_H}")

foreach(PATH ${CPPS_HEADERS_LIST})
file(RELATIVE_PATH PATH "${CPPS_HEADERS_DIR}" "${PATH}")
foreach(PATH ${HEADERS_LIST})
file(RELATIVE_PATH PATH "${HEADERS_DIR}" "${PATH}")
string(REGEX REPLACE "\.[^./\\]+$" ".gen.cpp" relative_path "${PATH}")
list(APPEND SOURCES_LIST "${CPPS_GEN_DIR}/${relative_path}")
list(APPEND SOURCES_LIST "${GEN_DIR}/${relative_path}")
endforeach()

add_custom_command(
OUTPUT
${CPPS_HEADERS_DIR}/${CPPS_HEADER_NAME}
${CPPS_HEADERS_DIR}/scripts.gen.h
${CPPS_HEADERS_DIR}/properties.gen.h
${HEADERS_DIR}/${HEADER_NAME}
${HEADERS_DIR}/scripts.gen.h
${HEADERS_DIR}/properties.gen.h
${SOURCES_LIST}

COMMAND
${Python3_EXECUTABLE} "${GODOT_CPPSCRIPT_PY_SCRIPT_PATH}"
"--header-name" "${CPPS_HEADER_NAME}"
"--header-dir" "${CPPS_HEADERS_DIR}"
"--gen-dir" "${CPPS_GEN_DIR}"
"--auto-methods" "${AUTO_METHODS_STR}"
"--definitions" ${CPPS_COMPILE_DEFS}
"--include-paths" ${CPPS_HEADERS_DIR} ${CPPS_INCLUDE_PATHS}
"--"
${CPPS_HEADERS_LIST}

DEPENDS ${CPPS_HEADERS_LIST}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
${Python3_EXECUTABLE} "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/cppscript_bindings.py"
"--header-name" "${HEADER_NAME}"
"--header-dir" "${HEADERS_DIR}"
"--gen-dir" "${GEN_DIR}"
"--auto-methods" "${AUTO_METHODS_STR}"
"--definitions" ${COMPILE_DEFS}
"--include-paths" ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/src ${HEADERS_DIR} ${INCLUDE_PATHS}
"--"
${HEADERS_LIST}

DEPENDS ${HEADERS_LIST}
WORKING_DIRECTORY ${CMAKE_CURRENT_FUNCTION_LIST_DIR}
VERBATIM
COMMAND_EXPAND_LISTS
COMMENT "Parsing header files..."
)
set(${CPPS_OUTPUT_SOURCES} "${SOURCES_LIST}" PARENT_SCOPE)

target_sources(${TARGET_NAME} PRIVATE ${SOURCES_LIST})
target_include_directories(${TARGET_NAME} PUBLIC ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/src ${HEADERS_DIR})
endfunction()


endif()
2 changes: 2 additions & 0 deletions godot_cppscript.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
# THIS FILE IS AUTO-GENERATED
# See `https://github.com/IvanInventor/godot-cppscript/tree/next` for proper source

import sys

Expand Down

0 comments on commit d4ae03a

Please sign in to comment.