Skip to content

Commit d5d44c1

Browse files
author
Vano
committed
Working SCons/CMake config function, TODO detach from godot-cpp
1 parent cb0db65 commit d5d44c1

File tree

6 files changed

+27
-29
lines changed

6 files changed

+27
-29
lines changed

CMakeLists.txt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,7 @@ include(godot-cppscript)
7575
# Get header files (.hpp only)
7676
file(GLOB_RECURSE CPPSCRIPT_HEADERS ../src/*.hpp)
7777

78-
# Optional
79-
80-
# C++ defines (TOOLS_ENABLED, DEBUG_METHODS etc.)
81-
# enable, if you conditionally enable classes/members
82-
# based on definitions
83-
#get_target_property(DEFS ${PROJECT_NAME} COMPILE_DEFINITIONS)
84-
85-
# Include paths
86-
# (try to avoid godot-cpp headers paths,
87-
# it slows parsing drastically)
88-
#get_target_property(INC_PATHS ${PROJECT_NAME} INCLUDE_DIRECTORIES)
78+
# Call function to configure your target
8979
create_cppscript_target(
9080
# Name of your main target
9181
${PROJECT_NAME}
@@ -105,8 +95,16 @@ create_cppscript_target(
10595
ON
10696

10797
# Optional
108-
"" # OR "${INC_PATHS}"
109-
"" # OR "${DEFS}"
98+
99+
# C++ defines (TOOLS_ENABLED, DEBUG_METHODS etc.)
100+
# Enable, if you conditionally enable classes/members
101+
# based on definitions
102+
"" # $<TARGET_PROPERTY:godot-cpp,COMPILE_DEFINITIONS>
103+
104+
# Include paths
105+
# (Try to avoid godot-cpp headers paths,
106+
# it slows parsing drastically)
107+
"" # $<TARGET_PROPERTY:${PROJECT_NAME},INCLUDE_DIRECTORIES>
110108
)
111109
###############################
112110

SConstruct

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ generated = create_cppscript_target(
3434
# Optional
3535

3636
## C++ defines (TOOLS_ENABLED, DEBUG_METHODS etc.)
37-
## enable, if you conditionally enable classes/members
37+
## Enable, if you conditionally enable classes/members
3838
## based on definitions
3939
#'compile_defs' : env['CPPDEFINES'],
4040
#
4141
## Include paths
42-
## (try to avoid godot-cpp headers paths,
42+
## (Try to avoid godot-cpp headers paths,
4343
## it slows parsing drastically)
4444
#'include_paths' : env['CPPPATH']
4545
}

cmake/godot-cppscript.cmake

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ find_package(Python3 3.4 REQUIRED)
33
set(CPPSCRIPT_DIR ${CMAKE_CURRENT_LIST_DIR}/..)
44

55
#TODO: make it work in parallel
6-
function(create_cppscript_target TARGET_NAME HEADER_NAME HEADERS_DIR GEN_DIR AUTO_METHODS INCLUDE_PATHS COMPILE_DEFS)
7-
# Handle empty lists
8-
if("${COMPILE_DEFS}" STREQUAL "DEFS-NOTFOUND")
9-
set(COMPILE_DEFS "")
10-
endif()
11-
if("${INCLUDE_PATHS}" STREQUAL "INC_PATHS-NOTFOUND")
6+
function(create_cppscript_target TARGET_NAME HEADER_NAME HEADERS_DIR GEN_DIR AUTO_METHODS COMPILE_DEFS INCLUDE_PATHS)
7+
# Handle empty/NOTFOUND lists
8+
if(NOT INCLUDE_PATHS)
129
set(INCLUDE_PATHS "")
1310
endif()
11+
if(NOT COMPILE_DEFS)
12+
set(COMPILE_DEFS "")
13+
endif()
14+
1415

1516
if(${AUTO_METHODS})
1617
set(AUTO_METHODS_STR "True")
@@ -46,6 +47,7 @@ function(create_cppscript_target TARGET_NAME HEADER_NAME HEADERS_DIR GEN_DIR AUT
4647
DEPENDS ${CPPSCRIPT_HEADERS}
4748
WORKING_DIRECTORY ${CPPSCRIPT_DIR}
4849
VERBATIM
50+
COMMAND_EXPAND_LISTS
4951
COMMENT "Parsing header files..."
5052
)
5153

cppscript.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def __call__(self, scons_env, source, call_args, *args, **kwargs):
2323
'header_name' : env['header_name'],
2424
'header_dir' : env['header_dir'],
2525
'gen_dir' : env['gen_dir'],
26-
'compile_defs' : [f'{i[0]}={i[1]}' if type(i) is tuple else str(i) for i in env.get('compile_defs', [])],
27-
'include_paths' : [cppscript_src] + env.get('include_paths', []),
26+
'compile_defs' : {f'{i[0]}={i[1]}' if type(i) is tuple else str(i) for i in env.get('compile_defs', [])},
27+
'include_paths' : {cppscript_src}.union({str(path) for path in env.get('include_paths', [])}),
2828
'auto_methods' : env['auto_methods']
2929
}
3030

@@ -190,10 +190,12 @@ def generate_header_emitter(target, source, env):
190190

191191

192192
def generate_header_scons(target, source, env):
193+
print(json.dumps(env['cppscript_env'], indent=2, default=lambda x: list(x) if type(x) is set else None))
193194
return generate_header(source, env['cppscript_env'], get_file_scons)
194195

195196

196197
def generate_header_cmake(source, env):
198+
print(json.dumps(env, indent=2, default=lambda x: list(x) if type(x) is set else x))
197199
return generate_header(source, env, get_file_cmake)
198200

199201

cppscript_bindings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
'header_name' : args.header_name[0],
2222
'header_dir' : args.header_dir[0],
2323
'gen_dir' : args.gen_dir[0],
24-
'compile_defs' : args.definitions,
25-
'include_paths' : args.include_paths,
24+
'compile_defs' : set(args.definitions),
25+
'include_paths' : set(args.include_paths),
2626
'auto_methods' : args.auto_methods
2727
}
2828

src/register_types.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
#define REGISTER_TYPES_H
44

55
#include <godot_cpp/core/class_db.hpp>
6-
#include <godot_cpp/classes/multiplayer_api.hpp>
7-
#include <godot_cpp/classes/multiplayer_peer.hpp>
8-
9-
#include "scripts.gen.h"
106

117
using namespace godot;
128

0 commit comments

Comments
 (0)