Permalink
Browse files

make core C/C++ compatible, new cmake build option `WITH_CPP_CORE`

  • Loading branch information...
raptor
raptor committed May 21, 2017
1 parent 59a0a4b commit 2c845d26cf362754c5a1251942d5f9006236a217
Showing with 94 additions and 73 deletions.
  1. +4 −6 CMakeLists.txt
  2. +3 −1 source/blender/blenkernel/CMakeLists.txt
  3. +1 −1 source/blender/blenkernel/intern/mesh.c
  4. +3 −3 source/blender/blenlib/BLI_math_matrix.h
  5. +3 −1 source/blender/blenlib/CMakeLists.txt
  6. +1 −1 source/blender/blenlib/intern/boxpack2d.c
  7. +1 −1 source/blender/blenlib/intern/callbacks.c
  8. +3 −9 source/blender/blenlib/intern/math_matrix.c
  9. +2 −2 source/blender/blenlib/intern/string.c
  10. +3 −1 source/blender/blenloader/CMakeLists.txt
  11. +3 −1 source/blender/bmesh/CMakeLists.txt
  12. +1 −1 source/blender/bmesh/intern/bmesh_opdefines.c
  13. +1 −1 source/blender/bmesh/operators/bmo_mesh_conv.c
  14. +3 −2 source/blender/editors/CMakeLists.txt
  15. +2 −2 source/blender/editors/animation/anim_channels_edit.c
  16. +1 −1 source/blender/editors/armature/armature_edit.c
  17. +2 −2 source/blender/editors/curve/editcurve_select.c
  18. +2 −2 source/blender/editors/mesh/editmesh_undo.c
  19. +1 −1 source/blender/editors/mesh/meshtools.c
  20. +2 −2 source/blender/editors/sculpt_paint/sculpt.c
  21. +1 −1 source/blender/editors/sculpt_paint/sculpt_undo.c
  22. +11 −11 source/blender/editors/space_view3d/view3d_edit.c
  23. +2 −2 source/blender/editors/space_view3d/view3d_intern.h
  24. +4 −4 source/blender/editors/space_view3d/view3d_view.c
  25. +2 −2 source/blender/editors/transform/transform_snap_object.c
  26. +3 −1 source/blender/gpu/CMakeLists.txt
  27. +3 −1 source/blender/ikplugin/CMakeLists.txt
  28. +3 −1 source/blender/makesdna/CMakeLists.txt
  29. +1 −1 source/blender/makesdna/DNA_object_types.h
  30. +3 −1 source/blender/makesrna/CMakeLists.txt
  31. +3 −1 source/blender/modifiers/CMakeLists.txt
  32. +3 −1 source/blender/nodes/CMakeLists.txt
  33. +3 −1 source/blender/physics/CMakeLists.txt
  34. +3 −1 source/blender/python/CMakeLists.txt
  35. +1 −1 source/blender/python/bmesh/bmesh_py_types.c
  36. +3 −1 source/blender/render/CMakeLists.txt
  37. +3 −1 source/blender/windowmanager/CMakeLists.txt
