Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to cmake part1 #2251

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ccddeda
Switch to CMake in deb packaging
peterNordin Nov 9, 2021
80030cc
Add missing doxygen/graphviz to deb control files
peterNordin Aug 29, 2023
a99c6da
Reuse existing clone of code to avoid redownload
peterNordin Aug 29, 2023
0754d58
Optionally use cache directory for dependency downloads
peterNordin Aug 29, 2023
338c9a4
Use cache dir for downloads, and keep temporary stage dir
peterNordin Aug 29, 2023
28f1565
Adjust cmake policys for older CMake support
peterNordin Aug 29, 2023
13c2d97
Fix compatibility with older cmake
peterNordin Aug 29, 2023
69a7038
Add missing ARCHIVE destinations for static libs
peterNordin Aug 29, 2023
0040f97
Prefer persistent cache dir in workspace
peterNordin Aug 30, 2023
6304d5f
Fix msgpackc workaround
peterNordin Aug 29, 2023
9580025
Remove old minimum cmake version, let main file decide
peterNordin Oct 16, 2024
1118be5
Remove experimental Warning
peterNordin Nov 5, 2024
a4eefdb
Update fmi4c and use the new cmake configuration
peterNordin Nov 5, 2024
55c9a20
Cleanup Linux build scripts
peterNordin Nov 7, 2024
c4c2bb3
Fix dcplib build on Linux and with MSVC
peterNordin Dec 3, 2024
9e70bc7
Simplify CMake DCP lookup
peterNordin Dec 4, 2024
163abb1
Install dependencies zlib, libzip and xerces
peterNordin Dec 4, 2024
649dcbe
Update gitignore
peterNordin Dec 5, 2024
cee05d4
Ignore build dir in code
peterNordin Dec 9, 2024
cbd3010
Cleanup hopsanremote CMake files
peterNordin Dec 9, 2024
215f021
Build libzip before DCPLib
peterNordin Dec 11, 2024
4bed85a
Switch appveyor MinGW build to CMake
peterNordin Dec 11, 2024
d07a1fe
Use alias target compatible with older cmake
peterNordin Dec 15, 2024
8c33e4e
Fix dcp build with mingw
peterNordin Dec 17, 2024
55f03b5
Fix cmake build and test on appveyor
peterNordin Dec 17, 2024
3d090aa
Update to 2019 appveyor image
peterNordin Dec 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
image:
- Visual Studio 2017
- Visual Studio 2019
environment:
HOPSAN_BUILD_SCRIPT_NOPAUSE: 1
HOPSAN_BUILD_QT_HOME: C:\Qt\5.12.6\mingw73_64
HOPSAN_BUILD_MINGW_HOME: C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64
HOPSAN_BUILD_QT_HOME: C:\Qt\5.15.2\mingw81_64
HOPSAN_BUILD_MINGW_HOME: C:\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64
platform: x64
configuration: Release
install:
Expand Down Expand Up @@ -31,12 +31,15 @@ build_script:
- setupMsgpack.bat
- call setHopsanBuildPaths.bat
- cd ..
- mkdir build
- cd build
- qmake.exe ..\HopsanNG.pro -r -spec win32-g++ CONFIG+=release
- cd ..
- mingw32-make.exe -j6 -C build
- cmake -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install_dir -Bbuild_dir -S.
- cmake --build build_dir --config Release --parallel 6
- cmake --build build_dir --config Release --parallel 6 --target install
- cd install_dir
- dir bin
- cd ..
test_script:
- runUnitTests.bat
- runValidationTests.bat
- cd build_dir
- ctest -C Release --output-on-failure --parallel 4
- cd ..
# - set PATH=%CD%\install\bin;%PATH%
# - runValidationTests.bat TODO Fix this
2 changes: 1 addition & 1 deletion .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ jobs:
./setupTclap.sh
./setupFmi4c.sh
./setupXerces.sh
./setupDCPLib.sh
./setupLibzip.sh
./setupDCPLib.sh

