Skip to content

Commit 499ba3f

Browse files
author
Vano
committed
Cmake/Python project config scripts
1 parent 4a28a4d commit 499ba3f

File tree

8 files changed

+98
-105
lines changed

8 files changed

+98
-105
lines changed

cppscript-configure.cmake

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
cmake_minimum_required(VERSION 3.6)
2+
3+
set(LIBRARY_NAME_FULL "${CMAKE_ARGV3}")
4+
set(SRC_DIR "${CMAKE_ARGV4}")
5+
set(PROJECT_DIR "${CMAKE_ARGV5}")
6+
7+
set(REFERENCE_STR "Usage:\n\tcmake -P cppscript/cppscript-configure.cmake <library_name> <src_dir> <project_dir>")
8+
if("${LIBRARY_NAME_FULL}" STREQUAL "")
9+
message(FATAL_ERROR "No library_name argument.\n${REFERENCE_STR}")
10+
elseif("${SRC_DIR}" STREQUAL "")
11+
message(FATAL_ERROR "No source_dir argument.\n${REFERENCE_STR}")
12+
elseif("${LIBRARY_NAME_FULL}" STREQUAL "")
13+
message(FATAL_ERROR "No project_dir argument.\n${REFERENCE_STR}")
14+
endif()
15+
16+
17+
string(REPLACE "-" "_" LIBRARY_NAME "${LIBRARY_NAME_FULL}")
18+
19+
message("Configuring '${PROJECT_DIR}/${LIBRARY_NAME_FULL}.gdextension' ...")
20+
configure_file(
21+
${CMAKE_CURRENT_LIST_DIR}/templates/scripts.gdextension.in
22+
${PROJECT_DIR}/${LIBRARY_NAME_FULL}.gdextension
23+
)
24+
25+
message("Configuring '${SRC_DIR}/register_types.h' ...")
26+
configure_file(
27+
${CMAKE_CURRENT_LIST_DIR}/templates/register_types.h.in
28+
${SRC_DIR}/register_types.h
29+
)
30+
31+
message("Configuring '${SRC_DIR}/register_types.cpp' ...")
32+
configure_file(
33+
${CMAKE_CURRENT_LIST_DIR}/templates/register_types.cpp.in
34+
${SRC_DIR}/register_types.cpp
35+
)
36+
37+
message("Files configured.")

cppscript-configure.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python3
2+
3+
import os, sys
4+
5+
try:
6+
library_name_full = sys.argv[1]
7+
src_dir = sys.argv[2]
8+
project_dir = sys.argv[3]
9+
except:
10+
print('ERROR: Not enough arguments.\nUsage:\n\tcmake -P cppscript/cppscript-configure.cmake <library_name> <src_dir> <project_dir>', file=sys.stderr)
11+
exit(1)
12+
13+
library_name = library_name_full.replace('-', '_')
14+
15+
def replace(in_path, out_path):
16+
with open(in_path, 'r') as infile:
17+
text = infile.read()
18+
with open(out_path, 'w') as outfile:
19+
outfile.write(text.replace('@LIBRARY_NAME@', library_name))
20+
21+
print(f"Configuring '{os.path.join(project_dir, f'{library_name_full}.gdextension')}' ...")
22+
replace(os.path.join(os.path.dirname(__file__), 'templates', 'scripts.gdextension.in'), os.path.join(project_dir, f'{library_name_full}.gdextension'))
23+
24+
print(f"Configuring '{os.path.join(src_dir, 'register_types.cpp')}' ...")
25+
replace(os.path.join(os.path.dirname(__file__), 'templates', 'register_types.cpp.in'), os.path.join(src_dir, 'register_types.cpp'))
26+
27+
print(f"Configuring '{os.path.join(src_dir, 'register_types.h')}' ...")
28+
replace(os.path.join(os.path.dirname(__file__), 'templates', 'register_types.h.in'), os.path.join(src_dir, 'register_types.h'))
29+
30+
print("Files configured.")

godot-cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

scripts.gdextension

Lines changed: 0 additions & 24 deletions
This file was deleted.

templates/register_types.cpp

Lines changed: 0 additions & 66 deletions
This file was deleted.

templates/register_types.cpp.in

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
using namespace godot;
1313

