From 4e5928455c0903ef54afb0558917787fe8ff01cd Mon Sep 17 00:00:00 2001 From: Bertrand Coconnier Date: Sun, 23 Jan 2022 23:25:57 +0100 Subject: [PATCH] Generate the MATLAB script to compile the S-Function directly from the folder installed by the Windows installer. See discussion in issue #491. --- .github/workflows/cpp-python-build.yml | 87 +++++++++++++------------- JSBSim.iss.in | 2 +- matlab/CMakeLists.txt | 12 +++- matlab/WindowsSimulinkCompile.m.in | 4 ++ 4 files changed, 60 insertions(+), 45 deletions(-) create mode 100644 matlab/WindowsSimulinkCompile.m.in diff --git a/.github/workflows/cpp-python-build.yml b/.github/workflows/cpp-python-build.yml index a9d149d94f..bf99b112fa 100644 --- a/.github/workflows/cpp-python-build.yml +++ b/.github/workflows/cpp-python-build.yml @@ -227,6 +227,44 @@ jobs: uses: matlab-actions/run-command@v1 with: command: addpath('build/matlab/RelWithDebInfo'), run('matlab/TestJSBSim.m') + + # Build the Windows installer + - name: Checkout JSBSim logos + if: env.release == 'true' && runner.os == 'Windows' + id: InstallLogos + uses: actions/checkout@v2 + with: + repository: JSBSim-Team/jsbsim-logo + path: jsbsim-logo + - name: Build JSBSim installer for Windows + if: steps.InstallLogos.outcome == 'success' + id: BuildInstaller + working-directory: build + run: | + cmake --build . --config RelWithDebInfo --target JSBSim aeromatic + # Relocate the logos for the wizard installer + mkdir logos + cp ..\jsbsim-logo\wizard_installer\*.bmp logos\. + mkdir small + cp ..\jsbsim-logo\wizard_installer\small\*.bmp small\. + # Relocate the executables for the installer + cp src\RelWithDebInfo\JSBSim.exe src\. + cp src\RelWithDebInfo\JSBSim.lib src\. + cp utils\aeromatic++\RelWithDebInfo\aeromatic.exe utils\aeromatic++\. + # Get the MSVC C++ DLL + $Paths = $Env:PATH+';'+[System.Environment]::SystemDirectory + foreach($path in $Paths -split ';') { + if (Test-Path $path) { + $File = Get-ChildItem -Path $path | Where-Object {$_.Name -eq 'msvcp140.dll'} + if ($File) { + cp $File.FullName . + break; + } + } + } + # Compile the installer with Inno Setup + iscc JSBSim.iss + - name: Upload Files for Release (Linux & MacOSX) if: runner.os != 'Windows' uses: actions/upload-artifact@v2 @@ -234,11 +272,13 @@ jobs: name: Matlab-SFunction-${{ runner.os }}.binaries path: build/matlab/JSBSim_SFunction.mex* - name: Upload Files for Release (Windows) - if: runner.os == 'Windows' + if: steps.BuildInstaller.outcome == 'success' uses: actions/upload-artifact@v2 with: name: Matlab-SFunction-${{ runner.os }}.binaries - path: build/matlab/RelWithDebInfo/JSBSim_SFunction.mex* + path: | + build/matlab/RelWithDebInfo/JSBSim_SFunction.mex* + build\Output\*.exe Windows-MinGW32: name: C/C++ build (MinGW32) @@ -356,49 +396,12 @@ jobs: build/Testing/Temporary/*.log build/tests/*-build.log - # Build the Windows installer - - name: Checkout JSBSim logos - if: env.release == 'true' - id: InstallLogos - uses: actions/checkout@v2 - with: - repository: JSBSim-Team/jsbsim-logo - path: jsbsim-logo - - name: Build JSBSim installer for Windows - if: steps.InstallLogos.outcome == 'success' - id: BuildInstaller - working-directory: build - run: | - # Relocate the logos for the wizard installer - mkdir logos - cp ..\jsbsim-logo\wizard_installer\*.bmp logos\. - mkdir small - cp ..\jsbsim-logo\wizard_installer\small\*.bmp small\. - # Relocate the executables for the installer - cp src\RelWithDebInfo\JSBSim.exe src\. - cp src\RelWithDebInfo\JSBSim.lib src\. - cp utils\aeromatic++\RelWithDebInfo\aeromatic.exe utils\aeromatic++\. - # Get the MSVC C++ DLL - $Paths = $Env:PATH+';'+[System.Environment]::SystemDirectory - foreach($path in $Paths -split ';') { - if (Test-Path $path) { - $File = Get-ChildItem -Path $path | Where-Object {$_.Name -eq 'msvcp140.dll'} - if ($File) { - cp $File.FullName . - break; - } - } - } - # Compile the installer with Inno Setup - iscc JSBSim.iss - - name: Upload Files for Release uses: actions/upload-artifact@v2 - if: steps.BuildInstaller.outcome == 'success' + if: env.release == 'true' with: name: ${{ runner.os }}.binaries path: | - build\Output\*.exe build\src\RelWithDebInfo\JSBSim.lib build\python\jsbsim.cxx build\python\setup.py @@ -576,7 +579,7 @@ jobs: build/python/dist/*.whl Rolling-Release: - needs: [ManyLinux-Wheels, MacWin-Wheels, Test-Build-PyPackage-From-Source, Windows-MinGW32] + needs: [ManyLinux-Wheels, MacWin-Wheels, Test-Build-PyPackage-From-Source, Windows-MinGW32, Matlab-SFunction] name: Deploy Rolling Release runs-on: ubuntu-latest if: github.event_name == 'push' && github.ref == 'refs/heads/master' @@ -606,7 +609,7 @@ jobs: dist/*.deb Stable-Release: - needs: [ManyLinux-Wheels, MacWin-Wheels, Test-Build-PyPackage-From-Source, Windows-MinGW32] + needs: [ManyLinux-Wheels, MacWin-Wheels, Test-Build-PyPackage-From-Source, Windows-MinGW32, Matlab-SFunction] name: Deploy Stable Release runs-on: ubuntu-latest if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') diff --git a/JSBSim.iss.in b/JSBSim.iss.in index cdee1ede27..1d5de2f5ee 100644 --- a/JSBSim.iss.in +++ b/JSBSim.iss.in @@ -35,7 +35,7 @@ Source: "${CMAKE_SOURCE_DIR}\src\*.h"; DestDir: "{app}\include"; Flags: recurses Source: "${CMAKE_SOURCE_DIR}\src\*.hxx"; DestDir: "{app}\include"; Flags: recursesubdirs; Components: devfiles Source: "${CMAKE_SOURCE_DIR}\matlab\*.cpp"; DestDir: "{app}\matlab"; Components: devfiles\matlab Source: "${CMAKE_SOURCE_DIR}\matlab\*.h"; DestDir: "{app}\matlab"; Components: devfiles\matlab -Source: "${CMAKE_SOURCE_DIR}\matlab\JSBSimSimulinkCompile.m"; DestDir: "{app}\matlab"; Components: devfiles\matlab +Source: "${CMAKE_BINARY_DIR}\matlab\JSBSimSimulinkCompile.m"; DestDir: "{app}\matlab"; Components: devfiles\matlab Source: "${CMAKE_SOURCE_DIR}\matlab\TestJSBSim.m"; DestDir: "{app}\matlab"; Components: devfiles\matlab Source: "${CMAKE_SOURCE_DIR}\matlab\ex737cruise.slx"; DestDir: "{app}\matlab"; Components: devfiles\matlab Source: "${CMAKE_SOURCE_DIR}\matlab\readme.txt"; DestDir: "{app}\matlab"; Components: devfiles\matlab diff --git a/matlab/CMakeLists.txt b/matlab/CMakeLists.txt index 76c43844f1..445a8f5b35 100644 --- a/matlab/CMakeLists.txt +++ b/matlab/CMakeLists.txt @@ -1,10 +1,18 @@ find_package(Matlab) -set(CMAKE_CXX_STANDARD 14) - if(Matlab_FOUND) matlab_add_mex(NAME JSBSim_SFunction SRC JSBSim_SFunction.cpp JSBSimInterface.cpp LINK_TO libJSBSim) target_include_directories(JSBSim_SFunction PUBLIC ${CMAKE_SOURCE_DIR}/src ${Matlab_ROOT_DIR}/simulink/include) + set_target_properties(JSBSim_SFunction PROPERTIES CXX_STANDARD 14) + + if(MSVC) + foreach(LINK_LIB ${JSBSIM_WINDOWS_LINK_LIBRARIES}) + string(APPEND WINDOWS_LINK_LIBRARIES " ${LINK_LIB}.lib") + endforeach() + + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/WindowsSimulinkCompile.m.in ${CMAKE_CURRENT_BINARY_DIR}/JSBSimSimulinkCompile.m) + endif(MSVC) + endif(Matlab_FOUND) diff --git a/matlab/WindowsSimulinkCompile.m.in b/matlab/WindowsSimulinkCompile.m.in new file mode 100644 index 0000000000..16d05bed59 --- /dev/null +++ b/matlab/WindowsSimulinkCompile.m.in @@ -0,0 +1,4 @@ +% This file is automatically generated. +disp('Compiling S-function from JSBSim...'); +mex -v -R2017b JSBSim_SFunction.cpp JSBSimInterface.cpp -I"..\include" -L"..\lib" -lJSBSim ${WINDOWS_LINK_LIBRARIES} +disp('Finished.')