Skip to content

Commit

Permalink
Fix compilation and dependencies
Browse files Browse the repository at this point in the history
Fix Windows dependencies

Added missing dependencies for Appveyor

Added CMakeLists.txt to hopsandcp

Add missing calls to dependency scripts for Appveyor

Correct include directories in CMake

Build all dependencies with ci-build

Added Linux script for setting up DCPLib

Set executable permission  to DCPLib install script

Added include path to libzip

Fix Linux setup script for libzip

Add include paths to Xerces and Asio

Add include path to libzip

Fix compilation error without ZMQ

Remove pause from Xerces setup script

Added missing include

Add patch to DCPLib code to fix a missing include

Add logging define to DCPLib to resolve compilation error

Patch for missing function in DCPLib

Enable LOGGING flag in hopsandcp

Specify release build for Zlib on Windows

Correct use of define in call to CMake

Make Cmake define public

Changed to forward slashes in CMake path

Remove unneeded patch

Added hopsandcp dependency to HopsanGUI

Added libzip dependency to HopsanCore

Patch DCPLib to make IpToString function inlined

Fix release build for zlib

Fix CMake build

Add check for MinGW compiler flag

Add Zlib, add DCPLib to setup scripts

Fix Linux compilation

Compilation fixes

Test local libzip in ci-build

Attempt to fix MSVC compilation

Add Zlib setup script to Appveyor

Attempt to fix MSVC linking

Attempt to fix patch command for msvc

Fix patch for Windows builds

Attempt to link Xerces with MSVC

Find local xerces with msvc

Attempt to fix libzip linking on msvc
  • Loading branch information
robbr48 committed Oct 23, 2024
1 parent 1577954 commit ce8b6f9
Show file tree
Hide file tree
Showing 29 changed files with 405 additions and 74 deletions.
6 changes: 5 additions & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ configuration: Release
install:
- git submodule update --init
- cd dependencies
- download-dependencies.py discount fmilibrary qwt zeromq cppzmq msgpack-c katex tclap fmi4c
- download-dependencies.py discount fmilibrary qwt zeromq cppzmq msgpack-c katex tclap fmi4c xerces asio zlib libzip dcplib
- cd ..
build_script:
# Remove sh.exe from PATH so that CMake works
Expand All @@ -19,6 +19,10 @@ build_script:
- setupDiscount.bat
- setupFMILibrary.bat
- setupFmi4c.bat
- setupXerces.bat
- setupZlib.bat
- setupLibzip.bat
- setupDCPLib.bat
# - setupHDF5.bat (takes to long to build)
- setupKatex.bat
- setupTclap.bat
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Download dependencies
shell: cmd
working-directory: dependencies
run: python download-dependencies.py fmilibrary tclap qwt fmi4c
run: python download-dependencies.py fmilibrary tclap qwt fmi4c xerces asio zlib libzip dcplib

- name: Build dependencies
shell: cmd
Expand All @@ -44,6 +44,10 @@ jobs:
call setupFMILibrary.bat
call setupQwt.bat
call setupFmi4c.bat
call setupXerces.bat
call setupZlib.bat
call setupLibzip.bat
call setupDCPLib.bat
- name: Configure
working-directory: hopsan-build
Expand All @@ -67,7 +71,7 @@ jobs:
- name: Install Packages
run: |
sudo apt-get update
sudo apt-get install qt5-default qtbase5-dev qtbase5-private-dev libqt5webkit5-dev libqt5svg5-dev libqt5opengl5-dev libhdf5-dev libmarkdown2-dev libmsgpack-dev libqwt-qt5-dev libzmq3-dev
sudo apt-get install qt5-default qtbase5-dev qtbase5-private-dev libqt5webkit5-dev libqt5svg5-dev libqt5opengl5-dev libhdf5-dev libmarkdown2-dev libmsgpack-dev libqwt-qt5-dev libzmq3-dev zlib1g zipcmp ziptool zipmerge
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -85,7 +89,7 @@ jobs:
- name: Download dependencies
shell: bash
working-directory: dependencies
run: ./download-dependencies.py fmilibrary tclap fmi4c
run: ./download-dependencies.py fmilibrary tclap fmi4c xerces asio dcplib libzip