- name: Configure
working-directory: hopsan-build
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.vs/
bin/
HopsanNG_bd/
build/
output64/
output/
output_deb/
Expand Down
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.10)
project(Hopsan)

cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0079 NEW)
cmake_policy(SET CMP0057 NEW)
if (POLICY CMP0079)
cmake_policy(SET CMP0079 NEW)
endif()

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)
Expand Down
2 changes: 1 addition & 1 deletion HopsanCLI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)

project(HopsanCLI)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
1 change: 0 additions & 1 deletion HopsanCore/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.1)
project(HopsanCore)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
2 changes: 1 addition & 1 deletion HopsanGUI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)

project(HopsanGUI)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
2 changes: 1 addition & 1 deletion HopsanGenerator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.0)

project(HopsanGenerator)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
1 change: 0 additions & 1 deletion Ops/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(Ops)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
1 change: 0 additions & 1 deletion SymHop/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.1)
project(SymHop)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
1 change: 0 additions & 1 deletion UnitTests/DefaultLibraryXMLTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(DefaultLibraryXMLTest)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
1 change: 0 additions & 1 deletion UnitTests/GeneratorTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(HopsanCoreTests)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(HopsanCoreTests)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
1 change: 0 additions & 1 deletion UnitTests/HopsanCoreTests/HStringTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(HopsanCoreTests)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
1 change: 0 additions & 1 deletion UnitTests/HopsanCoreTests/HVectorTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(HopsanCoreTests)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
1 change: 0 additions & 1 deletion UnitTests/HopsanCoreTests/LookupTableTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(HopsanCoreTests)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
1 change: 0 additions & 1 deletion UnitTests/HopsanCoreTests/SimulationTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(HopsanCoreTests)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
1 change: 0 additions & 1 deletion UnitTests/HopsanCoreTests/UtilitiesTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(HopsanCoreTests)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
1 change: 0 additions & 1 deletion UnitTests/SymHopTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(HopsanCoreTests)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
1 change: 0 additions & 1 deletion UnitTests/hopsanclitest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(hopsanclitest)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
1 change: 0 additions & 1 deletion componentLibraries/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(ComponentLibraries)

include(${CMAKE_CURRENT_LIST_DIR}/../helpers.cmake)
Expand Down
1 change: 0 additions & 1 deletion componentLibraries/ModelicaExampleLib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(ModelicaExampleLibrary)

install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/ DESTINATION componentLibraries/modelica-example-library
Expand Down
1 change: 0 additions & 1 deletion componentLibraries/autoLibs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(AutoLibs)

install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/ DESTINATION componentLibraries/autoLibs
Expand Down
3 changes: 1 addition & 2 deletions componentLibraries/defaultLibrary/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(DefaultComponentLibrary)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand All @@ -12,7 +11,7 @@ target_include_directories(defaultcomponentlibrary PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)

target_link_libraries(defaultcomponentlibrary hopsancore)
target_link_optional_libraries(defaultcomponentlibrary fmi4c)
target_link_optional_libraries(defaultcomponentlibrary fmi4c::fmi4c)
if(WIN32)
set_target_properties(defaultcomponentlibrary PROPERTIES
PREFIX ""
Expand Down
1 change: 0 additions & 1 deletion componentLibraries/exampleComponentLib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(ExampleComponentLibrary)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
1 change: 0 additions & 1 deletion componentLibraries/extensionLibrary/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cmake_minimum_required(VERSION 3.0)
project(ExampleComponentLibrary)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_DEBUG_POSTFIX _d)
Expand Down
24 changes: 7 additions & 17 deletions dependencies/.gitignore
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
*-code/
*-build/
*-build*/
fmilibrary/
fmilibrary-code/
fmilibrary-build/
fmi4c/
fmi4c-code/
fmi4c-build*/
qwt/
qwt-code/
qwt-build/
zeromq/
zeromq-code/
zeromq-build/
discount/
discount-code/
discount-build/
hdf5/
hdf5-code/
hdf5-build/
katex/
katex-code/
tclap/
tclap-code/
cppzmq-code/
msgpack-c/
msgpack-c-code/
msgpack-c-build/
libzip/
zlib/
xerces/
dcplib/
*.zip
*.tar.gz
*.tar.bz2
Expand Down
70 changes: 70 additions & 0 deletions dependencies/dcplib.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
set(local_xerces_dir ${CMAKE_CURRENT_LIST_DIR}/xerces)
set(local_zlib_dir ${CMAKE_CURRENT_LIST_DIR}/zlib)
set(local_libzip_dir ${CMAKE_CURRENT_LIST_DIR}/libzip)
set(local_asio_dir ${CMAKE_CURRENT_LIST_DIR}/asio-code)
set(local_dcplib_dir ${CMAKE_CURRENT_LIST_DIR}/dcplib)


