@@ -21,61 +21,105 @@ libclang
2121pip install libclang
2222```
2323
24- ## Installation as project submodule
24+ # Installation
2525
26- ### Recommended project layout
27- ```
28- / project root
29- ├── project godot project root (res://)
30- ├── bin compiled binaries
31- ├── external submodules
32- │ ├── cppscript
33- │ └── godot-cpp
34- └── src C++ source files
35- ```
36-
37- #
38- ### Installation
39-
40- #### From zero
26+ ### From zero
4127Install template from [ here] ( https://github.com/IvanInventor/godot-cppscript-template ) .
4228
43- #### To existing project
44- - From root of your project
45- ``` bash
46- git submodule add https://github.com/IvanInventor/godot-cppscript external/cppscript
47- git submodule update --init external/cppscript
48- ```
29+ ##
30+ ### To existing project
31+ Copy ` godot_cppscript.* ` to your project
32+ - ` godot_cppscript.py ` for SCons
33+
34+ *** OR***
35+
36+ - ` godot_cppscript.cmake ` for CMake
37+
38+ *** OR***
39+
40+ - Setup git submodule from root of your project
41+
42+ Recommended project layout
43+ ```
44+ / project root
45+ ├── project godot project root (res://)
46+ ├── bin compiled binaries
47+ ├── external submodules
48+ │ ├── cppscript
49+ │ └── godot-cpp
50+ ├── src C++ source files
51+ └── include (optional) separated header files
52+ ```
53+
54+ ``` bash
55+ $ git submodule add https://github.com/IvanInventor/godot-cppscript external/cppscript
56+ $ git submodule update --init external/cppscript
57+ ```
4958##### Generate files
50- - Copy and modify some files (library_name = 'scripts')
51- - By script
52- - With cmake
59+ Once per project, need to copy/modify some files (library_name = 'scripts', for example)
60+ - ` .gdextension ` file
61+ - ` register_types.cpp `
62+ - ` register_types.h `
63+
64+ Don't worry, you will still be able to add custom code to this files after configuring
65+
66+ - By script
67+ - With Python
5368 ``` bash
5469 # Usage:
55- # cmake -P external/cppscript/cppscript-configure.cmake <library_name> <src_dir> <project_dir>
56- cmake -P external/cppscript/cppscript-configure.cmake scripts src/ project/
70+ # python3 path/to/godot_cppscript.py
71+ # <library_name> (`my_library_name`)
72+ # <cpp_file_path> (`src/register_types.cpp`)
73+ # <header_file_path> (`include/register_types.h`)
74+ # <gdextension_file_path> (`project/my_library.gdextension`)
75+ $ python3 godot_cppscript.py scripts src/register_types.cpp src/register_types.h project/scripts.gdextension
76+ These files will be affected:
77+ (Override) project/scripts.gdextension
78+ (Override) src/register_types.cpp
79+ (Override) src/register_types.h
80+
81+ Are you sure? (Y/N) Y
82+ Configuring ' project/scripts.gdextension' ...
83+ Configuring ' src/register_types.cpp' ...
84+ Configuring ' src/register_types.h' ...
85+ Files configured.
5786 ```
58- OR
59- - With Python
87+
88+ *** OR***
89+
90+ - With cmake
6091 ` ` ` bash
6192 # Usage:
62- # python3 external/cppscript/cppscript-configure.py <library_name> <src_dir> <project_dir>
63- python3 external/cppscript/cppscript-configure.py scripts src/ project/
93+ # cmake -P path/to/godot_cppscript.cmake
94+ # <library_name> (`my_library_name`)
95+ # <cpp_file_path> (`src/register_types.cpp`)
96+ # <header_file_path> (`include/register_types.h`)
97+ # <gdextension_file_path> (`project/my_library.gdextension`)
98+ $ cmake -P godot_cppscript.cmake scripts src/register_types.cpp src/register_types.h project/scripts.gdextension
99+ These files will be affected:
100+ (Override) project/scripts.gdextension
101+ (Override) src/register_types.cpp
102+ (Override) src/register_types.h
103+
104+ Are you sure? (Y/N) Y
105+ Configuring ' project/scripts.gdextension' ...
106+ Configuring ' src/register_types.cpp' ...
107+ Configuring ' src/register_types.h' ...
108+ Files configured.
64109 ` ` `
65- OR
110+
111+ *** OR***
112+
66113 - By hand, replacing ` @LIBRARY_NAME@` in files with you library name
67- - [templates/scripts.gdextension.in](/templates/scripts.gdextension.in) -> project/< library_name> .gdextension
68- - [templates/register_types.cpp.in](/templates/register_types.cpp.in) -> src/register_types.cpp
69- - [templates/register_types.h.in](/templates/register_types.h.in) -> src/register_types.h
114+ - [templates/scripts.gdextension.in](https://github.com/IvanInventor/godot-cppscript/blob/next /templates/scripts.gdextension.in) -> project/< library_name> .gdextension
115+ - [templates/register_types.cpp.in](https://github.com/IvanInventor/godot-cppscript/blob/next /templates/register_types.cpp.in) -> src/register_types.cpp
116+ - [templates/register_types.h.in](https://github.com/IvanInventor/godot-cppscript/blob/next /templates/register_types.h.in) -> src/register_types.h
70117
71118- Create cppscript target in your build script
72119 - SCons
73120 ` ` ` python
74- # import module
75- import sys
76- sys.path.append(' external/cppscript' )
77- from cppscript import create_cppscript_target
78- from cppscript import GlobRecursive # Optional
121+ from godot_cppscript import create_cppscript_target
122+ from godot_cppscript import GlobRecursive # Optional
79123
80124 # ...
81125
@@ -108,7 +152,7 @@ git submodule update --init external/cppscript
108152 ## C++ defines (TOOLS_ENABLED, DEBUG_METHODS etc.)
109153 ## Enable, if you conditionally enable classes/members
110154 ## based on definitions
111- # 'compile_defs' : env['CPPDEFINES'],
155+ 'compile_defs' : env['CPPDEFINES'],
112156 #
113157 ## Include paths
114158 ## (Try to avoid godot-cpp headers paths,
@@ -117,6 +161,9 @@ git submodule update --init external/cppscript
117161 }
118162 )
119163
164+ # Include headers path (if not done already)
165+ env.Append(CPPPATH='src')
166+
120167 # Your project's target generation
121168 # You only need to modify it
122169 if env["platform"] == "macos":
@@ -140,48 +187,58 @@ git submodule update --init external/cppscript
140187
141188 - Cmake
142189 ` ` ` cmake
143- # Include module
144- list(APPEND CMAKE_MODULE_PATH " ${CMAKE_CURRENT_SOURCE_DIR} /external/cppscript" )
145- include(godot-cppscript)
190+ include(${CMAKE_CURRENT_SOURCE_DIR} /godot_cppscript.cmake)
146191
147192 # Get header files (Prefer .hpp files)
148193 file(GLOB_RECURSE CPPSCRIPT_HEADERS src/* .hpp)
149194
150- # Call function to configure your target
195+ # Call function to create cppscript target
151196 create_cppscript_target(
152- # Name of your main target
153- ${PROJECT_NAME}
154-
155- # Header files to parse
156- " ${CPPSCRIPT_HEADERS} "
157-
158197 # Name of header to be included to enable cppscript
159198 # (Prefer name unique to your project)
160- cppscript.h
199+ HEADER_NAME
200+ cppscript.h
161201
162- # FULL PATH to C++ header files
163- ${CMAKE_CURRENT_SOURCE_DIR} /src
202+ # Header files to parse (.hpp only)
203+ HEADERS_LIST
204+ ${CPPSCRIPT_HEADERS}
164205
165- # FULL PATH to generated object files
166- ${CMAKE_CURRENT_SOURCE_DIR} /.gen
206+ # FULL PATH to C++ header files
207+ HEADERS_DIR
208+ ${CMAKE_CURRENT_SOURCE_DIR} /src
209+
210+ # Variable name for generated sources list
211+ OUTPUT_SOURCES
212+ GEN_SOURCES
167213
168214 # Generate bindings to public methods automatically
169215 # or require GMETHOD() before methods
170- ON
216+ AUTO_METHODS
171217
172218 # Optional
173219
174220 # C++ defines (TOOLS_ENABLED, DEBUG_METHODS etc.)
175221 # Enable, if you conditionally enable classes/members
176222 # based on definitions
177- " " # $<TARGET_PROPERTY:godot-cpp,COMPILE_DEFINITIONS>
223+ #
224+ COMPILE_DEFS
225+ $< TARGET_PROPERTY:${PROJECT_NAME} ,COMPILE_DEFINITIONS>
178226
179227 # Include paths
180228 # (Try to avoid godot-cpp headers paths,
181229 # it slows parsing drastically)
182- " " # $<TARGET_PROPERTY:${PROJECT_NAME},INCLUDE_DIRECTORIES>
230+ #
231+ # INCLUDE_PATHS
232+ # $<TARGET_PROPERTY:${PROJECT_NAME},INCLUDE_DIRECTORIES>
233+ )
234+
235+ # Add sources to your target
236+ target_sources(${PROJECT_NAME} PRIVATE ${GEN_SOURCES} )
237+
238+ # Include headers path (if not done already)
239+ target_include_directories(${PROJECT_NAME} PRIVATE
240+ src
183241 )
184-
185242 ` ` `
186243
187244# # Usage example
0 commit comments