- name: Build dependencies
shell: bash
Expand All @@ -94,6 +98,9 @@ jobs:
./setupFMILibrary.sh
./setupTclap.sh
./setupFmi4c.sh
./setupXerces.sh
./setupDCPLib.sh
./setupLibzip.sh
- name: Configure
working-directory: hopsan-build
Expand Down
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ cmake_policy(SET CMP0079 NEW)
set(HOPSANCORE_INSTALL_DST "HopsanCore")
message(WARNING "Hopsan CMake support is still experimental, but should be working for for GCC / MinGW and limited MSVC build")

include(CheckCXXCompilerFlag)
if (MINGW)
check_cxx_compiler_flag("Wa,-mbig-obj" COMPILER_HAS_MBIG_OBJ)
if (${COMPILER_HAS_MBIG_OBJ})
set(CMAKE_CXX_FLAGS -Wa,-mbig-obj)
endif()
endif ()

enable_testing()

add_subdirectory(doc)
add_subdirectory(HopsanCore)
add_subdirectory(componentLibraries)
add_subdirectory(hopsandcp)
add_subdirectory(HopsanCLI)
add_subdirectory(HopsanGUI)
add_subdirectory(HopsanGenerator)
Expand Down
8 changes: 6 additions & 2 deletions HopsanGUI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/../helpers.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../dependencies/qwt.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../dependencies/discount.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../dependencies/katex.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/../dependencies/xerces.cmake)

set(target_name hopsangui)

Expand All @@ -22,7 +23,9 @@ add_executable(${target_name} ${srcfiles})

target_include_directories(${target_name} PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../Utilities>)
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/../Utilities>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../hopsandcp/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../dependencies/libzip/include>)

target_compile_definitions(${target_name} PRIVATE _USE_MATH_DEFINES)
if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
Expand All @@ -31,7 +34,8 @@ if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
endif()

target_link_libraries(${target_name} Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Xml Qt5::Svg Qt5::Network Qt5::Test Qt5::PrintSupport
qwt hopsancore hopsangeneratorgui symhop ops)
qwt hopsancore hopsangeneratorgui symhop ops hopsandcp xercesc )

target_link_optional_libraries(${target_name} libhopsanremoteclient hopsanhdf5exporter discount katex)

set_target_properties(${target_name} PROPERTIES INSTALL_RPATH "\$ORIGIN/../lib")
Expand Down
12 changes: 6 additions & 6 deletions HopsanGUI/GraphicsView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,24 +143,24 @@ void GraphicsView::contextMenuEvent ( QContextMenuEvent * event )
QCursor cursor;
QAction *selectedAction = menu.exec(cursor.pos());