find_package(Threads)
find_package(ICU MODULE COMPONENTS uc data)
find_package(XercesC CONFIG PATHS ${local_xerces_dir} NO_DEFAULT_PATH)
find_package(libzip CONFIG PATHS ${local_libzip_dir} NO_DEFAULT_PATH)

#add_library(ZIP::ZIP ALIAS libzip::zip)
# add alias compatible with older cmake versions
add_library(ZIP::ZIP INTERFACE IMPORTED)
set_target_properties(ZIP::ZIP PROPERTIES INTERFACE_LINK_LIBRARIES libzip::zip)

# TODO Use proper ASIO lookup and installation
add_library(ASIO::ASIO INTERFACE IMPORTED)
set_target_properties(ASIO::ASIO PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "ASIO_STANDALONE"
INTERFACE_INCLUDE_DIRECTORIES "${local_asio_dir}/include"
)
target_link_libraries(ASIO::ASIO INTERFACE Threads::Threads)

find_package(DCPLib CONFIG PATHS ${local_dcplib_dir} NO_DEFAULT_PATH)


# Add libzip to installation if local variant found
if (EXISTS ${local_zlib_dir})
# When building with mingw, libzip uses the lib prefix on windows
if (MINGW)
file(GLOB lib_files ${local_zlib_dir}/bin/libzlib${CMAKE_SHARED_LIBRARY_SUFFIX})
else()
file(GLOB lib_files ${local_zlib_dir}/bin/zlib${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
install(FILES ${lib_files} DESTINATION bin)
endif()

# Add libzip to installation if local variant found
if (EXISTS ${local_libzip_dir})
# When building with mingw, libzip uses the lib prefix on windows
if (WIN32)
if (MINGW)
file(GLOB lib_files ${local_libzip_dir}/bin/libzip${CMAKE_SHARED_LIBRARY_SUFFIX})
else()
file(GLOB lib_files ${local_libzip_dir}/bin/zip*${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
install(FILES ${lib_files} DESTINATION bin)
else()
file(GLOB lib_files ${local_libzip_dir}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}zip${CMAKE_SHARED_LIBRARY_SUFFIX}*)
install(FILES ${lib_files} DESTINATION lib)
endif()
endif()

# Add xerces to installation if local variant found
if (EXISTS ${local_xerces_dir})
# When building with mingw, xerces uses the lib prefix on windows
if (WIN32)
if (MINGW)
file(GLOB lib_files ${local_xerces_dir}/bin/libxerces-c${CMAKE_SHARED_LIBRARY_SUFFIX})
else()
file(GLOB lib_files ${local_xerces_dir}/bin/xerces-c*${CMAKE_SHARED_LIBRARY_SUFFIX})
endif()
install(FILES ${lib_files} DESTINATION bin)
else()
file(GLOB lib_files ${local_xerces_dir}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}xerces-c*${CMAKE_SHARED_LIBRARY_SUFFIX}*)
install(FILES ${lib_files} DESTINATION lib)
endif()
endif()
4 changes: 2 additions & 2 deletions dependencies/dependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@
</dependency>

<dependency name="fmi4c">
<releasefile sha256="05dd5000e4b8e7892b020279e6d5ecedfb9e3f6e38e01a51956f2e0e84570772">
<url>https://github.com/robbr48/fmi4c/archive/e81d407473122cc7ee10209622e38c5d30e34d40.zip</url>
<releasefile sha256="fb00aebcd6b863977528bf5fccc4bf5cc9e63a0a96b467a9e89711fd4799006d">
<url>https://github.com/robbr48/fmi4c/archive/cde695706fa7441aaacd5c19aeae10f64e778b26.zip</url>
</releasefile>
</dependency>

Expand Down
32 changes: 30 additions & 2 deletions dependencies/download-dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ class DependenciesXML:
def __init__(self, dependencies_xml_file):
tree = ET.parse(dependencies_xml_file)
self.root = tree.getroot()
self.cache_dir = str()

def __match_choice(self, name, version, choices, allow_missing):
found_name = False
Expand All @@ -204,6 +205,19 @@ def __download_and_check_releasefile(self, dep_name, releasefile_element, force)
fname = decide_file_name(dep_name, url)

do_download = True

use_cache = len(self.cache_dir) > 0
cached_fpath = os.path.join(self.cache_dir, fname)
if use_cache and not os.path.isfile(fname) and os.path.isfile(cached_fpath):
print("Found {} in download cache".format(fname))
if verify_filehash(cached_fpath, hash_algo, expected_hashsum):
print("Copying {}".format(cached_fpath))
shutil.copyfile(cached_fpath, fname)
else:
print('Warning: ' + hash_algo + ' missmatch in file ' + cached_fpath)
print('Expected: ' + expected_hashsum)
print('Actual: ' + hashsum_file(cached_fpath, hash_algo))

if os.path.isfile(fname):
print('Info: File already exists '+fname)
if verify_filehash(fname, hash_algo, expected_hashsum):
Expand All @@ -218,6 +232,9 @@ def __download_and_check_releasefile(self, dep_name, releasefile_element, force)
if do_download:
isok = download(url, fname, hash_algo, expected_hashsum)
if isok:
if use_cache:
print("Copying {} to download cache {}".format(fname, cached_fpath))
shutil.copyfile(fname, cached_fpath)
return (fname, True, True)

return ("", False, False)
Expand All @@ -234,6 +251,9 @@ def __get_dependencies_matching_choice(self, chosen_deps, choose_all):
allready_added_names.append(dep_name)
return matching_dependencies

def set_download_cache_dir(self, dir_path):
self.cache_dir = dir_path

def list_dependencies(self):
names = list()
for dep in self.root:
Expand Down Expand Up @@ -333,6 +353,7 @@ def download_and_unpack_chosen_dependencies(self, choices, download_all, include
if __name__ == "__main__":
argparser = argparse.ArgumentParser()
argparser.add_argument('--all', dest='download_all', action='store_true', help='Download all dependencies (excluding toolchain)' )
argparser.add_argument('--cache', dest='cache_dir', type=str, help='Cache directory for downloads')
argparser.add_argument('--include-toolchain', dest='download_toolchain', action='store_true', help='Download toolchain dependencies' )
argparser.add_argument('--list', dest='list', action='store_true', help='List available dependencies' )
argparser.add_argument('--force', dest='force', action='store_true',
Expand All @@ -346,6 +367,13 @@ def download_and_unpack_chosen_dependencies(self, choices, download_all, include
chosen_deps = args.dependency_name[0]

deps_xml = DependenciesXML('dependencies.xml')
if args.cache_dir:
print("Using download cache dir: " + args.cache_dir)
if not os.path.isdir(args.cache_dir):
print('Error: {} does not exist or is not a directory'.format(args.cache_dir))
sys.exit(1)
deps_xml.set_download_cache_dir(args.cache_dir)

if args.output_flatpak:
deps = deps_xml.ouput_dependencies_flatpak()
output = str()
Expand All @@ -360,6 +388,6 @@ def download_and_unpack_chosen_dependencies(self, choices, download_all, include
deps_xml.check_choices(chosen_deps)
all_ok = deps_xml.download_and_unpack_chosen_dependencies(chosen_deps, args.download_all, args.download_toolchain, args.force)
if all_ok:
exit(0)
sys.exit(0)
else:
exit(1)
sys.exit(1)
Loading