View
@@ -47,9 +47,7 @@ endif()
cmake_minimum_required(VERSION 2.8)
-#set(CMAKE_C_COMPILER g++)
-#set(CMAKE_C_COMPILER_INIT g++)
-#set(CMAKE_CXX_COMPILER_INIT g++)
+set(WITH_CPP_CORE OFF)
if(NOT EXECUTABLE_OUTPUT_PATH)
set(FIRST_RUN TRUE)
@@ -1640,9 +1638,9 @@ if(WITH_ASSERT_ABORT)
endif()
#set(CMAKE_C_FLAGS "-fpermissive -std=c++11 ${CMAKE_C_FLAGS}")
-
-set(CMAKE_C_FLAGS "-fpermissive -std=c++11 -Wall -Wconversion -Wcast-align -Wsign-conversion -Werror=implicit-function-declaration -Werror=return-type -Werror=vla -Wmissing-prototypes -Wno-char-subscripts -Wno-unknown-pragmas -Wpointer-arith -Wunused-parameter -Wwrite-strings -Wlogical-op -Wundef -Winit-self -Wnonnull -Wmissing-include-dirs -Wno-div-by-zero -Wtype-limits -Wformat-signedness -Wuninitialized -Wredundant-decls -Wshadow -Wno-error=unused-but-set-variable -fuse-ld=gold -fopenmp -std=gnu11 -msse -pipe -fPIC -funsigned-char -fno-strict-aliasing -msse2")
-
+if (WITH_CPP_CORE)
+ set(CMAKE_C_FLAGS "-fpermissive -std=c++11 -Wall -Wconversion -Wcast-align -Wsign-conversion -Werror=implicit-function-declaration -Werror=return-type -Werror=vla -Wmissing-prototypes -Wno-char-subscripts -Wno-unknown-pragmas -Wpointer-arith -Wunused-parameter -Wwrite-strings -Wlogical-op -Wundef -Winit-self -Wnonnull -Wmissing-include-dirs -Wno-div-by-zero -Wtype-limits -Wformat-signedness -Wuninitialized -Wredundant-decls -Wshadow -Wno-error=unused-but-set-variable -fuse-ld=gold -fopenmp -std=gnu11 -msse -pipe -fPIC -funsigned-char -fno-strict-aliasing -msse2")
+endif()
message(STATUS "Using CFLAGS: ${CMAKE_C_FLAGS}")
message(STATUS "Using CXXFLAGS: ${CMAKE_CXX_FLAGS}")
@@ -23,7 +23,9 @@
#
# ***** END GPL LICENSE BLOCK *****
-SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})
+if (WITH_CPP_CORE)
+ SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})
+endif()
set(INC
.
@@ -550,7 +550,7 @@ BMesh *BKE_mesh_to_bmesh(
//);
bm = BM_mesh_create(&allocsize, params);
- BMeshFromMeshParams bparams = {};
+ struct BMeshFromMeshParams bparams;

This comment has been minimized.

Show comment
Hide comment
@hartsantler

hartsantler May 21, 2017

Owner

g++ will allow BMeshFromMeshParams bparams = {}; to compile, but gcc will not. gcc requires the prefix struct (because the struct is not typedef'ed). The C-style is strict, makes the code more readable and safer.

@hartsantler

hartsantler May 21, 2017

Owner

g++ will allow BMeshFromMeshParams bparams = {}; to compile, but gcc will not. gcc requires the prefix struct (because the struct is not typedef'ed). The C-style is strict, makes the code more readable and safer.

bparams.add_key_index = add_key_index;
bparams.use_shapekey = true;
bparams.active_shapekey = ob->shapenr;
@@ -116,8 +116,8 @@ void mul_v2_project_m4_v3(float r[2], float M[4][4], const float vec[3]);
void mul_m3_v2(float m[3][3], float r[2]);
void mul_v2_m3v2(float r[2], float m[3][3], float v[2]);
void mul_m3_v3(float M[3][3], float r[3]);
-void mul_v3_m3v3(float r[3], float M[3][3], const float a[3]);

This comment has been minimized.

Show comment
Hide comment
@hartsantler

hartsantler May 21, 2017

Owner

we lose the const correctness of these functions to make passing a copy simpler, because UNPACK3 macro was not c++ compatible

@hartsantler

hartsantler May 21, 2017

Owner

we lose the const correctness of these functions to make passing a copy simpler, because UNPACK3 macro was not c++ compatible

-void mul_v2_m3v3(float r[2], float M[3][3], const float a[3]);
+void mul_v3_m3v3(float r[3], float M[3][3], float a[3]);
+void mul_v2_m3v3(float r[2], float M[3][3], float a[3]);
void mul_transposed_m3_v3(float M[3][3], float r[3]);
void mul_transposed_mat3_m4_v3(float M[4][4], float r[3]);
void mul_m3_v3_double(float M[3][3], double r[3]);
@@ -143,7 +143,7 @@ void mul_m4_v4d(float M[4][4], double r[4]);
void mul_v4d_m4v4d(double r[4], float M[4][4], double v[4]);
/* double matrix functions (no mixing types) */
-void mul_v3_m3v3_db(double r[3], double M[3][3], const double a[3]);
+void mul_v3_m3v3_db(double r[3], double M[3][3], double a[3]);
void mul_m3_v3_db(double M[3][3], double r[3]);
@@ -23,7 +23,9 @@
#
# ***** END GPL LICENSE BLOCK *****
-SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})
+if (WITH_CPP_CORE)
+ SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})
+endif()
set(INC
.
@@ -470,7 +470,7 @@ void BLI_box_pack_2d(BoxPack *boxarray, const unsigned int len, float *r_tot_x,
tot_y = max_ff(box_ymax_get(box), tot_y);
/* Place the box */
- vert->free &= static_cast<signed char>( ~quad_flag(j) );

This comment has been minimized.

Show comment
Hide comment
@hartsantler

hartsantler May 21, 2017

Owner

static_cast and other c++ only syntax should be avoided to maintain C backwards compatibility in as much of blender coder as possible.

@hartsantler

hartsantler May 21, 2017

Owner

static_cast and other c++ only syntax should be avoided to maintain C backwards compatibility in as much of blender coder as possible.

+ vert->free &= (signed char)( ~quad_flag(j) );
switch (j) {
case TR:
@@ -57,7 +57,7 @@ void BLI_callback_global_init(void)
void BLI_callback_global_finalize(void)
{
//eCbEvent evt; // this is just an enum
- auto evt = 0;
+ int evt = 0;
for (evt = 0; evt < BLI_CB_EVT_TOT; evt++) {
ListBase *lb = &callback_slots[evt];
bCallbackFuncStore *funcstore;
@@ -578,43 +578,37 @@ void mul_m4_v4d(float mat[4][4], double r[4])
mul_v4d_m4v4d(r, mat, r);
}
-void mul_v3_m3v3(float r[3], float M[3][3], const float a[3])
-{
+void mul_v3_m3v3(float r[3], float M[3][3], float a[3]) {
BLI_assert(r != a);
-
r[0] = M[0][0] * a[0] + M[1][0] * a[1] + M[2][0] * a[2];
r[1] = M[0][1] * a[0] + M[1][1] * a[1] + M[2][1] * a[2];
r[2] = M[0][2] * a[0] + M[1][2] * a[1] + M[2][2] * a[2];
}
-//void mul_v3_m3v3_db(double r[3], double M[3][3], const double a[3]) {
void mul_v3_m3v3_db(double r[3], double M[3][3], double a[3]) {
BLI_assert(r != a);
-
r[0] = M[0][0] * a[0] + M[1][0] * a[1] + M[2][0] * a[2];
r[1] = M[0][1] * a[0] + M[1][1] * a[1] + M[2][1] * a[2];
r[2] = M[0][2] * a[0] + M[1][2] * a[1] + M[2][2] * a[2];
}
-//void mul_v2_m3v3(float r[2], float M[3][3], const float a[3]) {
void mul_v2_m3v3(float r[2], float M[3][3], float a[3]) {
BLI_assert(r != a);
-
r[0] = M[0][0] * a[0] + M[1][0] * a[1] + M[2][0] * a[2];
r[1] = M[0][1] * a[0] + M[1][1] * a[1] + M[2][1] * a[2];
}
void mul_m3_v3(float M[3][3], float r[3])
{
//mul_v3_m3v3(r, M, (const float[3]){UNPACK3(r)}); // OLD C
- auto v = r; // copy
+ float v[3] = {r[0], r[1], r[2]}; // copy
mul_v3_m3v3(r, M, v);
}
void mul_m3_v3_db(double M[3][3], double r[3])
{
//mul_v3_m3v3_db(r, M, (const double[3]){UNPACK3(r)}); // OLD C
- auto v = r; // copy
+ double v[3] = {r[0], r[1], r[2]}; // copy
mul_v3_m3v3_db(r, M, v);
}
@@ -216,7 +216,7 @@ size_t BLI_vsnprintf(char *__restrict buffer, size_t maxncpy, const char *__rest
BLI_assert(maxncpy > 0);
BLI_assert(format != NULL);
- auto n = vsnprintf(buffer, maxncpy, format, arg);
+ int n = vsnprintf(buffer, maxncpy, format, arg);
if (n != -1 && n < (size_t)maxncpy) {
buffer[n] = '\0';
@@ -237,7 +237,7 @@ size_t BLI_vsnprintf_rlen(char *__restrict buffer, size_t maxncpy, const char *_
BLI_assert(maxncpy > 0);
BLI_assert(format != NULL);
- auto n = vsnprintf(buffer, maxncpy, format, arg);
+ int n = vsnprintf(buffer, maxncpy, format, arg);
if (n != -1 && n < (size_t)maxncpy) {
/* pass */
@@ -23,7 +23,9 @@
#
# ***** END GPL LICENSE BLOCK *****
-SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})
+if (WITH_CPP_CORE)
+ SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})
+endif()
set(INC
.
@@ -23,7 +23,9 @@
#
# ***** END GPL LICENSE BLOCK *****
-SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})
+if (WITH_CPP_CORE)
+ SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})
+endif()
set(INC
.
@@ -100,7 +100,7 @@
*
* Smooths vertices by using a basic vertex averaging scheme. eBMOpSlotSubType_Elem
*/
-static BMOpDefine bmo_smooth_vert_def = BMOpDefine{
+static BMOpDefine bmo_smooth_vert_def = {
"smooth_vert",
/* slots_in */
{{"verts", BMO_OP_SLOT_ELEMENT_BUF, {BMO_OP_SLOT_SUBTYPE_ELEM_VERT}}, /* input vertices */
@@ -44,7 +44,7 @@ void bmo_mesh_to_bmesh_exec(BMesh *bm, BMOperator *op)
Object *ob = BMO_slot_ptr_get(op->slots_in, "object");
Mesh *me = BMO_slot_ptr_get(op->slots_in, "mesh");
bool set_key = BMO_slot_bool_get(op->slots_in, "use_shapekey");
- auto mparams = BMeshFromMeshParams{};
+ struct BMeshFromMeshParams mparams;
mparams.use_shapekey = set_key; mparams.active_shapekey = ob->shapenr;
BM_mesh_bm_from_me(bm, me, &mparams);
@@ -18,8 +18,9 @@
#
# ***** END GPL LICENSE BLOCK *****
-## force C++ for all editors ##
-SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})
+if (WITH_CPP_CORE)
+ SET(CMAKE_C_COMPILER ${CMAKE_CXX_COMPILER})
+endif()
if(WITH_BLENDER)
if(WITH_INPUT_NDOF)
@@ -1021,8 +1021,8 @@ static void rearrange_nla_channels(bAnimContext *ac, AnimData *adt, eRearrangeAn
/* hack: invert mode so that functions will work in right order */
//mode *= -1;
- auto m = static_cast<short>(mode); // is it safe to cast enums like this?
- m *= -1; mode = static_cast<eRearrangeAnimChan_Mode>(m);
+ int m = (int)(mode);
+ m *= -1; mode = (eRearrangeAnimChan_Mode)m;
/* get rearranging function */
rearrange_func = rearrange_get_mode_func(mode);
@@ -293,7 +293,7 @@ static int armature_calc_roll_exec(bContext *C, wmOperator *op)
{
Object *ob = CTX_data_edit_object(C);
//eCalcRollTypes type = RNA_enum_get(op->ptr, "type");
- auto type = RNA_enum_get(op->ptr, "type");
+ int type = RNA_enum_get(op->ptr, "type");
const bool axis_only = RNA_boolean_get(op->ptr, "axis_only");
/* axis_flip when matching the active bone never makes sense */
bool axis_flip = ((type >= CALC_ROLL_ACTIVE) ? RNA_boolean_get(op->ptr, "axis_flip") :
@@ -306,7 +306,7 @@ static void select_adjacent_cp(
lastsel = false;
}
/* move around in zigzag way so that we go through each */
- bezt -= (next - next / std::abs((int)next));
+ bezt -= (next - next / abs((int)next));
}
}
else {
@@ -327,7 +327,7 @@ static void select_adjacent_cp(
lastsel = false;
}
/* move around in zigzag way so that we go through each */
- bp -= (next - next / std::abs((int)next));
+ bp -= (next - next / abs((int)next));
}
}
}
@@ -497,7 +497,7 @@ static void *editbtMesh_to_undoMesh(void *emv, void *obdata)
//BM_mesh_bm_to_me(em->bm, &um->me, (&(struct BMeshToMeshParams){
// .cd_mask_extra = CD_MASK_SHAPE_KEYINDEX,
//}));
- auto params = BMeshToMeshParams{};
+ struct BMeshToMeshParams params;
params.cd_mask_extra = CD_MASK_SHAPE_KEYINDEX;
BM_mesh_bm_to_me(em->bm, &um->me, &params);
um->selectmode = em->selectmode;
@@ -573,7 +573,7 @@ static void undoMesh_to_editbtMesh(void *um_v, void *em_v, void *obdata)
//BM_mesh_bm_from_me( bm, &um->me, (&(struct BMeshFromMeshParams){
// .calc_face_normal = true, .active_shapekey = um->shapenr,
//}));
- auto params = BMeshFromMeshParams{};
+ struct BMeshFromMeshParams params;
params.calc_face_normal = true;
params.active_shapekey = um->shapenr;
BM_mesh_bm_from_me( bm, &um->me, &params );
@@ -734,7 +734,7 @@ int ED_mesh_mirror_spatial_table(Object *ob, BMEditMesh *em, DerivedMesh *dm, co
/** \name Mesh Topology Mirror API
* \{ */
-static MirrTopoStore_t mesh_topo_store = MirrTopoStore_t{NULL, -1, -1, -1};
+static MirrTopoStore_t mesh_topo_store = {NULL, -1, -1, -1};
/* mode is 's' start, or 'e' end, or 'u' use */
/* if end, ob can be NULL */
@@ -4989,10 +4989,10 @@ void sculpt_dynamic_topology_enable(bContext *C)
BKE_mesh_mselect_clear(me);
/* Create triangles-only BMesh */
- auto cparams = BMeshCreateParams{};
+ struct BMeshCreateParams cparams;
cparams.use_toolflags = false;
ss->bm = BM_mesh_create(&allocsize, &cparams);
- auto fparams = BMeshFromMeshParams{};
+ struct BMeshFromMeshParams fparams;
fparams.calc_face_normal = true;
fparams.use_shapekey = true;
fparams.active_shapekey = ob->shapenr;
@@ -526,7 +526,7 @@ static void sculpt_undo_restore(bContext *C, ListBase *lb)
* needs to work correct when exiting/entering sculpt mode and
* the nodes get recreated, though in that case it could do all */
if (partial_update) {
- PartialUpdateData data = {};
+ struct PartialUpdateData data;
data.rebuild = rebuild;
data.pbvh = ss->pbvh;
BKE_pbvh_search_callback(ss->pbvh, NULL, NULL, update_cb_partial, &data);
@@ -2901,13 +2901,13 @@ static void view3d_from_minmax(bContext *C, View3D *v3d, ARegion *ar,
if (rv3d->persp == RV3D_CAMOB && !ED_view3d_camera_lock_check(v3d, rv3d)) {
rv3d->persp = RV3D_PERSP;
- auto vparams = V3D_SmoothParams{};
+ struct V3D_SmoothParams vparams;
vparams.camera_old = v3d->camera; vparams.ofs = new_ofs;
vparams.dist = ok_dist ? &new_dist : NULL;
ED_view3d_smooth_view(C, v3d, ar, smooth_viewtx, &vparams);
}
else {
- auto vparams = V3D_SmoothParams{};
+ struct V3D_SmoothParams vparams;
vparams.ofs = new_ofs;
vparams.dist = ok_dist ? &new_dist : NULL;
ED_view3d_smooth_view(C, v3d, ar, smooth_viewtx, &vparams);
@@ -3241,7 +3241,7 @@ static int viewcenter_cursor_exec(bContext *C, wmOperator *op)
/* non camera center */
float new_ofs[3];
negate_v3_v3(new_ofs, ED_view3d_cursor3d_get(scene, v3d));
- auto vparams = V3D_SmoothParams{};
+ struct V3D_SmoothParams vparams;
vparams.ofs = new_ofs;
ED_view3d_smooth_view(C, v3d, ar, smooth_viewtx, &vparams);
@@ -3290,7 +3290,7 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev
ED_view3d_win_to_3d_int(v3d, ar, new_ofs, event->mval, new_ofs);
}
negate_v3(new_ofs);
- auto vparams = V3D_SmoothParams{};
+ struct V3D_SmoothParams vparams;
vparams.ofs = new_ofs;
ED_view3d_smooth_view(C, v3d, ar, smooth_viewtx, &vparams);
}
@@ -3670,7 +3670,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
/* clamp after because we may have been zooming out */
CLAMP(new_dist, dist_range[0], dist_range[1]);
- auto vparams = V3D_SmoothParams{};
+ struct V3D_SmoothParams vparams;
vparams.ofs = new_ofs; vparams.dist = &new_dist;
ED_view3d_smooth_view( C, v3d, ar, smooth_viewtx, &vparams);
@@ -3827,7 +3827,7 @@ static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar,
if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
/* to camera */
- auto vparams = V3D_SmoothParams{};
+ struct V3D_SmoothParams vparams;
vparams.camera_old = v3d->camera; vparams.ofs = rv3d->ofs; vparams.quat = quat;
ED_view3d_smooth_view(C, v3d, ar, smooth_viewtx,&vparams);
}
@@ -3840,7 +3840,7 @@ static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar,
/* so we animate _from_ the camera location */
ED_view3d_from_object(v3d->camera, rv3d->ofs, NULL, &rv3d->dist, NULL);
- auto vparams = V3D_SmoothParams{};
+ struct V3D_SmoothParams vparams;
vparams.ofs = ofs; vparams.quat = quat; vparams.dist = &dist;
ED_view3d_smooth_view(C, v3d, ar, smooth_viewtx, &vparams);
}
@@ -3857,7 +3857,7 @@ static void axis_set_view(bContext *C, View3D *v3d, ARegion *ar,
}
/* no camera involved */
- auto vparams = V3D_SmoothParams{};
+ V3D_SmoothParams vparams;
vparams.quat = quat; vparams.dyn_ofs = dyn_ofs_pt;
ED_view3d_smooth_view(C, v3d, ar, smooth_viewtx, &vparams);
}
@@ -3950,7 +3950,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
/* finally do snazzy view zooming */
rv3d->persp = RV3D_CAMOB;
- auto vparams = V3D_SmoothParams{};
+ struct V3D_SmoothParams vparams;
vparams.camera = v3d->camera; vparams.ofs = rv3d->ofs; vparams.quat = rv3d->viewquat;
vparams.dist = &rv3d->dist; vparams.lens = &v3d->lens;
ED_view3d_smooth_view(C, v3d, ar, smooth_viewtx, &vparams);
@@ -4081,7 +4081,7 @@ static int vieworbit_exec(bContext *C, wmOperator *op)
dyn_ofs_pt = dyn_ofs;
}
}
- auto vparams = V3D_SmoothParams{};
+ struct V3D_SmoothParams vparams;
vparams.quat = quat_new; vparams.dyn_ofs = dyn_ofs_pt;
ED_view3d_smooth_view(C, v3d, ar, smooth_viewtx,&vparams);
@@ -4267,7 +4267,7 @@ static int viewroll_exec(bContext *C, wmOperator *op)
dyn_ofs_pt = dyn_ofs;
}
}
- auto vparams = V3D_SmoothParams{};
+ struct V3D_SmoothParams vparams;
vparams.quat = quat_new; vparams.dyn_ofs = dyn_ofs_pt;
ED_view3d_smooth_view(C, v3d, ar, smooth_viewtx, &vparams);
Oops, something went wrong.

0 comments on commit 2c845d2

Please sign in to comment.