if(selectedAction == addTextBoxAction)
{
if(selectedAction == addTextBoxAction) {
mpContainerObject->getUndoStackPtr()->newPost();
mpContainerObject->addTextBoxWidget(this->mapToScene(event->pos()).toPoint());
}
else if(selectedAction == addImageWidgetAction) {
mpContainerObject->getUndoStackPtr()->newPost();
mpContainerObject->addImageWidget(this->mapToScene(event->pos()).toPoint());
}
else if(addDcpServerAction != nullptr && selectedAction == addDcpServerAction) {
QString dcpPath = QFileDialog::getOpenFileName(gpMainWindowWidget, tr("Select Distributed Co-Simulation Protocol File"),
gpConfig->getStringSetting(CFG_DCPDIR),
gpConfig->getStringSetting(cfg::dir::dcp),
tr("Distributed Co-Simulation Protocol Files (*.dcp)"));
if(dcpPath.isEmpty()) {
return;
}
QFileInfo dcpFileInfo(dcpPath);
gpConfig->setStringSetting(CFG_DCPDIR, dcpFileInfo.absolutePath());

gpConfig->setStringSetting(cfg::dir::dcp, dcpFileInfo.absolutePath());
//Check that DCP server is not already added to model
for(const auto &comp : mpParentModelWidget->getTopLevelSystemContainer()->getModelObjects()) {
if(comp->getParameterValue("dcpFile") == dcpFileInfo.absoluteFilePath()) {
Expand All @@ -171,7 +171,7 @@ void GraphicsView::contextMenuEvent ( QContextMenuEvent * event )

hopsan::HString name, variables, valueRefs;
getDataFromProtocolFile(dcpFileInfo.filePath().toStdString().c_str(), name, variables, valueRefs);

ModelObject *pObj = mpContainerObject->addModelObject(HOPSANGUIDCPCOMPONENT, this->mapToScene(event->pos()).toPoint());
mpParentModelWidget->getTopLevelSystemContainer()->renameModelObject(pObj->getName(), (name.c_str()));
pObj->setParameterValue("dcpFile", dcpFileInfo.absoluteFilePath());
Expand Down
2 changes: 2 additions & 0 deletions HopsanGUI/HopsanGUI.pro
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ have_hdf5(){
}
#--------------------------------------------------------

include($${PWD}/../dependencies/libzip.pri)

#--------------------------------------------------------
# Set HopsanCore Paths
INCLUDEPATH *= $${PWD}/../HopsanCore/include/
Expand Down
4 changes: 2 additions & 2 deletions HopsanGUI/Widgets/ModelWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ void ModelWidget::stopRealtimeSimulation()
bool ModelWidget::simulateDcpServer()
{
// Save backup copy
if (!isSaved() && gpConfig->getBoolSetting(CFG_AUTOBACKUP))
if (!isSaved() && gpConfig->getBoolSetting(cfg::autobackup))
{
//! @todo this should be a help function, also we may not want to call it every time when we run optimization (not sure if that is done now but probably)
QString fileNameWithoutHmf = mpToplevelSystem->getModelFileInfo().fileName();
Expand Down Expand Up @@ -783,7 +783,7 @@ bool ModelWidget::simulateDcpServer()
bool ModelWidget::simulateDcpMaster()
{
// Save backup copy
if (!isSaved() && gpConfig->getBoolSetting(CFG_AUTOBACKUP))
if (!isSaved() && gpConfig->getBoolSetting(cfg::autobackup))
{
//! @todo this should be a help function, also we may not want to call it every time when we run optimization (not sure if that is done now but probably)
QString fileNameWithoutHmf = mpToplevelSystem->getModelFileInfo().fileName();
Expand Down
2 changes: 1 addition & 1 deletion HopsanGUI/Widgets/ModelWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ private slots:
SharedRemoteCoreSimulationHandlerT mpLocalRemoteCoreSimulationHandler;
SharedRemoteCoreSimulationHandlerT mpExternalRemoteCoreSimulationHandler;
SharedRemoteCoreSimulationHandlerT chooseRemoteCoreSimulationHandler() const;
double mSimulationProgress;
#endif
// Remote collected data
double mSimulationProgress;
QVector<RemoteResultVariable> mRemoteResultVariables;
QMutex mSimulateMutex;
};
Expand Down
4 changes: 2 additions & 2 deletions HopsanNG.pro
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ TEMPLATE = subdirs
SUBDIRS = HopsanCore componentLibraries SymHop Ops HopsanGenerator hopsangeneratorgui hopsanremote hopsanhdf5exporter HopsanGUI HopsanCLI UnitTests hopsanc hopsandcp

componentLibraries.depends = HopsanCore
hopsandcp.depends = HopsanCore
HopsanGenerator.depends = HopsanCore SymHop
HopsanCLI.depends = HopsanCore HopsanGenerator hopsanhdf5exporter Ops
HopsanGUI.depends = HopsanCore hopsangeneratorgui hopsanhdf5exporter hopsanremote Ops
HopsanGUI.depends = hopsandcp HopsanCore hopsangeneratorgui hopsanhdf5exporter hopsanremote Ops
hopsanc.depends = HopsanCore
hopsanhdf5exporter.depends = HopsanCore
hopsanremote.depends = HopsanCore
UnitTests.depends = HopsanCore HopsanGenerator componentLibraries
hopsandcp.depends = HopsanCore
4 changes: 4 additions & 0 deletions dependencies/dcplib-patch.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
5c5
< std::string ipToString(const uint32_t ip) {
---
> inline std::string ipToString(const uint32_t ip) {
14 changes: 13 additions & 1 deletion dependencies/dependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

<dependency name="asio">
<releasefile sha1="bac61183b633a6d91ef7ae31836434bdf4f2b0d0">
<url>https://sourceforge.net/projects/asio/files/asio/1.12.1 (Stable)/asio-1.12.1.zip</url>
<url>https://master.dl.sourceforge.net/project/asio/asio/1.12.1%20%28Stable%29/asio-1.12.1.zip</url>
</releasefile>
</dependency>

Expand All @@ -99,11 +99,23 @@
</releasefile>
</dependency>

<dependency name="zlib">
<releasefile sha256="72af66d44fcc14c22013b46b814d5d2514673dda3d115e64b690c1ad636e7b17">
<url>https://github.com/madler/zlib/releases/download/v1.3.1/zlib131.zip</url>
</releasefile>
</dependency>

<dependency name="libzip">
<releasefile sha256="242083351e0a568e6ae69ca05f8eb76ed028807bf39cd8fcb4ea58d409ae0f3f">
<url>https://github.com/nih-at/libzip/archive/v1.7.3.zip</url>
</releasefile>
</dependency>

<dependency name="dcplib">
<releasefile sha256="4acf1115359bb6e8ed351993f27f5ccb7e8f70c208bc33221fb67ab4845f0210">
<url>https://github.com/modelica/DCPLib/archive/refs/tags/v0.2.zip</url>
</releasefile>
</dependency>

<dependency name="mingw-w64" version="5.4.0" type="toolchain">
<releasefile sha1="608c72d6d2fcd91920fc49aa7fd295134bff3010" platform="windows">
Expand Down
33 changes: 33 additions & 0 deletions dependencies/libzip.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set(local_libzip_dir ${CMAKE_CURRENT_LIST_DIR}/libzip)
if(WIN32)
set(CMAKE_FIND_LIBRARY_PREFIXES lib)
endif(WIN32)
find_library(libzip NAMES ${CMAKE_FIND_LIBRARY_PREFIXES}zip ${CMAKE_FIND_LIBRARY_PREFIXES}zip${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_PREFIX}zip${CMAKE_STATIC_LIBRARY_SUFFIX} PATHS ${local_libzip_dir}/lib NO_DEFAULT_PATH)

if (libzip)
message(STATUS "Found local libzip")
add_library(libzip STATIC IMPORTED)
if (MSVC)
set_target_properties(libzip PROPERTIES
IMPORTED_LOCATION ${local_libzip_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}zip${CMAKE_STATIC_LIBRARY_SUFFIX}
INTERFACE_INCLUDE_DIRECTORIES ${local_libzip_dir}/include)
elseif (MINGW)
set_target_properties(libzip PROPERTIES
IMPORTED_LOCATION ${local_libzip_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}zip${CMAKE_SHARED_LIBRARY_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}
INTERFACE_INCLUDE_DIRECTORIES ${local_libzip_dir}/include)
else()
set_target_properties(libzip PROPERTIES
IMPORTED_LOCATION ${local_libzip_dir}/lib/libzip.so
INTERFACE_INCLUDE_DIRECTORIES ${local_libzip_dir}/include)
endif()

else()
message(STATUS "Looking for libzip in system")
find_package(libzip CONFIG) # Search in system
if (libzip_FOUND)
message(STATUS "Found libzip")
add_library(libzip STATIC IMPORTED)
else()
message(WARNING "Could not find libzip")
endif()
endif()
26 changes: 26 additions & 0 deletions dependencies/libzip.pri
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
libzip_dir = $${PWD}/libzip
zlib_dir = $${PWD}/zlib
message(libzip_dir)
exists($${libzip_dir}) {
INCLUDEPATH *= $${libzip_dir}/include
LIBS *= -L$${libzip_dir}/bin -lzip

macx {
# Not supported
} win32 {
src_file = $$quote($${libzip_dir}/bin/libzip.dll)
src_file_zlib = $$quote($${zlib_dir}/bin/libzlib.dll)
dst_dir = $$quote($${PWD}/../bin)
# Replace slashes in paths with backslashes for Windows
src_file ~= s,/,\\,g
src_file_zlib ~= s,/,\\,g
dst_dir ~= s,/,\\,g

QMAKE_POST_LINK += $$QMAKE_COPY $${src_file} $${dst_dir} $$escape_expand(\\n\\t)
QMAKE_POST_LINK += $$QMAKE_COPY $${src_file_zlib} $${dst_dir} $$escape_expand(\\n\\t)
} else {
# Note! The RPATH is absolute and only meant for dev builds in the IDE, on release runtime paths should be stripped
unix:QMAKE_RPATHDIR *= $${libzip_dir/bin}
}
}

3 changes: 3 additions & 0 deletions dependencies/setupAll.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ start /wait cmd /c setupZeroMQ.bat
start /wait cmd /c setupKatex.bat
start /wait cmd /c setupTclap.bat
start /wait cmd /c setupHDF5.bat
start /wait cmd /c setupXerces.bat
start /wait cmd /c setupLibzip.bat
start /wait cmd /c setupDCPLib.bat
2 changes: 1 addition & 1 deletion dependencies/setupAll.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
./setupKatex.sh
./setupTclap.sh
./setupHDF5.sh
./setupAsio.sh
./setupXerces.sh
./setupLibzip.sh
./setupDCPLib.sh
27 changes: 0 additions & 27 deletions dependencies/setupAsio.sh

This file was deleted.

29 changes: 29 additions & 0 deletions dependencies/setupDCPLib.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@ECHO OFF
REM Bat script building libzip dependency automatically

setlocal
set basedir=%~dp0
set name=dcplib
set codedir=%basedir%\%name%-code
set builddir=%basedir%\%name%-build
set installdir=%basedir%\%name%

set xercesdir=%basedir:\=/%xerces

call setHopsanBuildPaths.bat

"%git_path%\..\usr\bin\patch" dcplib-code/include/core/dcp/model/pdu/IpToStr.hpp dcplib-patch.txt

mkdir %builddir%
cd %builddir%
cmake -Wno-dev -G %HOPSAN_BUILD_CMAKE_GENERATOR% -DLOGGING=ON -DASIO_ROOT="%basedir%\asio-code" -DXercesC_LIBRARY="%xercesdir%/bin/libxerces-c.dll" -DXercesC_INCLUDE_DIR="%xercesdir%/include" -DXercesC_VERSION="3.2.2" -DZIP_LIBRARY="%basedir%\libzip\bin\libzip.dll" -DZIP_INCLUDE_DIR="%basedir%\libzip\include" -DCMAKE_INSTALL_PREFIX="%installdir%" %codedir%
cmake --build . --parallel 8
cmake --build . --target install

cd %basedir%
echo.
echo setupDCPLib.bat done
if "%HOPSAN_BUILD_SCRIPT_NOPAUSE%" == "" (
pause
)
endlocal
Loading

0 comments on commit ce8b6f9

Please sign in to comment.