14-
void LIBRARY_INIT_FUNC(ModuleInitializationLevel p_level) {
14+
void initialize_@LIBRARY_NAME@_module(ModuleInitializationLevel p_level) {
1515
switch (p_level) {
1616
case MODULE_INITIALIZATION_LEVEL_CORE:
1717
_register_level_core();
@@ -33,7 +33,7 @@ void LIBRARY_INIT_FUNC(ModuleInitializationLevel p_level) {
3333
}
3434
}
3535

36-
void LIBRARY_DEINIT_FUNC(ModuleInitializationLevel p_level) {
36+
void uninitialize_@LIBRARY_NAME@_module(ModuleInitializationLevel p_level) {
3737
switch (p_level) {
3838
case MODULE_INITIALIZATION_LEVEL_CORE:
3939
break;
@@ -53,11 +53,11 @@ void LIBRARY_DEINIT_FUNC(ModuleInitializationLevel p_level) {
5353

5454
extern "C" {
5555
// GDExtension initialization
56-
GDExtensionBool GDE_EXPORT LIBRARY_ENTRY_SYMBOL_FUNC(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
56+
GDExtensionBool GDE_EXPORT @LIBRARY_NAME@_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
5757
godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);
5858

59-
init_obj.register_initializer(LIBRARY_INIT_FUNC);
60-
init_obj.register_terminator(LIBRARY_DEINIT_FUNC);
59+
init_obj.register_initializer(initialize_@LIBRARY_NAME@_module);
60+
init_obj.register_terminator(uninitialize_@LIBRARY_NAME@_module);
6161
init_obj.set_minimum_library_initialization_level(DEFAULT_INIT_LEVEL);
6262

6363
return init_obj.init();

templates/register_types.h.in

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@
44

55
#include <godot_cpp/core/class_db.hpp>
66

7-
// Modify this variable
8-
#define LIBRARY_NAME scripts
9-
10-
#define LIBRARY_INIT_FUNC initialize_ ## LIBRARY_NAME ## _module
11-
#define LIBRARY_UNINIT_FUNC uninitialize_ ## LIBRARY_NAME ## _module
12-
#define LIBRARY_ENTRY_SYMBOL_FUNC LIBRARY_NAME ## _library_init
13-
14-
void LIBRARY_INIT_FUNC(godot::ModuleInitializationLevel p_level);
15-
void LIBRARY_UNINIT_FUNC(godot::ModuleInitializationLevel p_level);
7+
void initialize_@LIBRARY_NAME@_module(godot::ModuleInitializationLevel p_level);
8+
void initialize_@LIBRARY_NAME@_module(godot::ModuleInitializationLevel p_level);
169

1710
#endif // REGISTER_TYPES_H

templates/scripts.gdextension.in

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[configuration]
2+
3+
entry_symbol = "@LIBRARY_NAME@_library_init"
4+
compatibility_minimum = 4.1
5+
6+
[libraries]
7+
8+
macos.debug = "res://../bin/lib@[email protected]_debug.framework"
9+
macos.release = "res://../bin/lib@[email protected]_release.framework"
10+
windows.debug.x86_32 = "res://../bin/lib@[email protected]_debug.x86_32.dll"
11+
windows.release.x86_32 = "res://../bin/lib@[email protected]_release.x86_32.dll"
12+
windows.debug.x86_64 = "res://../bin/lib@[email protected]_debug.x86_64.dll"
13+
windows.release.x86_64 = "res://../bin/lib@[email protected]_release.x86_64.dll"
14+
linux.debug.x86_64 = "res://../bin/lib@[email protected]_debug.x86_64.so"
15+
linux.release.x86_64 = "res://../bin/lib@[email protected]_release.x86_64.so"
16+
linux.debug.arm64 = "res://../bin/lib@[email protected]_debug.arm64.so"
17+
linux.release.arm64 = "res://../bin/lib@[email protected]_release.arm64.so"
18+
linux.debug.rv64 = "res://../bin/lib@[email protected]_debug.rv64.so"
19+
linux.release.rv64 = "res://../bin/lib@[email protected]_release.rv64.so"
20+
android.debug.x86_64 = "res://../bin/lib@[email protected]_debug.x86_64.so"
21+
android.release.x86_64 = "res://../bin/lib@[email protected]_release.x86_64.so"
22+
android.debug.arm64 = "res://../bin/lib@[email protected]_debug.arm64.so"
23+
android.release.arm64 = "res://../bin/lib@[email protected]_release.arm64.so"
24+
web.debug.wasm32 = "res://../bin/lib@[email protected]_debug.wasm32.wasm"

0 commit comments

Comments
 (0)