Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Eisel <julian@blender.org>2022-03-14 18:39:42 +0300
committerJulian Eisel <julian@blender.org>2022-03-14 18:50:49 +0300
commit9b298cf3dbec9e246748448cc635a5055fe90c19 (patch)
treec9fb6ddaf16bec463d9d4dd5a65a8c9d285afc8f /source/blender/makesrna
parentcff6eb65804da3a06bde3c9152bec26e01a24992 (diff)
RNA: Generate property declerations header, solving msg-bus C++ incompatibility
Lets `makesrna` generate a `RNA_prototypes.h` header with declarations for all RNA properties. This can be included in regular source files when needing to reference RNA properties statically. This solves an issue on MSVC with adding such declarations in functions, like we used to do. See 800fc1736748. Removes any such declarations and the related FIXME comments. Reviewed By: campbellbarton, LazyDodo, brecht Differential Revision: https://developer.blender.org/D13837
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r--source/blender/makesrna/intern/CMakeLists.txt5
-rw-r--r--source/blender/makesrna/intern/makesrna.c65
-rw-r--r--source/blender/makesrna/intern/rna_access.c22
-rw-r--r--source/blender/makesrna/intern/rna_internal.h12
4 files changed, 72 insertions, 32 deletions
diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt
index a0e5fc282d2..4e3a4aae727 100644
--- a/source/blender/makesrna/intern/CMakeLists.txt
+++ b/source/blender/makesrna/intern/CMakeLists.txt
@@ -122,6 +122,7 @@ set(APISRC
string(REGEX REPLACE "rna_([a-zA-Z0-9_-]*).c" "${CMAKE_CURRENT_BINARY_DIR}/rna_\\1_gen.c" GENSRC "${DEFSRC}")
list(APPEND GENSRC
"${CMAKE_CURRENT_BINARY_DIR}/rna_prototypes_gen.h"
+ "${CMAKE_CURRENT_BINARY_DIR}/../RNA_prototypes.h"
)
set_source_files_properties(${GENSRC} PROPERTIES GENERATED TRUE)
@@ -188,6 +189,8 @@ set(INC
# dna_type_offsets.h
${CMAKE_CURRENT_BINARY_DIR}/../../makesdna/intern
+ # RNA_prototypes.h
+ ${CMAKE_CURRENT_BINARY_DIR}/../../makesrna/
)
set(INC_SYS
@@ -402,7 +405,7 @@ endif()
# note (linux only): with crashes try add this after COMMAND: valgrind --leak-check=full --track-origins=yes
add_custom_command(
OUTPUT ${GENSRC}
- COMMAND "$<TARGET_FILE:makesrna>" ${CMAKE_CURRENT_BINARY_DIR}/
+ COMMAND "$<TARGET_FILE:makesrna>" ${CMAKE_CURRENT_BINARY_DIR}/ ${CMAKE_CURRENT_BINARY_DIR}/../
DEPENDS makesrna
)
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index 3ea7f8e0df6..f19bab6870a 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -3304,7 +3304,7 @@ static const char *rna_property_subtype_unit(PropertySubType type)
}
}
-static void rna_generate_prototypes(BlenderRNA *brna, FILE *f)
+static void rna_generate_internal_struct_prototypes(BlenderRNA *brna, FILE *f)
{
StructRNA *srna;
@@ -3343,7 +3343,19 @@ static void rna_generate_blender(BlenderRNA *brna, FILE *f)
"};\n\n");
}
-static void rna_generate_property_prototypes(BlenderRNA *UNUSED(brna), StructRNA *srna, FILE *f)
+static void rna_generate_external_property_prototypes(BlenderRNA *brna, FILE *f)
+{
+ for (StructRNA *srna = brna->structs.first; srna; srna = srna->cont.next) {
+ for (PropertyRNA *prop = srna->cont.properties.first; prop; prop = prop->next) {
+ fprintf(f, "extern struct PropertyRNA rna_%s_%s;\n", srna->identifier, prop->identifier);
+ }
+ fprintf(f, "\n");
+ }
+}
+
+static void rna_generate_internal_property_prototypes(BlenderRNA *UNUSED(brna),
+ StructRNA *srna,
+ FILE *f)
{
PropertyRNA *prop;
StructRNA *base;
@@ -4499,7 +4511,7 @@ static void rna_generate(BlenderRNA *brna, FILE *f, const char *filename, const
for (ds = DefRNA.structs.first; ds; ds = ds->cont.next) {
if (!filename || ds->filename == filename) {
- rna_generate_property_prototypes(brna, ds->srna, f);
+ rna_generate_internal_property_prototypes(brna, ds->srna, f);
rna_generate_function_prototypes(brna, ds->srna, f);
}
}
@@ -5128,7 +5140,11 @@ static void make_bad_file(const char *file, int line)
fclose(fp);
}
-static int rna_preprocess(const char *outfile)
+/**
+ * \param extern_outfile: Directory to put public headers into. Can be NULL, in which case
+ * everything is put into \a outfile.
+ */
+static int rna_preprocess(const char *outfile, const char *public_header_outfile)
{
BlenderRNA *brna;
StructDefRNA *ds;
@@ -5137,6 +5153,10 @@ static int rna_preprocess(const char *outfile)
int i, status;
const char *deps[3]; /* expand as needed */
+ if (!public_header_outfile) {
+ public_header_outfile = outfile;
+ }
+
/* define rna */
brna = RNA_create();
@@ -5161,7 +5181,36 @@ static int rna_preprocess(const char *outfile)
status = (DefRNA.error != 0);
- /* create rna prototype header file */
+ /* Create external rna struct prototype header file RNA_prototypes.h. */
+ strcpy(deffile, public_header_outfile);
+ strcat(deffile, "RNA_prototypes.h" TMP_EXT);
+ if (status) {
+ make_bad_file(deffile, __LINE__);
+ }
+ file = fopen(deffile, "w");
+ if (!file) {
+ fprintf(stderr, "Unable to open file: %s\n", deffile);
+ status = 1;
+ }
+ else {
+ fprintf(file,
+ "/* Automatically generated RNA property declarations, to statically reference \n"
+ " * properties as `rna_[struct-name]_[property-name]`.\n"
+ " *\n"
+ " * DO NOT EDIT MANUALLY, changes will be overwritten.\n"
+ " */\n\n");
+
+ fprintf(file, "#pragma once\n\n");
+ fprintf(file, "#ifdef __cplusplus\n extern \"C\" {\n#endif\n\n");
+ rna_generate_external_property_prototypes(brna, file);
+ fprintf(file, "#ifdef __cplusplus\n }\n#endif\n");
+ fclose(file);
+ status = (DefRNA.error != 0);
+
+ replace_if_different(deffile, NULL);
+ }
+
+ /* create internal rna struct prototype header file */
strcpy(deffile, outfile);
strcat(deffile, "rna_prototypes_gen.h");
if (status) {
@@ -5176,7 +5225,7 @@ static int rna_preprocess(const char *outfile)
fprintf(file,
"/* Automatically generated function declarations for the Data API.\n"
" * Do not edit manually, changes will be overwritten. */\n\n");
- rna_generate_prototypes(brna, file);
+ rna_generate_internal_struct_prototypes(brna, file);
fclose(file);
status = (DefRNA.error != 0);
}
@@ -5288,7 +5337,7 @@ int main(int argc, char **argv)
CLG_level_set(debugSRNA);
if (argc < 2) {
- fprintf(stderr, "Usage: %s outdirectory/\n", argv[0]);
+ fprintf(stderr, "Usage: %s outdirectory [public header outdirectory]/\n", argv[0]);
return_status = 1;
}
else {
@@ -5296,7 +5345,7 @@ int main(int argc, char **argv)
fprintf(stderr, "Running makesrna\n");
}
makesrna_path = argv[0];
- return_status = rna_preprocess(argv[1]);
+ return_status = rna_preprocess(argv[1], (argc > 2) ? argv[2] : NULL);
}
CLG_exit();
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index a6fa369dc73..943b2fccbb7 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -400,28 +400,28 @@ static bool rna_idproperty_verify_valid(PointerRNA *ptr, PropertyRNA *prop, IDPr
}
static PropertyRNA *typemap[IDP_NUMTYPES] = {
- (PropertyRNA *)&rna_PropertyGroupItem_string,
- (PropertyRNA *)&rna_PropertyGroupItem_int,
- (PropertyRNA *)&rna_PropertyGroupItem_float,
+ &rna_PropertyGroupItem_string,
+ &rna_PropertyGroupItem_int,
+ &rna_PropertyGroupItem_float,
NULL,
NULL,
NULL,
- (PropertyRNA *)&rna_PropertyGroupItem_group,
- (PropertyRNA *)&rna_PropertyGroupItem_id,
- (PropertyRNA *)&rna_PropertyGroupItem_double,
- (PropertyRNA *)&rna_PropertyGroupItem_idp_array,
+ &rna_PropertyGroupItem_group,
+ &rna_PropertyGroupItem_id,
+ &rna_PropertyGroupItem_double,
+ &rna_PropertyGroupItem_idp_array,
};
static PropertyRNA *arraytypemap[IDP_NUMTYPES] = {
NULL,
- (PropertyRNA *)&rna_PropertyGroupItem_int_array,
- (PropertyRNA *)&rna_PropertyGroupItem_float_array,
+ &rna_PropertyGroupItem_int_array,
+ &rna_PropertyGroupItem_float_array,
NULL,
NULL,
NULL,
- (PropertyRNA *)&rna_PropertyGroupItem_collection,
+ &rna_PropertyGroupItem_collection,
NULL,
- (PropertyRNA *)&rna_PropertyGroupItem_double_array,
+ &rna_PropertyGroupItem_double_array,
};
void rna_property_rna_or_id_get(PropertyRNA *prop,
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 44bf51d9770..c59fd2a0535 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -493,18 +493,6 @@ void RNA_def_main_simulations(BlenderRNA *brna, PropertyRNA *cprop);
/* ID Properties */
-extern StringPropertyRNA rna_PropertyGroupItem_string;
-extern IntPropertyRNA rna_PropertyGroupItem_int;
-extern IntPropertyRNA rna_PropertyGroupItem_int_array;
-extern FloatPropertyRNA rna_PropertyGroupItem_float;
-extern FloatPropertyRNA rna_PropertyGroupItem_float_array;
-extern PointerPropertyRNA rna_PropertyGroupItem_group;
-extern PointerPropertyRNA rna_PropertyGroupItem_id;
-extern CollectionPropertyRNA rna_PropertyGroupItem_collection;
-extern CollectionPropertyRNA rna_PropertyGroupItem_idp_array;
-extern FloatPropertyRNA rna_PropertyGroupItem_double;
-extern FloatPropertyRNA rna_PropertyGroupItem_double_array;
-
#ifndef __RNA_ACCESS_H__
extern StructRNA RNA_PropertyGroupItem;
extern StructRNA RNA_PropertyGroup;