From ce8b6f9db4af0ec9878742a02fec8cc9907ca1ce Mon Sep 17 00:00:00 2001 From: Robert Braun Date: Fri, 11 Oct 2024 15:35:58 +0200 Subject: [PATCH] Fix compilation and dependencies 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 --- .appveyor.yml | 6 +++- .github/workflows/ci-build.yaml | 13 +++++++-- CMakeLists.txt | 9 ++++++ HopsanGUI/CMakeLists.txt | 8 ++++-- HopsanGUI/GraphicsView.cpp | 12 ++++---- HopsanGUI/HopsanGUI.pro | 2 ++ HopsanGUI/Widgets/ModelWidget.cpp | 4 +-- HopsanGUI/Widgets/ModelWidget.h | 2 +- HopsanNG.pro | 4 +-- dependencies/dcplib-patch.txt | 4 +++ dependencies/dependencies.xml | 14 ++++++++- dependencies/libzip.cmake | 33 ++++++++++++++++++++++ dependencies/libzip.pri | 26 +++++++++++++++++ dependencies/setupAll.bat | 3 ++ dependencies/setupAll.sh | 2 +- dependencies/setupAsio.sh | 27 ------------------ dependencies/setupDCPLib.bat | 29 +++++++++++++++++++ dependencies/setupDCPLib.sh | 35 +++++++++++++++++++++++ dependencies/setupLibzip.bat | 32 +++++++++++++++++++++ dependencies/setupLibzip.sh | 6 ++-- dependencies/setupXerces.bat | 28 ++++++++++++++++++ dependencies/setupZlib.bat | 25 ++++++++++++++++ dependencies/xerces.cmake | 40 ++++++++++++++++++++++++++ dependencies/xerces.pri | 25 ++++++++++++++++ hopsandcp/CMakeLists.txt | 47 +++++++++++++++++++++++++++++++ hopsandcp/dependencies/DCPLib | 1 - hopsandcp/hopsandcp.pro | 33 ++++++++-------------- hopsandcp/src/dcpmaster.cpp | 6 ++-- hopsandcp/src/dcpserver.cpp | 3 +- 29 files changed, 405 insertions(+), 74 deletions(-) create mode 100644 dependencies/dcplib-patch.txt create mode 100644 dependencies/libzip.cmake create mode 100644 dependencies/libzip.pri delete mode 100755 dependencies/setupAsio.sh create mode 100644 dependencies/setupDCPLib.bat create mode 100755 dependencies/setupDCPLib.sh create mode 100644 dependencies/setupLibzip.bat create mode 100644 dependencies/setupXerces.bat create mode 100644 dependencies/setupZlib.bat create mode 100644 dependencies/xerces.cmake create mode 100644 dependencies/xerces.pri create mode 100644 hopsandcp/CMakeLists.txt delete mode 160000 hopsandcp/dependencies/DCPLib diff --git a/.appveyor.yml b/.appveyor.yml index 3596e82a32..d81d7a5faa 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -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 @@ -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 diff --git a/.github/workflows/ci-build.yaml b/.github/workflows/ci-build.yaml index b45067d9e2..db8436146b 100644 --- a/.github/workflows/ci-build.yaml +++ b/.github/workflows/ci-build.yaml @@ -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 @@ -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 @@ -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 @@ -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 @@ -94,6 +98,9 @@ jobs: ./setupFMILibrary.sh ./setupTclap.sh ./setupFmi4c.sh + ./setupXerces.sh + ./setupDCPLib.sh + ./setupLibzip.sh - name: Configure working-directory: hopsan-build diff --git a/CMakeLists.txt b/CMakeLists.txt index cc1bb12d40..5cbe7f9d03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/HopsanGUI/CMakeLists.txt b/HopsanGUI/CMakeLists.txt index f14eb01077..fa71ec5996 100644 --- a/HopsanGUI/CMakeLists.txt +++ b/HopsanGUI/CMakeLists.txt @@ -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) @@ -22,7 +23,9 @@ add_executable(${target_name} ${srcfiles}) target_include_directories(${target_name} PRIVATE $ - $) + $ + $ + $) target_compile_definitions(${target_name} PRIVATE _USE_MATH_DEFINES) if(NOT CMAKE_BUILD_TYPE MATCHES Debug) @@ -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") diff --git a/HopsanGUI/GraphicsView.cpp b/HopsanGUI/GraphicsView.cpp index 6a9c4c7f46..89e3c83b1f 100644 --- a/HopsanGUI/GraphicsView.cpp +++ b/HopsanGUI/GraphicsView.cpp @@ -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()) { @@ -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()); diff --git a/HopsanGUI/HopsanGUI.pro b/HopsanGUI/HopsanGUI.pro index 1b10309eaf..311ca1c011 100644 --- a/HopsanGUI/HopsanGUI.pro +++ b/HopsanGUI/HopsanGUI.pro @@ -80,6 +80,8 @@ have_hdf5(){ } #-------------------------------------------------------- +include($${PWD}/../dependencies/libzip.pri) + #-------------------------------------------------------- # Set HopsanCore Paths INCLUDEPATH *= $${PWD}/../HopsanCore/include/ diff --git a/HopsanGUI/Widgets/ModelWidget.cpp b/HopsanGUI/Widgets/ModelWidget.cpp index c0cac001b5..29e46c23d8 100644 --- a/HopsanGUI/Widgets/ModelWidget.cpp +++ b/HopsanGUI/Widgets/ModelWidget.cpp @@ -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(); @@ -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(); diff --git a/HopsanGUI/Widgets/ModelWidget.h b/HopsanGUI/Widgets/ModelWidget.h index f75b0e1b5d..887983a6dc 100644 --- a/HopsanGUI/Widgets/ModelWidget.h +++ b/HopsanGUI/Widgets/ModelWidget.h @@ -190,9 +190,9 @@ private slots: SharedRemoteCoreSimulationHandlerT mpLocalRemoteCoreSimulationHandler; SharedRemoteCoreSimulationHandlerT mpExternalRemoteCoreSimulationHandler; SharedRemoteCoreSimulationHandlerT chooseRemoteCoreSimulationHandler() const; - double mSimulationProgress; #endif // Remote collected data + double mSimulationProgress; QVector mRemoteResultVariables; QMutex mSimulateMutex; }; diff --git a/HopsanNG.pro b/HopsanNG.pro index 777329f56a..216979127c 100644 --- a/HopsanNG.pro +++ b/HopsanNG.pro @@ -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 diff --git a/dependencies/dcplib-patch.txt b/dependencies/dcplib-patch.txt new file mode 100644 index 0000000000..1ce35b6332 --- /dev/null +++ b/dependencies/dcplib-patch.txt @@ -0,0 +1,4 @@ +5c5 +< std::string ipToString(const uint32_t ip) { +--- +> inline std::string ipToString(const uint32_t ip) { diff --git a/dependencies/dependencies.xml b/dependencies/dependencies.xml index fd067d075d..95bc239bd8 100644 --- a/dependencies/dependencies.xml +++ b/dependencies/dependencies.xml @@ -89,7 +89,7 @@ - https://sourceforge.net/projects/asio/files/asio/1.12.1 (Stable)/asio-1.12.1.zip + https://master.dl.sourceforge.net/project/asio/asio/1.12.1%20%28Stable%29/asio-1.12.1.zip @@ -99,11 +99,23 @@ + + + https://github.com/madler/zlib/releases/download/v1.3.1/zlib131.zip + + + https://github.com/nih-at/libzip/archive/v1.7.3.zip + + + + https://github.com/modelica/DCPLib/archive/refs/tags/v0.2.zip + + diff --git a/dependencies/libzip.cmake b/dependencies/libzip.cmake new file mode 100644 index 0000000000..741d1fb160 --- /dev/null +++ b/dependencies/libzip.cmake @@ -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() diff --git a/dependencies/libzip.pri b/dependencies/libzip.pri new file mode 100644 index 0000000000..e8c4f8fee4 --- /dev/null +++ b/dependencies/libzip.pri @@ -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} + } +} + diff --git a/dependencies/setupAll.bat b/dependencies/setupAll.bat index baeaadfbd7..ef78d27e92 100644 --- a/dependencies/setupAll.bat +++ b/dependencies/setupAll.bat @@ -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 diff --git a/dependencies/setupAll.sh b/dependencies/setupAll.sh index 7336fc38e4..60613a4c02 100755 --- a/dependencies/setupAll.sh +++ b/dependencies/setupAll.sh @@ -8,6 +8,6 @@ ./setupKatex.sh ./setupTclap.sh ./setupHDF5.sh -./setupAsio.sh ./setupXerces.sh ./setupLibzip.sh +./setupDCPLib.sh diff --git a/dependencies/setupAsio.sh b/dependencies/setupAsio.sh deleted file mode 100755 index 5cbe818dcb..0000000000 --- a/dependencies/setupAsio.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# $Id$ - -# Shell script building HopsaGUI dependency Asio automatically - -basedir=`pwd` -name=asio -codedir=${basedir}/${name}-code -builddir=${basedir}/${name}-build -installdir=${basedir}/${name} - -# Download and verify -./download-dependencies.py ${name} - -# Copy code to build dir, not sure if out-of-source build is possible -mkdir -p $builddir -pushd $builddir -cp -a $codedir/* . - -# Generate makefiles -chmod u+x ./configure -./configure --prefix=$installdir --without-boost -cd include -make install - -popd -echo "setupAsio.sh done!" diff --git a/dependencies/setupDCPLib.bat b/dependencies/setupDCPLib.bat new file mode 100644 index 0000000000..dc777987ae --- /dev/null +++ b/dependencies/setupDCPLib.bat @@ -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 diff --git a/dependencies/setupDCPLib.sh b/dependencies/setupDCPLib.sh new file mode 100755 index 0000000000..03a62e542c --- /dev/null +++ b/dependencies/setupDCPLib.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Shell script building Hopsan dependency DCPLib + +basedir=$(pwd) + +name=dcplib +codedir=${basedir}/${name}-code +builddir=${basedir}/${name}-build +installdir=${basedir}/${name} +xercesdir=${basedir}/xerces + +# Download and verify +./download-dependencies.py ${name} + +#Patch code to fix bug +patch dcplib-code/include/core/dcp/model/pdu/IpToStr.hpp dcplib-patch.txt + +# Include general settings +source setHopsanBuildPaths.sh + +# Create build dir and enter it +mkdir -p $builddir +cd $builddir + +# Generate makefiles +cmake -Wno-dev -DLOGGING=ON -DASIO_ROOT="${basedir}/asio-code" -DXercesC_LIBRARY="${xercesdir}/bin/libxerces-c" -DXercesC_INCLUDE_DIR="${xercesdir}/include" -DXercesC_VERSION="3.2.2" -DZIP_LIBRARY="${basedir}/libzip/bin/libzip" -DZIP_INCLUDE_DIR="${basedir}/libzip/include" -DCMAKE_INSTALL_PREFIX="${installdir}" "${codedir}" + +# Build and install +cmake --build . --parallel 8 +cmake --build . --target install + +# Return to basedir +cd $basedir +echo "setupDCPLib.sh done!" diff --git a/dependencies/setupLibzip.bat b/dependencies/setupLibzip.bat new file mode 100644 index 0000000000..7a68c12611 --- /dev/null +++ b/dependencies/setupLibzip.bat @@ -0,0 +1,32 @@ +@ECHO OFF +REM Bat script building libzip dependency automatically + +setlocal +set basedir=%~dp0 +set name=libzip +set codedir=%basedir%\%name%-code +set builddir=%basedir%\%name%-build +set installdir=%basedir%\%name% + +set zlibdir=%basedir:\=/%/zlib +echo %zlibdir% + +call setHopsanBuildPaths.bat + +mkdir %builddir% +cd %builddir% +if "%HOPSAN_BUILD_COMPILER%" == "msvc" ( +cmake -Wno-dev -G %HOPSAN_BUILD_CMAKE_GENERATOR% -DZLIB_INCLUDE_DIR="%zlibdir%/include" -DZLIB_LIBRARY="%zlibdir%/lib/zlib.lib" -DCMAKE_INSTALL_PREFIX="%installdir%" %codedir% +) else ( +cmake -Wno-dev -G %HOPSAN_BUILD_CMAKE_GENERATOR% -DZLIB_INCLUDE_DIR="%zlibdir%/include" -DZLIB_LIBRARY="%zlibdir%/bin/libzlib.dll" -DCMAKE_INSTALL_PREFIX="%installdir%" %codedir% +) +cmake --build . --parallel 8 +cmake --build . --target install + +cd %basedir% +echo. +echo setupLibzip.bat done +if "%HOPSAN_BUILD_SCRIPT_NOPAUSE%" == "" ( + pause +) +endlocal diff --git a/dependencies/setupLibzip.sh b/dependencies/setupLibzip.sh index 2e7834c427..c58fce3521 100755 --- a/dependencies/setupLibzip.sh +++ b/dependencies/setupLibzip.sh @@ -20,11 +20,11 @@ mkdir -p $builddir cd $builddir # Generate makefiles -cmake -Wno-dev -DCMAKE_INSTALL_PREFIX=$installdir ${codedir} +cmake -Wno-dev -DCMAKE_INSTALL_PREFIX=${installdir} ${codedir} # Build and install -make -j16 -make install +cmake --build . --parallel 8 +cmake --build . --target install # Return to basedir cd $basedir diff --git a/dependencies/setupXerces.bat b/dependencies/setupXerces.bat new file mode 100644 index 0000000000..7759e62c62 --- /dev/null +++ b/dependencies/setupXerces.bat @@ -0,0 +1,28 @@ +@ECHO OFF +REM Bat script building libzip dependency automatically + +setlocal +set basedir=%~dp0 +set name=xerces +set codedir=%basedir%\%name%-code +set builddir=%basedir%\%name%-build +set installdir=%basedir%\%name% + +set zlibdir=%basedir:\=/%/zlib +echo %zlibdir% + +call setHopsanBuildPaths.bat + +mkdir %builddir% +cd %builddir% +cmake -Wno-dev -G %HOPSAN_BUILD_CMAKE_GENERATOR% -DCMAKE_INSTALL_PREFIX="%installdir%" %codedir% +cmake --build . --parallel 8 +cmake --build . --target install + +cd %basedir% +echo. +echo setupXerces.bat done +if "%HOPSAN_BUILD_SCRIPT_NOPAUSE%" == "" ( + pause +) +endlocal diff --git a/dependencies/setupZlib.bat b/dependencies/setupZlib.bat new file mode 100644 index 0000000000..b932efc89c --- /dev/null +++ b/dependencies/setupZlib.bat @@ -0,0 +1,25 @@ +@ECHO OFF +REM Bat script building libzip dependency automatically + +setlocal +set basedir=%~dp0 +set name=zlib +set codedir=%basedir%\%name%-code +set builddir=%basedir%\%name%-build +set installdir=%basedir%\%name% + +call setHopsanBuildPaths.bat + +mkdir %builddir% +cd %builddir% +cmake -Wno-dev -G %HOPSAN_BUILD_CMAKE_GENERATOR% -DCMAKE_INSTALL_PREFIX="%installdir%" %codedir% +cmake --build . --config Release --parallel 8 +cmake --build . --config Release --target install + +cd %basedir% +echo. +echo setupZlib.bat done +if "%HOPSAN_BUILD_SCRIPT_NOPAUSE%" == "" ( + pause +) +endlocal diff --git a/dependencies/xerces.cmake b/dependencies/xerces.cmake new file mode 100644 index 0000000000..e7ca6f384f --- /dev/null +++ b/dependencies/xerces.cmake @@ -0,0 +1,40 @@ +if (NOT TARGET xercesc) + set(local_xerces_dir ${CMAKE_CURRENT_LIST_DIR}/xerces) + set(CMAKE_FIND_LIBRARY_PREFIXES lib) + find_library(xercesc NAMES xerces-c ${CMAKE_STATIC_LIBRARY_PREFIX}xerces-c_3D${CMAKE_STATIC_LIBRARY_SUFFIX} PATHS ${local_xerces_dir}/lib) + + #set(CMAKE_FIND_DEBUG_MODE TRUE) + #find_package(xercesc CONFIG PATHS ${local_xerces_dir} NO_DEFAULT_PATH REQUIRED) # Search for local version + #set(CMAKE_FIND_DEBUG_MODE FALSE) + + if (xercesc) + message(STATUS "Found local xerces") + #add_library(xercesc INTERFACE) + + add_library(xercesc STATIC IMPORTED) + + if (MINGW) + set_target_properties(xercesc PROPERTIES + IMPORTED_LOCATION ${local_xerces_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}xerces-c${CMAKE_SHARED_LIBRARY_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} + INTERFACE_INCLUDE_DIRECTORIES ${local_xerces_dir}/include) + elseif(MSVC) + set_target_properties(xercesc PROPERTIES + IMPORTED_LOCATION ${local_xerces_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}xerces-c_3D${CMAKE_STATIC_LIBRARY_SUFFIX} + INTERFACE_INCLUDE_DIRECTORIES ${local_xerces_dir}/include) + else() + set_target_properties(xercesc PROPERTIES + IMPORTED_LOCATION ${local_xerces_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}xerces-c${CMAKE_SHARED_LIBRARY_SUFFIX} + INTERFACE_INCLUDE_DIRECTORIES ${local_xerces_dir}/include) + endif() + + else() + message(STATUS "Looking for xerces in system") + find_package(xercesc CONFIG) # Search in system + if (xercesc_FOUND) + message(STATUS " Found xerces") + add_library(xercesc INTERFACE) + else() + message(WARNING "Could not find xerces") + endif() + endif() +endif() diff --git a/dependencies/xerces.pri b/dependencies/xerces.pri new file mode 100644 index 0000000000..fc5e2b6f5e --- /dev/null +++ b/dependencies/xerces.pri @@ -0,0 +1,25 @@ +xerces_dir = $${PWD}/xerces + +exists($${xerces_dir}) { + INCLUDEPATH *= $${xerces_dir}/include + LIBS *= -L$${xerces_dir}/bin -lxerces-c + + macx { + # Not supported + } win32 { + src_file = $$quote($${xerces_dir}/bin/libxerces-c.dll) + dst_dir = $$quote($${PWD}/../bin) + # Replace slashes in paths with backslashes for Windows + src_file ~= s,/,\\,g + dst_dir ~= s,/,\\,g + + message($${src_file}) + message($${dst_dir}) + + QMAKE_POST_LINK += $$QMAKE_COPY $${src_file} $${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 *= $${xerces_dir/bin} + } +} + diff --git a/hopsandcp/CMakeLists.txt b/hopsandcp/CMakeLists.txt new file mode 100644 index 0000000000..81fed7ae70 --- /dev/null +++ b/hopsandcp/CMakeLists.txt @@ -0,0 +1,47 @@ +cmake_minimum_required(VERSION 3.1) +project(hopsandcp) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_DEBUG_POSTFIX _d) +if(WIN32) + set(CMAKE_SHARED_LIBRARY_PREFIX "") +endif() + +set(CMAKE_AUTOMOC ON) + +# include(${CMAKE_CURRENT_LIST_DIR}/../dependencies/xerces.cmake) +# include(${CMAKE_CURRENT_LIST_DIR}/../dependencies/libzip.cmake) +# include(${CMAKE_CURRENT_LIST_DIR}/../dependencies/zlib.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/../dependencies/libzip.cmake) +#include(${CMAKE_CURRENT_LIST_DIR}/../dependencies/zlib.cmake) + +# Find source code +file(GLOB_RECURSE srcfiles src/*.cpp) +file(GLOB_RECURSE headerfiles include/*.h include/*.hpp) + +# Create library target and add source code files +add_library(hopsandcp STATIC ${srcfiles} ${headerfiles}) + +# Set include directories +target_include_directories(hopsandcp PUBLIC + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $) + +if(WIN32) + target_link_libraries(hopsandcp hopsancore libzip -lws2_32) +else() + target_link_libraries(hopsandcp hopsancore libzip) +endif() + +target_compile_definitions(hopsandcp PUBLIC LOGGING=ON) + diff --git a/hopsandcp/dependencies/DCPLib b/hopsandcp/dependencies/DCPLib deleted file mode 160000 index 402264a2f3..0000000000 --- a/hopsandcp/dependencies/DCPLib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 402264a2f349e5eb4c6ce6fbcf0d8566ca27546e diff --git a/hopsandcp/hopsandcp.pro b/hopsandcp/hopsandcp.pro index b04ec7fe14..d2d9aac2b4 100644 --- a/hopsandcp/hopsandcp.pro +++ b/hopsandcp/hopsandcp.pro @@ -28,41 +28,30 @@ LIBS *= -L$${PWD}/../bin -lhopsancore$${DEBUG_EXT} DEFINES *= HOPSANCORE_DLLIMPORT #-------------------------------------------------- -#-------------------------------------------------- -# Add the include and lib path to xerces -INCLUDEPATH *= $${PWD}/../dependencies/xerces/include/ -LIBS *= -L$${PWD}/../dependencies/xerces/lib/ -LIBS *= -lxerces-c -#-------------------------------------------------- - #-------------------------------------------------- # Add the include path to xerces -INCLUDEPATH *= $${PWD}/../dependencies/asio/include/ +INCLUDEPATH *= $${PWD}/../dependencies/asio-code/include/ #-------------------------------------------------- #-------------------------------------------------- # Add the include and lib path to libzip -INCLUDEPATH *= $${PWD}/../dependencies/libzip/include/ -LIBS *= -L$${PWD}/../dependencies/libzip/lib/ -LIBS *= -lzip +include($${PWD}/../dependencies/libzip.pri) #-------------------------------------------------- #-------------------------------------------------- # Add the include and lib path to xerces -INCLUDEPATH *= $${PWD}/../dependencies/xerces/include/ -LIBS *= -L$${PWD}/../dependencies/xerces/lib/ -LIBS *= -lxerces-c +include($${PWD}/../dependencies/xerces.pri) #-------------------------------------------------- #-------------------------------------------------- # Add the include path to DCPLib -INCLUDEPATH *= $${PWD}/dependencies/DCPLib/include/bluetooth -INCLUDEPATH *= $${PWD}/dependencies/DCPLib/include/core -INCLUDEPATH *= $${PWD}/dependencies/DCPLib/include/ethernet -INCLUDEPATH *= $${PWD}/dependencies/DCPLib/include/master -INCLUDEPATH *= $${PWD}/dependencies/DCPLib/include/slave -INCLUDEPATH *= $${PWD}/dependencies/DCPLib/include/xml -INCLUDEPATH *= $${PWD}/dependencies/DCPLib/include/zip +INCLUDEPATH *= $${PWD}/../dependencies/dcplib-code/include/bluetooth +INCLUDEPATH *= $${PWD}/../dependencies/dcplib-code/include/core +INCLUDEPATH *= $${PWD}/../dependencies/dcplib-code/include/ethernet +INCLUDEPATH *= $${PWD}/../dependencies/dcplib-code/include/master +INCLUDEPATH *= $${PWD}/../dependencies/dcplib-code/include/slave +INCLUDEPATH *= $${PWD}/../dependencies/dcplib-code/include/xml +INCLUDEPATH *= $${PWD}/../dependencies/dcplib-code/include/zip #-------------------------------------------------- #-------------------------------------------------------- @@ -92,6 +81,8 @@ SOURCES = \ src/utilities.cpp HEADERS += \ + ../dependencies/dcplib-code/include/master/dcp/logic/DcpManagerMaster.hpp \ + ../dependencies/dcplib-code/include/slave/dcp/logic/DcpManagerSlave.hpp \ include/dcpmaster.h \ include/dcpserver.h \ include/hopsandcp_win32dll.h \ diff --git a/hopsandcp/src/dcpmaster.cpp b/hopsandcp/src/dcpmaster.cpp index 343dc11d89..45d96ddbda 100644 --- a/hopsandcp/src/dcpmaster.cpp +++ b/hopsandcp/src/dcpmaster.cpp @@ -2,7 +2,7 @@ #include "dcp/log/OstreamLog.hpp" #include "dcp/helper/LogHelper.hpp" -#include "dcp/model/pdu/DcpPduFactory.hpp" +//#include "dcp/model/pdu/DcpPduFactory.hpp" #include "dcp/zip/DcpSlaveReader.hpp" #include "dcp/driver/ethernet/udp/UdpDriver.hpp" #include "dcp/logic/DcpManagerMaster.hpp" @@ -10,10 +10,12 @@ #include #include #include -#include +//#include #include #include +#include "ComponentUtilities/num2string.hpp" + DcpMaster::DcpMaster(hopsan::ComponentSystem *pSystem, const std::string host, int port, double comStep, double startTime, double stopTime, bool realTime) : mpSystem(pSystem), mRealTime(realTime), mComStep(comStep), mStartTime(startTime), mStopTime(stopTime) { diff --git a/hopsandcp/src/dcpserver.cpp b/hopsandcp/src/dcpserver.cpp index be502faf4f..2ea0de29fd 100644 --- a/hopsandcp/src/dcpserver.cpp +++ b/hopsandcp/src/dcpserver.cpp @@ -1,4 +1,5 @@ #include "dcpserver.h" +#include "ComponentSystem.h" #include "utilities.h" #include @@ -8,7 +9,7 @@ #include #include -#include "HopsanEssentials.h" +//#include "HopsanEssentials.h" #include "HopsanCoreMacros.h" #include "HopsanCoreVersion.h"