Repository: FloatingArrayDesign/MoorDyn (language: python)

Issue:
Runtime issue using CMake
I'm not sure at what point things were changed, but MD-C compiled with CMake is now significantly slower compared to MD-C compiled with the makefiles in the `compile/` folder. For the case1 attached file, the table below shows the runtimes from my Mac when simulated for 50 seconds with a static fairlead:

MD-F:
- real    0m3.390s
- user    0m3.216s
- sys     0m0.541s

MD-C compile/DYLIB :
- real    0m2.168s
- user    0m2.337s
- sys     0m0.467s

MD-C build/ :
- real    1m36.923s
- user    1m36.363s
- sys     0m0.583s

[case1.txt](https://github.com/FloatingArrayDesign/MoorDyn/files/12786939/case1.txt)



Discussion / hints:

Fix patch:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3e815cf0..617f55ef 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
 cmake_minimum_required(VERSION 3.10)
 set(MOORDYN_MAJOR_VERSION 2)
 set(MOORDYN_MINOR_VERSION 2)
-set(MOORDYN_PATCH_VERSION 1)
+set(MOORDYN_PATCH_VERSION 2)
 set(MOORDYN_VERSION ${MOORDYN_MAJOR_VERSION}.${MOORDYN_MINOR_VERSION})
 project(Moordyn VERSION ${MOORDYN_VERSION})
 
@@ -25,6 +25,8 @@ set(EXTERNAL_EIGEN OFF CACHE BOOL
     "Use the Eigen3 installed in the system")
 set(USE_VTK OFF CACHE BOOL
     "Link with VTK to produce output binary files")
+set(MOORDYN_PACKAGE_IGNORE_VTK_DEPENDENCY OFF CACHE BOOL
+    "Specifically tells MoorDyn to ignore the VTK dependency on the exported package. This can be useful if VTK was linked statically")
 set(FORTRAN_WRAPPER OFF CACHE BOOL
     "Build the Fortran module")
 set(MATLAB_WRAPPER OFF CACHE BOOL
@@ -40,11 +42,23 @@ set(MOORDYN_SINGLEPRECISSION OFF CACHE BOOL
 set(MOORDYN_SSE "OFF" CACHE STRING "Use enhanced instructions set")
 set_property(CACHE MOORDYN_SSE PROPERTY STRINGS OFF SSE SSE2 SSE4 AVX AVX2 AVX512)
 set(MOORDYN_FASTMATH OFF CACHE BOOL "Enhances performance at the cost of accuracy")
+
+mark_as_advanced(MOORDYN_PACKAGE_IGNORE_VTK_DEPENDENCY)
 mark_as_advanced(PYTHON_WRAPPER_USERINSTALL)
 mark_as_advanced(MOORDYN_SINGLEPRECISSION)
 mark_as_advanced(MOORDYN_SSE)
 mark_as_advanced(MOORDYN_FASTMATH)
 
+# Set RelWithDebInfo as the default build type
+if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+  message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
+  set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE
+      STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel" FORCE)
+  # Set the possible values of build type for cmake-gui
+  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
+    "None" "Debug" "Release" "RelWithDebInfo" "MinSizeRel")
+endif()
+
 # Look for the dependencies
 if(${USE_VTK})
     find_package(VTK
@@ -147,6 +161,14 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
 endif()
 if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) AND BUILD_TESTING)
     add_subdirectory(extern/Catch2)
+    get_cmake_property(_variableNames VARIABLES)
+    list (SORT _variableNames)
+    foreach (_variableName ${_variableNames})
+        string(FIND "${_variableName}" "CATCH_CONFIG" out)
+        if("${out}" EQUAL 0)
+            mark_as_advanced(${_variableName})
+        endif()
+    endforeach()
     add_subdirectory(tests)
 endif()
 
diff --git a/cmake/MoorDynConfig.cmake b/cmake/MoorDynConfig.cmake
index adda8dab..08a7cad3 100644
--- a/cmake/MoorDynConfig.cmake
+++ b/cmake/MoorDynConfig.cmake
@@ -2,6 +2,7 @@ include(CMakeFindDependencyMacro)
 
 set(MOORDYN_EXTERNAL_EIGEN @EXTERNAL_EIGEN@)
 set(MOORDYN_USE_VTK @USE_VTK@)
+set(MOORDYN_SKIP_VTK_DEP @MOORDYN_PACKAGE_IGNORE_VTK_DEPENDENCY@)
 set(MOORDYN_PYTHON_WRAPPER @PYTHON_WRAPPER@)
 set(MOORDYN_FORTRAN_WRAPPER @FORTRAN_WRAPPER@)
 set(MOORDYN_MATLAB_WRAPPER @MATLAB_WRAPPER@)
@@ -12,7 +13,7 @@ set(MOORDYN_FASTMATH @MOORDYN_FASTMATH@)
 if(MOORDYN_EXTERNAL_EIGEN)
     find_dependency(Eigen3)
 endif()
-if(MOORDYN_USE_VTK)
+if(MOORDYN_USE_VTK AND NOT MOORDYN_SKIP_VTK_DEP)
     find_dependency(VTK)
 endif()
 
diff --git a/source/Body.cpp b/source/Body.cpp
index c68eaa54..0eda87f5 100644
--- a/source/Body.cpp
+++ b/source/Body.cpp
@@ -305,7 +305,7 @@ real
 Body::GetBodyOutput(OutChanProps outChan)
 {
 
-	vec3 rotations = Quat2Euler(r7.quat);
+	vec3 rotations = rad2deg * Quat2Euler(r7.quat);
 
 	if (outChan.QType == PosX)
 		return r7.pos.x();
diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index 3985b3ad..94d675f8 100644
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -51,12 +51,25 @@ set(MOORDYN_HEADERS
 )
 
 set(MOORDYN_PUBLIC_DEPS "")
+set(MOORDYN_PRIVATE_DEPS "")
 if(USE_VTK)
-    list(APPEND MOORDYN_PUBLIC_DEPS VTK::CommonCore
-                                    VTK::IOCore
-                                    VTK::IOXML
-                                    VTK::IOGeometry
-                                    VTK::FiltersGeneral)
+    if(MOORDYN_PACKAGE_IGNORE_VTK_DEPENDENCY)
+        list(APPEND MOORDYN_PRIVATE_DEPS VTK::CommonCore
+                                         VTK::IOCore
+                                         VTK::IOXML
+                                         VTK::IOGeometry
+                                         VTK::FiltersGeneral)
+        get_target_property(MOORDYN_PRIVATE_INCLUDE_DIRS
+                            VTK::CommonCore
+                            INTERFACE_INCLUDE_DIRECTORIES)
+    else()
+        list(APPEND MOORDYN_PUBLIC_DEPS VTK::CommonCore
+                                        VTK::IOCore
+                                        VTK::IOXML
+                                        VTK::IOGeometry
+                                        VTK::FiltersGeneral)
+        set(MOORDYN_PRIVATE_INCLUDE_DIRS "")
+    endif()
     list(APPEND MOORDYN_HEADERS Util/VTK_Util.hpp)
     list(APPEND MOORDYN_SRCS Util/VTK_Util.cpp)
 endif()
@@ -86,7 +99,9 @@ if(${CMAKE_VERSION} VERSION_GREATER "3.15")
   endif()
 endif()
 target_compile_definitions(moordyn PUBLIC MoorDyn_EXPORTS)
-target_link_libraries(moordyn PUBLIC ${MOORDYN_PUBLIC_DEPS})
+target_link_libraries(moordyn PUBLIC ${MOORDYN_PUBLIC_DEPS}
+                              PRIVATE ${MOORDYN_PRIVATE_DEPS})
+target_include_directories(moordyn PRIVATE ${MOORDYN_PRIVATE_INCLUDE_DIRS})
 
 install(TARGETS moordyn EXPORT MoorDynTargets
   LIBRARY DESTINATION lib


Test patch:
diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml
index 36daddf5..9411de56 100644
--- a/.github/workflows/build-test.yml
+++ b/.github/workflows/build-test.yml
@@ -2,7 +2,7 @@ name: CMake
 
 on:
   push:
-    branches: [ $default-branch, master ]
+    branches: [ $default-branch, master, releases ]
   pull_request:
     branches:
       - "**"
@@ -108,16 +108,12 @@ jobs:
           tar -xvzf vtk-${{runner.os}}-x86_64.tar.gz -C vtk/
 
     - name: Configure CMake (Linux)
-      run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DEXTERNAL_EIGEN:BOOL=OFF -DPYTHON_WRAPPER:BOOL=OFF -DFORTRAN_WRAPPER:BOOL=ON -DRUST_WRAPPER:BOOL=OFF -DUSE_VTK=ON -DVTK_DIR=${{github.workspace}}/vtk/lib/cmake/vtk-${{env.VTK_VERSION_MAJOR}}.${{env.VTK_VERSION_MINOR}}/ -DBUILD_TESTING=ON
+      run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DEXTERNAL_EIGEN:BOOL=OFF -DPYTHON_WRAPPER:BOOL=OFF -DFORTRAN_WRAPPER:BOOL=ON -DRUST_WRAPPER:BOOL=OFF -DUSE_VTK=ON -DVTK_DIR=${{github.workspace}}/vtk/lib/cmake/vtk-${{env.VTK_VERSION_MAJOR}}.${{env.VTK_VERSION_MINOR}}/ -DMOORDYN_PACKAGE_IGNORE_VTK_DEPENDENCY=ON -DBUILD_TESTING=ON
       if: runner.os == 'Linux'
 
-    - name: Configure CMake (Windows)
-      run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DEXTERNAL_EIGEN:BOOL=OFF -DPYTHON_WRAPPER:BOOL=OFF -DFORTRAN_WRAPPER:BOOL=OFF -DRUST_WRAPPER:BOOL=OFF -DUSE_VTK=ON -DVTK_DIR=${{github.workspace}}/vtk/lib/cmake/vtk-${{env.VTK_VERSION_MAJOR}}.${{env.VTK_VERSION_MINOR}}/ -DBUILD_TESTING=ON
-      if: runner.os == 'Windows'
-
-    - name: Configure CMake (Mac)
-      run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DEXTERNAL_EIGEN:BOOL=OFF -DPYTHON_WRAPPER:BOOL=OFF -DFORTRAN_WRAPPER:BOOL=OFF -DRUST_WRAPPER:BOOL=OFF -DUSE_VTK=ON -DVTK_DIR=${{github.workspace}}/vtk/lib/cmake/vtk-${{env.VTK_VERSION_MAJOR}}.${{env.VTK_VERSION_MINOR}}/ -DBUILD_TESTING=ON
-      if: runner.os == 'macOS'
+    - name: Configure CMake (Windows & MacOS)
+      run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_INSTALL_PREFIX=${{github.workspace}}/install -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON -DEXTERNAL_EIGEN:BOOL=OFF -DPYTHON_WRAPPER:BOOL=OFF -DFORTRAN_WRAPPER:BOOL=OFF -DRUST_WRAPPER:BOOL=OFF -DUSE_VTK=ON -DVTK_DIR=${{github.workspace}}/vtk/lib/cmake/vtk-${{env.VTK_VERSION_MAJOR}}.${{env.VTK_VERSION_MINOR}}/ -DMOORDYN_PACKAGE_IGNORE_VTK_DEPENDENCY=ON -DBUILD_TESTING=ON
+      if: runner.os != 'Linux'
 
     - name: Build
       id: build
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 57408555..8257f9bd 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -42,8 +42,21 @@ set(CATCH2_TESTS
 )
 
 function(make_executable test_name)
+    set(TEST_PRIVATE_DEPS "moordyn;")
     add_executable(${test_name} ${test_name}.cpp)
-    target_link_libraries(${test_name} PRIVATE moordyn)
+    if(USE_VTK AND MOORDYN_PACKAGE_IGNORE_VTK_DEPENDENCY)
+        list(APPEND TEST_PRIVATE_DEPS VTK::CommonCore
+                                         VTK::IOCore
+                                         VTK::IOXML
+                                         VTK::IOGeometry
+                                         VTK::FiltersGeneral)
+        get_target_property(TEST_PRIVATE_INCLUDE_DIRS
+                            VTK::CommonCore
+                            INTERFACE_INCLUDE_DIRECTORIES)
+        target_include_directories(${test_name}
+                                   PRIVATE ${TEST_PRIVATE_INCLUDE_DIRS})
+    endif()
+    target_link_libraries(${test_name} PRIVATE ${TEST_PRIVATE_DEPS})
     add_dependencies(${test_name} Test_MooringConfigFiles)
 endfunction()