Skip to content

Commit

Permalink
Build FMUSim GUI for macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sommer committed Sep 16, 2024
1 parent 9793508 commit 7ec129a
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 47 deletions.
21 changes: 19 additions & 2 deletions .github/workflows/build-fmusim-gui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
branches: [ main ]

jobs:
build-fmusim-gui:
build-fmusim-gui-windows:
runs-on: windows-2019
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -39,4 +39,21 @@ jobs:
name: fmusim-gui-x86_64-windows
path: fmusim-gui/build/fmusim-gui/Release
if-no-files-found: error

build-fmusim-gui-macos:
runs-on: macos-12
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install Qt
uses: jurplel/install-qt-action@v4
with:
version: '6.7.1'
modules: 'qtpositioning qtwebchannel qtwebengine'
- run: python -m pip install fmpy requests
- run: python fmusim-gui/build/build_cvode.py
- run: python fmusim-gui/build/build_libxml2.py
- run: python fmusim-gui/build/build_zlib.py
- run: cmake -D CMAKE_PREFIX_PATH=${{env.QT_ROOT_DIR}} -S fmusim-gui -B fmusim-gui/build/fmusim-gui
- run: cmake --build fmusim-gui/build/fmusim-gui --config Release
60 changes: 47 additions & 13 deletions fmusim-gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,26 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "AMD64|x86_64")
set(FMI_ARCHITECTURE "x86_64")
elseif (${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "aarch64")
set(FMI_ARCHITECTURE "aarch64")
else ()
message(FATAL_ERROR "Unknown System Architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif ()

if (WIN32)
set(FMI_PLATFORM "${FMI_ARCHITECTURE}-windows")
elseif (APPLE)
set(FMI_PLATFORM "${FMI_ARCHITECTURE}-darwin")
else ()
set(FMI_PLATFORM "${FMI_ARCHITECTURE}-linux")
endif ()

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
set(CVODE_DIR ${CMAKE_SOURCE_DIR}/build/cvode-x86_64-windows/install)
set(LIBXML2_DIR ${CMAKE_SOURCE_DIR}/build/libxml2-x86_64-windows/install)
set(ZLIB_DIR ${CMAKE_SOURCE_DIR}/build/zlib-x86_64-windows/install)
set(CVODE_DIR ${CMAKE_SOURCE_DIR}/build/cvode-${FMI_PLATFORM}/install)
set(LIBXML2_DIR ${CMAKE_SOURCE_DIR}/build/libxml2-${FMI_PLATFORM}/install)
set(ZLIB_DIR ${CMAKE_SOURCE_DIR}/build/zlib-${FMI_PLATFORM}/install)

set(ZLIB_SRC_DIR ${CMAKE_SOURCE_DIR}/build/zlib-1.3)

Expand All @@ -31,7 +47,6 @@ set(PROJECT_SOURCES
../fmusim/miniunzip.c
${ZLIB_SRC_DIR}/contrib/minizip/unzip.c
${ZLIB_SRC_DIR}/contrib/minizip/ioapi.c
${ZLIB_SRC_DIR}/contrib/minizip/iowin32.c
../fmusim/FMIModelDescription.c
../fmusim/FMIModelDescription.h
../fmusim/FMIBuildDescription.c
Expand All @@ -40,6 +55,15 @@ set(PROJECT_SOURCES
../src/structured_variable_name.yy.c
)

if (WIN32)
set(PROJECT_SOURCES ${PROJECT_SOURCES} ${ZLIB_SRC_DIR}/contrib/minizip/iowin32.c)
elseif (APPLE)
set(MACOSX_BUNDLE_ICON_FILE icon.icns)
set(app_icon_macos "${CMAKE_CURRENT_SOURCE_DIR}/resources/icon/icon.icns")
set_source_files_properties(${app_icon_macos} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
set(PROJECT_SOURCES ${PROJECT_SOURCES} ${app_icon_macos})
endif ()

if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(fmusim-gui
MANUAL_FINALIZATION
Expand Down Expand Up @@ -118,16 +142,26 @@ target_include_directories(fmusim-gui PRIVATE
${CVODE_DIR}/include
)

target_compile_definitions(fmusim-gui PRIVATE
YY_NO_UNISTD_H
)
if (WIN32)
target_compile_definitions(fmusim-gui PRIVATE YY_NO_UNISTD_H)
endif ()

target_link_libraries(fmusim-gui PRIVATE
Qt6::WebEngineWidgets
${LIBXML2_DIR}/lib/libxml2.lib
${ZLIB_DIR}/lib/zlib.lib
${CVODE_DIR}/lib/sundials_cvode.lib
)

if (WIN32)
target_link_libraries(fmusim-gui PRIVATE
Qt6::WebEngineWidgets
${LIBXML2_DIR}/lib/libxml2.lib
${ZLIB_DIR}/lib/zlib.lib
${CVODE_DIR}/lib/sundials_cvode.lib
)
elseif (APPLE)
target_link_libraries(fmusim-gui PRIVATE
Qt6::WebEngineWidgets
${LIBXML2_DIR}/lib/libxml2.dylib
${ZLIB_DIR}/lib/libz.a
${CVODE_DIR}/lib/libsundials_cvode.a
)
endif ()

# Define target properties for Android with Qt 6 as:
# set_property(TARGET fmusim-gui APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
Expand Down
5 changes: 3 additions & 2 deletions fmusim-gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern "C" {
#include "FMISimulation.h"
#include "FMIEuler.h"
#include "FMICVode.h"
#include <string.h>
}

#define FMI_PATH_MAX 4096
Expand Down Expand Up @@ -561,7 +562,7 @@ void MainWindow::simulate() {

const QByteArray ba = unzipdir.toLocal8Bit();

settings->unzipdir = _strdup(ba.data());
settings->unzipdir = strdup(ba.data());
settings->modelDescription = modelDescription;

if (interfaceTypeComboBox->currentText() == "Co-Simulation") {
Expand Down Expand Up @@ -610,7 +611,7 @@ void MainWindow::simulate() {
for (auto [variable, value] : startValues.asKeyValueRange()) {
settings->startVariables[i] = (FMIModelVariable*)variable;
QByteArray buffer = value.toLocal8Bit();
settings->startValues[i] = _strdup(buffer.data());
settings->startValues[i] = strdup(buffer.data());
i++;
}

Expand Down
1 change: 0 additions & 1 deletion fmusim-gui/PlotUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ QString PlotUtil::createPlot(const FMIRecorder* initialRecorder, const FMIRecord
" var layout = {"
" showlegend: false,"
" autosize: true,"
" font: {family: 'Segoe UI', size: 12},"
+ plotColors +
" grid: {rows: " + QString::number(plotVariables.size()) + ", columns: 1, pattern: 'independent'},"
+ axes +
Expand Down
25 changes: 15 additions & 10 deletions fmusim-gui/build/build_cvode.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
from pathlib import Path
from subprocess import check_call
from fmpy.util import download_file
import tarfile
from fmpy import platform_tuple
from fmpy.util import download_file


archive = download_file('https://github.com/LLNL/sundials/releases/download/v6.4.1/cvode-6.4.1.tar.gz',
checksum='0a614e7d7d525d9ec88d5a30c887786d7c3681bd123bb6679fb9a4ec5f4609fe')

root = Path(__file__).parent

build_dir = root / 'cvode-x86_64-windows' / 'build'
install_prefix = root / 'cvode-x86_64-windows' / 'install'
archive = download_file('https://github.com/LLNL/sundials/releases/download/v6.4.1/cvode-6.4.1.tar.gz',
checksum='0a614e7d7d525d9ec88d5a30c887786d7c3681bd123bb6679fb9a4ec5f4609fe')

with tarfile.open(archive) as file:
file.extractall(root)

cmake_args = [
'-G', 'Visual Studio 16 2019',
'-A', 'x64'
]

if platform_tuple == 'x86_64-windows':
cmake_args = [
'-G', 'Visual Studio 16 2019',
'-A', 'x64'
]
else:
cmake_args = []

build_dir = root / f'cvode-{platform_tuple}' / 'build'
install_prefix = root / f'cvode-{platform_tuple}' / 'install'

check_call(
['cmake'] +
Expand Down
22 changes: 12 additions & 10 deletions fmusim-gui/build/build_libxml2.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
from pathlib import Path
from subprocess import check_call
from fmpy import extract, platform_tuple
from fmpy.util import download_file
from fmpy import extract


root = Path(__file__).parent

archive = download_file('https://github.com/GNOME/libxml2/archive/refs/tags/v2.11.5.zip',
checksum='711675470075cc85ba450f56aff7424f1ecdef00bc5d1d5dced3ffecd1a9b772')

root = Path(__file__).parent

extract(archive, root)

build_dir = root / 'libxml2-x86_64-windows' / 'build'

install_prefix = root / 'libxml2-x86_64-windows' / 'install'
if platform_tuple == 'x86_64-windows':
cmake_args = [
'-G', 'Visual Studio 16 2019',
'-A', 'x64'
]
else:
cmake_args = []

cmake_args = [
'-G', 'Visual Studio 16 2019',
'-A', 'x64'
]
build_dir = root / f'libxml2-{platform_tuple}' / 'build'
install_prefix = root / f'libxml2-{platform_tuple}' / 'install'

check_call(
['cmake'] +
Expand Down
20 changes: 12 additions & 8 deletions fmusim-gui/build/build_zlib.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import tarfile
from pathlib import Path
from subprocess import check_call
from fmpy import platform_tuple
from fmpy.util import download_file


root = Path(__file__).parent

archive = download_file('https://www.zlib.net/fossils/zlib-1.3.tar.gz',
checksum='ff0ba4c292013dbc27530b3a81e1f9a813cd39de01ca5e0f8bf355702efa593e')

root = Path(__file__).parent

with tarfile.open(archive) as tf:
tf.extractall(root)

build_dir = root / f'zlib-x86_64-windows' / 'build'

install_prefix = root / f'zlib-x86_64-windows' / 'install'
if platform_tuple == 'x86_64-windows':
cmake_args = [
'-G', 'Visual Studio 16 2019',
'-A', 'x64'
]
else:
cmake_args = []

cmake_args = [
'-G', 'Visual Studio 16 2019',
'-A', 'x64'
]
build_dir = root / f'zlib-{platform_tuple}' / 'build'
install_prefix = root / f'zlib-{platform_tuple}' / 'install'

check_call(
['cmake'] +
Expand Down
3 changes: 2 additions & 1 deletion fmusim-gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ int main(int argc, char *argv[]) {
app.setStyle("Fusion");

QFont font = app.font();
font.setPointSize(10);
// font.setPointSize(10);
app.setFont(font);

MainWindow *window = new MainWindow();
//window->setStyleSheet("QWidget { font-size: 11px; }");
window->show();

for (qsizetype i = 1; i < app.arguments().length(); i++) {
Expand Down
Binary file added fmusim-gui/resources/icon/icon.icns
Binary file not shown.

0 comments on commit 7ec129a

Please sign in to comment.