Browse Source

Setting IK_RESTRICT properly this time. Also refactoring export.h.in

TheComet 8 years ago
parent
commit
ea593632a5

+ 18 - 3
Source/ThirdParty/ik/CMakeLists.txt

@@ -33,9 +33,24 @@ endif ()
 option (IK_MEMORY_DEBUGGING "Global switch for memory options. Keep track of the number of allocations and de-allocations and prints a report when the program shuts down" ${DEFAULT_MEMORY_DEBUGGING})
 cmake_dependent_option (IK_MEMORY_BACKTRACE "Generate backtraces for every malloc(), making it easy to track down memory leaks" "${DEFAULT_MEMORY_DEBUGGING}" "IK_MEMORY_DEBUGGING AND NOT WEB" FALSE)
 
+# Need to set IK_PLATFORM for dllimport/dllexport
+if (WIN32)
+    set (IK_PLATFORM "WINDOWS")
+elseif (APPLE AND ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
+    set (IK_PLATFORM "OSX")
+elseif (IOS)
+    set (IK_PLATFORM "IOS")
+elseif (UNIX)
+    set (IK_PLATFORM "LINUX")
+else ()
+    set (IK_PLATFORM "ANDROID")
+endif ()
+
 # Enable restrict keyword in quaternion and vector operations if not in debug
-if (NOT IK_RESTRICT)
-    set (IK_RESTRICT "")
+# Only do this if IK_RESTRICT is not cached yet.
+get_cmake_property (CACHED_VARS VARIABLES)
+list (FIND CACHED_VARS "IK_RESTRICT" RESULT)
+if (${RESULT} MATCHES -1)
     foreach (RESTRICT_KEYWORD restrict __restrict __restrict__)
         check_c_source_compiles ("int test (void *${RESTRICT_KEYWORD} x); int main (void) {return 0;}" IK_RESTRICT_${RESTRICT_KEYWORD})
         if (IK_RESTRICT_${RESTRICT_KEYWORD})
@@ -43,7 +58,7 @@ if (NOT IK_RESTRICT)
             break ()
         endif ()
     endforeach ()
-    set (IK_RESTRICT ${IK_RESTRICT} CACHE STRING "Restrict Keyword")
+    set (IK_RESTRICT ${IK_RESTRICT} CACHE STRING "Restrict Keyword (may be empty)")
 endif ()
 
 set (IK_REAL float CACHE STRING "Type to use for real numbers")

+ 37 - 65
Source/ThirdParty/ik/include/ik/export.h.in

@@ -2,12 +2,10 @@
  * Export and visibility amcros
  * ----------------------------------------------------------------
  * Substitution variables:
- *  - PROJECT_NAME          : All-caps variable identifying the
- *                            name of the project being built.
- *  - BUILD_TYPE            : Set to either SHARED or STATIC.
+ *  - IK_LIB_TYPE   : Set to either SHARED or STATIC.
+ *  - IK_PLATFORM   : Set to WINDOWS, OSX, LINUX, ANDROID, or IOS
  * Global definitions (non substitution)
- *  - PROJECT_NAME_BUILDING : Define this if the library is being
- *                            built.
+ *  - IK_BUILDING   : Define this if the library is being built.
  * ------------------------------------------------------------- */
 
 #ifndef IK_EXPORT_H
@@ -15,46 +13,45 @@
 
     /* set @BUILD_TYPE@ to SHARED or STATIC */
 #   define IK_@IK_LIB_TYPE@
+#   define IK_PLATFORM_@IK_PLATFORM@
 
     /* --------------------------------------------------------------
      * define visibility macros
      * --------------------------------------------------------------*/
 
-    /* define platform dependent and build dependent visibility macro helpers */
-#   if defined(IK_SHARED)
-#       if defined(IK_PLATFORM_WINDOWS)
-#           if defined(__GNUC__)
-                /* cygwin visbibility */
-#               define IK_HELPER_API_EXPORT __attribute__ ((dllexport))
-#               define IK_HELPER_API_IMPORT __attribute__ ((dllimport))
-#           else
-                /* msvc visibility */
-#               define IK_HELPER_API_EXPORT __declspec(dllexport)
-#               define IK_HELPER_API_IMPORT __declspec(dllimport)
-                /* disable warnings */
-#               pragma warning(disable: 4996) /* 'strcpy': This function or variable may be unsafe */
-#           endif
-#           define IK_HELPER_API_LOCAL
+#   if !defined(IK_SHARED) && !defined(IK_STATIC)
+#       error Please define IK_SHARED or IK_STATIC.
+#   endif
+
+    /* DLL platforms */
+#   if defined(IK_SHARED) && defined(IK_PLATFORM_WINDOWS)
+#       if defined(__GNUC__)
+            /* cygwin visbibility */
+#           define IK_HELPER_API_EXPORT __attribute__ ((dllexport))
+#           define IK_HELPER_API_IMPORT __attribute__ ((dllimport))
 #       else
-#           if __GNUC__ >= 4
-                /* gcc 4+ visibility */
-#               define IK_HELPER_API_EXPORT __attribute__ ((visibility ("default")))
-#               define IK_HELPER_API_IMPORT __attribute__ ((visibility ("default")))
-#               define IK_HELPER_API_LOCAL  __attribute__ ((visibility ("hidden")))
-#           else
-                /* gcc lower than 4 doesn't have any explicit visibility, everything is exported */
-#               define IK_HELPER_API_EXPORT
-#               define IK_HELPER_API_IMPORT
-#               define IK_HELPER_API_LOCAL
-#           endif
+            /* msvc visibility */
+#           define IK_HELPER_API_EXPORT __declspec(dllexport)
+#           define IK_HELPER_API_IMPORT __declspec(dllimport)
 #       endif
-#   elif defined(IK_STATIC)
-        /* static build */
+#       define IK_HELPER_PRIVATE_API
+
+    /* Other platforms, just assume it's GCC/clang */
+#   elif defined(IK_SHARED) && defined(__GNUC__) && __GNUC__ >= 4
+        /* gcc 4+ visibility */
+#       define IK_HELPER_API_EXPORT __attribute__ ((visibility ("default")))
+#       define IK_HELPER_API_IMPORT __attribute__ ((visibility ("default")))
+#       define IK_HELPER_PRIVATE_API  __attribute__ ((visibility ("hidden")))
+
+    /*
+     * All other cases:
+     *   + gcc lower than 4 doesn't have any explicit visibility, everything is exported
+     *   + static libs don't need visibility macros
+     */
+#   else
 #       define IK_HELPER_API_EXPORT
 #       define IK_HELPER_API_IMPORT
-#       define IK_HELPER_API_LOCAL
-#   else
-#       error Please define IK_SHARED or IK_STATIC
+#       define IK_HELPER_PRIVATE_API
 #   endif
 
     /*
@@ -66,39 +63,14 @@
 #   else
 #       define IK_PUBLIC_API IK_HELPER_API_IMPORT
 #   endif
-
-    /*
-     * define local visibility macro. If we're testing, everything
-     * is visible
-     */
-#   if defined(TESTING)
-#       define IK_LOCAL_API IK_PUBLIC_API
-#   else
-#       define IK_LOCAL_API IK_HELPER_API_LOCAL
-#   endif
-
-    /*
-     * define class member visibility macros. If we're testing, everything
-     * is public
-     */
-#   if defined(TESTING)
-#       define PUBLIC public
-#       define PROTECTED public
-#       define PRIVATE public
-#   else
-#       define PUBLIC public
-#       define PROTECTED protected
-#       define PRIVATE private
-#   endif
+#   define IK_PRIVATE_API IK_HELPER_PRIVATE_API
 
     /* --------------------------------------------------------------
-     * typeof support
+     * Disable MSVC warnings
      * --------------------------------------------------------------*/
 
-#   if defined(__GNUC__)
-#       define TYPEOF(x) __typeof__(x)
-#   else
-#       undef TYPEOF
+#   if defined(IK_PLATFORM_WINDOWS) && !defined(__GNUC__)
+#       pragma warning(disable: 4996) /* 'strcpy': This function or variable may be unsafe */
 #   endif
 
     /* --------------------------------------------------------------

+ 1 - 1
Source/ThirdParty/ik/include/ik/solver.h

@@ -185,7 +185,7 @@ ik_solver_iterate_tree(ik_solver_t* solver,
  * positions and rotations for every node in the tree.
  */
 IK_PUBLIC_API void
-ik_solver_reset_to_initial_pose(ik_solver_t* solver);
+ik_solver_reset_to_original_pose(ik_solver_t* solver);
 
 C_HEADER_END
 

+ 4 - 4
Source/ThirdParty/ik/src/solver.c

@@ -227,22 +227,22 @@ ik_solver_iterate_tree(ik_solver_t* solver,
 
 /* ------------------------------------------------------------------------- */
 static void
-reset_solved_data_recursive(ik_node_t* node)
+reset_active_pose_recursive(ik_node_t* node)
 {
     node->position = node->original_position;
     node->rotation = node->initial_rotation;
 
     BSTV_FOR_EACH(&node->children, ik_node_t, guid, child)
-        reset_solved_data_recursive(child);
+        reset_active_pose_recursive(child);
     BSTV_END_EACH
 }
 void
-ik_solver_reset_to_initial_pose(ik_solver_t* solver)
+ik_solver_reset_to_original_pose(ik_solver_t* solver)
 {
     if (solver->tree == NULL)
         return;
 
-    reset_solved_data_recursive(solver->tree);
+    reset_active_pose_recursive(solver->tree);
 }
 
 /* ------------------------------------------------------------------------- */

+ 1 - 1
Source/Urho3D/IK/IKSolver.cpp

@@ -341,7 +341,7 @@ void IKSolver::ApplySceneToActivePose()
 // ----------------------------------------------------------------------------
 void IKSolver::ApplyOriginalPoseToActivePose()
 {
-    ik_solver_reset_to_initial_pose(solver_);
+    ik_solver_reset_to_original_pose(solver_);
 }
 
 // ----------------------------------------------------------------------------