From 61b61fd8e3218ad43f2a37cb1bfb54fc45853591 Mon Sep 17 00:00:00 2001 From: Robert Braun Date: Tue, 22 Oct 2024 08:39:47 +0200 Subject: [PATCH] Fix CMake build --- .appveyor.yml | 1 - .github/workflows/ci-build.yaml | 1 - CMakeLists.txt | 2 ++ HopsanGUI/CMakeLists.txt | 4 +++- dependencies/dependencies.xml | 6 ------ dependencies/libzip.cmake | 20 ++++++++++++++++++++ dependencies/setupAll.bat | 3 +++ dependencies/setupAll.sh | 1 - dependencies/setupAsio.bat | 27 --------------------------- dependencies/setupAsio.sh | 27 --------------------------- dependencies/setupZlib.bat | 25 ------------------------- dependencies/xerces.cmake | 30 ++++++++++++++++++++++++++++++ hopsandcp/CMakeLists.txt | 10 ++++++++++ 13 files changed, 68 insertions(+), 89 deletions(-) create mode 100644 dependencies/libzip.cmake delete mode 100644 dependencies/setupAsio.bat delete mode 100755 dependencies/setupAsio.sh delete mode 100644 dependencies/setupZlib.bat create mode 100644 dependencies/xerces.cmake diff --git a/.appveyor.yml b/.appveyor.yml index d81d7a5faa..8771120843 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -20,7 +20,6 @@ build_script: - setupFMILibrary.bat - setupFmi4c.bat - setupXerces.bat - - setupZlib.bat - setupLibzip.bat - setupDCPLib.bat # - setupHDF5.bat (takes to long to build) diff --git a/.github/workflows/ci-build.yaml b/.github/workflows/ci-build.yaml index 48d0c36b84..856da31fe6 100644 --- a/.github/workflows/ci-build.yaml +++ b/.github/workflows/ci-build.yaml @@ -45,7 +45,6 @@ jobs: call setupQwt.bat call setupFmi4c.bat call setupXerces.bat - call setupZlib.bat call setupLibzip.bat call setupDCPLib.bat diff --git a/CMakeLists.txt b/CMakeLists.txt index e13981cc18..8f8ad9c7f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,8 @@ 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") +set(CMAKE_CXX_FLAGS -Wa,-mbig-obj) + enable_testing() add_subdirectory(doc) diff --git a/HopsanGUI/CMakeLists.txt b/HopsanGUI/CMakeLists.txt index 100a1462d1..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) @@ -33,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 hopsandcp libzip) + 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/dependencies/dependencies.xml b/dependencies/dependencies.xml index 95bc239bd8..e10b8dfc80 100644 --- a/dependencies/dependencies.xml +++ b/dependencies/dependencies.xml @@ -99,12 +99,6 @@ - - - https://github.com/madler/zlib/releases/download/v1.3.1/zlib131.zip - - - https://github.com/nih-at/libzip/archive/v1.7.3.zip diff --git a/dependencies/libzip.cmake b/dependencies/libzip.cmake new file mode 100644 index 0000000000..ae199ad43f --- /dev/null +++ b/dependencies/libzip.cmake @@ -0,0 +1,20 @@ +set(local_libzip_dir ${CMAKE_CURRENT_LIST_DIR}/libzip) +find_library(libzip NAMES libzip PATHS ${local_libzip_dir}/lib) + +if (libzip) + message(STATUS "Found local libzip") + add_library(libzip STATIC IMPORTED) + set_target_properties(libzip PROPERTIES + IMPORTED_LOCATION ${local_libzip_dir}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}libzip${CMAKE_SHARED_LIBRARY_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} + INTERFACE_INCLUDE_DIRECTORIES ${local_libzip_dir}/include) + +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 INTERFACE) + else() + message(WARNING "Could not find libzip") + endif() +endif() diff --git a/dependencies/setupAll.bat b/dependencies/setupAll.bat index baeaadfbd7..6013a755a6 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.sh +start /wait cmd /c setupLibzip.sh + diff --git a/dependencies/setupAll.sh b/dependencies/setupAll.sh index 7336fc38e4..c99f74d3ba 100755 --- a/dependencies/setupAll.sh +++ b/dependencies/setupAll.sh @@ -8,6 +8,5 @@ ./setupKatex.sh ./setupTclap.sh ./setupHDF5.sh -./setupAsio.sh ./setupXerces.sh ./setupLibzip.sh diff --git a/dependencies/setupAsio.bat b/dependencies/setupAsio.bat deleted file mode 100644 index b49abad7e1..0000000000 --- a/dependencies/setupAsio.bat +++ /dev/null @@ -1,27 +0,0 @@ -@ECHO OFF -REM Bat script building libzip dependency automatically - -setlocal -set basedir=%~dp0 -set name=asio -set codedir=%basedir%\%name%-code -set builddir=%basedir%\%name%-build -set installdir=%basedir%\%name% - -pause - -call setHopsanBuildPaths.bat - -cd %codedir% -configure --prefix=$installdir --without-boost -cd src -mingw32-make -f Makefile.mgw. - -cd %basedir% -echo. -echo setupAsio.bat done -if "%HOPSAN_BUILD_SCRIPT_NOPAUSE%" == "" ( - pause -) -endlocal - 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/setupZlib.bat b/dependencies/setupZlib.bat deleted file mode 100644 index b932efc89c..0000000000 --- a/dependencies/setupZlib.bat +++ /dev/null @@ -1,25 +0,0 @@ -@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..6146ecc424 --- /dev/null +++ b/dependencies/xerces.cmake @@ -0,0 +1,30 @@ +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 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) + + 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) + + 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/hopsandcp/CMakeLists.txt b/hopsandcp/CMakeLists.txt index 18e98971da..0be2c60062 100644 --- a/hopsandcp/CMakeLists.txt +++ b/hopsandcp/CMakeLists.txt @@ -8,6 +8,12 @@ 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) @@ -31,4 +37,8 @@ target_include_directories(hopsandcp PUBLIC $ $) +target_link_libraries(hopsandcp hopsancore ${CMAKE_CURRENT_LIST_DIR}/../dependencies/libzip/lib/libzip.dll.a -lws2_32) +#target_link_libraries(hopsandcp hopsancore libzip -lws2_32) + target_compile_definitions(hopsandcp PUBLIC LOGGING=ON) +