Repository: FloatingArrayDesign/MoorDyn (language: python)

Issue:
Figuring out how to proceed on Windows
Windows is the worst, because is designed by the monkeys of the monkeys for the monkeys. Unfortunately we shall deal with it, offering a Windows way of life for people wanting to use MoorDyn (i.e. not spending much neurons on the task).

The Python solution is on its way:

https://github.com/FloatingArrayDesign/MoorDyn/pull/132

But on C we have some problems... Mainly because MinGW and MSVC are not compatible. Each one has its merits...

 - MinGW can easily deal with fortran, but it is rather impossible to build the Python wrapper on any modern CPython implementation, i.e. > 3.4 (see https://wiki.python.org/moin/WindowsCompilers#GCC_-_MinGW-w64_.28x86.2C_x64.29). Providing VTK support is also a pain in the ass.
 - MSVC needs a truckload of shit, and if you want the Fortran wrapper you need to add the Intel One SDK, which is another truckload of shit. On the other hand, it can easily deal with Python and VTK.

Thus, I suggest to change the documentation:

 - Recommend to Python users to install it with pip
 - Recommend to Windows C users to use the installer provided on the automatic releases (https://github.com/FloatingArrayDesign/MoorDyn/releases/download/nightly/Moordyn-2.2.0-win64.exe was the last one)
 - Provide a compilation guide for both MSVC and MinGW for more advanced users (if they want to deal with that)

Can any of you, @RyanDavies19 or @AlexWKinley, try out the [Windows installer](https://github.com/FloatingArrayDesign/MoorDyn/releases/download/nightly/Moordyn-2.2.0-win64.exe)? it is a bit outdated, but shall be functional anyway


Discussion / hints:
@sanguinariojoe I am on MacOS so I can't. However someone from the WECSim team has compiled for windows using CMake (with the Matlab wrapper). He said it worked fine once he disabled the Fortran and Python wrappers. @mattEhall if you have some time could you give the window compiling with cmake as well as the installer a shot?
Trying out the windows installer I've thus far run into 2 strange issues. 

Firstly, during the install process, when I ask it to add MoorDyn to the system path the installer throws an error that the system path is too long, and it can't add to it.
![Screenshot 2023-09-21 125326](https://github.com/FloatingArrayDesign/MoorDyn/assets/129765925/8c18968f-484b-48eb-ac91-1c95783669c6)

I'm certainly able to add to the path myself, so I'm not sure what's the cause of this error.

The next issue I ran into when trying to use the installed MoorDyn was that it wanted the moordynf.lib file but it didn't exist.

My cmake file looked like
```
cmake_minimum_required(VERSION 3.10)

project(MDTest)


add_executable(MDTest
    src/main.cpp
)

find_package(MoorDyn REQUIRED)
target_link_libraries(MDTest
    MoorDyn::moodyn
)
```

And the output of running cmake (through vscode) is 
```
[proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -SC:/Users/A.Kinley/Documents/moordyn_install_test -Bc:/Users/A.Kinley/Documents/moordyn_install_test/build -G "Visual Studio 17 2022" -T host=x64 -A x64
[cmake] Not searching for unused variables given on the command line.
[cmake] -- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22621.
[cmake] CMake Error at C:/Program Files/MoorDyn-2.2/lib/cmake/moordyn/MoorDynTargets.cmake:98 (message):
[cmake]   The imported target "MoorDyn::moordynf" references the file
[cmake] 
[cmake]      "C:/Program Files/MoorDyn-2.2/lib/moordynf.lib"
[cmake] 
[cmake]   but this file does not exist.  Possible reasons include:
[cmake] 
[cmake]   * The file was deleted, renamed, or moved to another location.
[cmake] 
[cmake]   * An install or uninstall procedure did not complete successfully.
[cmake] 
[cmake]   * The installation package was faulty and contained
[cmake] 
[cmake]      "C:/Program Files/MoorDyn-2.2/lib/cmake/moordyn/MoorDynTargets.cmake"
[cmake] 
[cmake]   but not all the files it references.
[cmake] 
[cmake] Call Stack (most recent call first):
[cmake]   C:/Program Files/MoorDyn-2.2/lib/cmake/moordyn/MoorDynConfig.cmake:19 (include)
[cmake]   CMakeLists.txt:10 (find_package)
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!
[proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -SC:/Users/A.Kinley/Documents/moordyn_install_test -Bc:/Users/A.Kinley/Documents/moordyn_install_test/build -G "Visual Studio 17 2022" -T host=x64 -A x64 exited with code: 1
```

I'm not familiar enough with how things are set up and the like to know if this is an error of my own causing, or if a file isn't getting included that should be. 

Keep me in the loop if there's anything I can do to help with windows stuff, Kelson primarily uses Windows so I have access to both my development machine and other machines that are yet untouched by MoorDyn.
Argh! Sorry! Totally my bad... the installer (master branch) is way more
outdated than i thought. It is still using the intel one sdk.

I will try to craft you an installer later.

Ty so much!

On Thu, 21 Sept 2023, 19:00 AlexWKinley, ***@***.***> wrote:

> Trying out the windows installer I've thus far run into 2 strange issues.
>
> Firstly, during the install process, when I ask it to add MoorDyn to the
> system path the installer throws an error that the system path is too long,
> and it can't add to it.
> [image: Screenshot 2023-09-21 125326]
> <https://user-images.githubusercontent.com/129765925/269697166-8c18968f-484b-48eb-ac91-1c95783669c6.png>
>
> I'm certainly able to add to the path myself, so I'm not sure what's the
> cause of this error.
>
> The next issue I ran into when trying to use the installed MoorDyn was
> that it wanted the moordynf.lib file but it didn't exist.
>
> My cmake file looked like
>
> cmake_minimum_required(VERSION 3.10)
>
> project(MDTest)
>
>
> add_executable(MDTest
>     src/main.cpp
> )
>
> find_package(MoorDyn REQUIRED)
> target_link_libraries(MDTest
>     MoorDyn::moodyn
> )
>
> And the output of running cmake (through vscode) is
>
> [proc] Executing command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -SC:/Users/A.Kinley/Documents/moordyn_install_test -Bc:/Users/A.Kinley/Documents/moordyn_install_test/build -G "Visual Studio 17 2022" -T host=x64 -A x64
> [cmake] Not searching for unused variables given on the command line.
> [cmake] -- Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.22621.
> [cmake] CMake Error at C:/Program Files/MoorDyn-2.2/lib/cmake/moordyn/MoorDynTargets.cmake:98 (message):
> [cmake]   The imported target "MoorDyn::moordynf" references the file
> [cmake]
> [cmake]      "C:/Program Files/MoorDyn-2.2/lib/moordynf.lib"
> [cmake]
> [cmake]   but this file does not exist.  Possible reasons include:
> [cmake]
> [cmake]   * The file was deleted, renamed, or moved to another location.
> [cmake]
> [cmake]   * An install or uninstall procedure did not complete successfully.
> [cmake]
> [cmake]   * The installation package was faulty and contained
> [cmake]
> [cmake]      "C:/Program Files/MoorDyn-2.2/lib/cmake/moordyn/MoorDynTargets.cmake"
> [cmake]
> [cmake]   but not all the files it references.
> [cmake]
> [cmake] Call Stack (most recent call first):
> [cmake]   C:/Program Files/MoorDyn-2.2/lib/cmake/moordyn/MoorDynConfig.cmake:19 (include)
> [cmake]   CMakeLists.txt:10 (find_package)
> [cmake]
> [cmake]
> [cmake] -- Configuring incomplete, errors occurred!
> [proc] The command: "C:\Program Files\CMake\bin\cmake.EXE" --no-warn-unused-cli -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -SC:/Users/A.Kinley/Documents/moordyn_install_test -Bc:/Users/A.Kinley/Documents/moordyn_install_test/build -G "Visual Studio 17 2022" -T host=x64 -A x64 exited with code: 1
>
> I'm not familiar enough with how things are set up and the like to know if
> this is an error of my own causing, or if a file isn't getting included
> that should be.
>
> Keep me in the loop if there's anything I can do to help with windows
> stuff, Kelson primarily uses Windows so I have access to both my
> development machine and other machines that are yet untouched by MoorDyn.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/FloatingArrayDesign/MoorDyn/issues/135#issuecomment-1729965658>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAMXKKAOSKADK47FQXSYMGLX3RXA7ANCNFSM6AAAAAA5BJ6QWQ>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>

@AlexWKinley you have the new installer [here](https://github.com/core-marine-dev/MoorDyn/releases/tag/v2.2.1). Please, give it a shot
@sanguinariojoe Well besides the same path error problem, it unfortunately still doesn't seem to work, but for a different reason. 

I used the same cmake file (although fixed the typo in target link libraries), and now it succesfully builds, but when trying to run, it tries to find a moordyn.dll, fails, and then exits. It seems like the installer provided a moordyn.lib, which somehow didn't get statically linked I guess? If I look at the executable dependencies, it lists moordyn.dll, and that it didn't find it
![image](https://github.com/FloatingArrayDesign/MoorDyn/assets/129765925/4a8153fc-9143-47cc-8a72-4ebbc21b2d9b)

I'll attach the entire test project folder, including the build folder, in case that provides any useful information. 
I did compile with clang on windows (using the windows toolchain), but compiling with MSVC ran into the same issue, and I figured the ninja files, and clang commands might be a little easier to look through than solution files.

We're in agreement on the frustration of windows. As always let me know what assistance I can provide. 
[moordyn_install_test.zip](https://github.com/FloatingArrayDesign/MoorDyn/files/12702210/moordyn_install_test.zip)


Fix patch:
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3e815cf0..bbfe3912 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,6 +42,8 @@ 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)
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/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()