ihedvall / mdflib

Implementation of the ASAM MDF data file.
https://ihedvall.github.io/mdflib/
MIT License
69 stars 29 forks source link

export functions to build shard library and use vcpkg to manage dependennces #31

Closed Simplxss closed 1 year ago

Simplxss commented 1 year ago

Currently in progress, don't maege it! Suggestions welcome.

29 #30

Simplxss commented 1 year ago

CLR will enable only when complier is MSVC. There is one property to enable it. set_target_properties(mdflibrary PROPERTIES COMMON_LANGUAGE_RUNTIME "") When built by gcc or other compilers, only pure C functions will be exported. All exported functions are in MdfExport.h/cpp.

Simplxss commented 1 year ago

Moreover, I have tested building in windows and ubuntu(wsl), it wsorks well.(except install) I don't know how to change the path, the true path is include/mdflibrary/MdfExport.h. Why cmake append mdflibrary/ in front of it?

CMake Error at mdflibrary/cmake_install.cmake:65 (file):
  file INSTALL cannot find
  "/home/runner/work/mdflib/mdflib/mdflibrary/include/mdflibrary/MdfExport.h":
  No such file or directory.
Simplxss commented 1 year ago

Building in Linux and Windows is fixed, macos need replace the functions in mdflib\src\platform.h/cpp to fix. Do you have time to fix it?

ihedvall commented 1 year ago

The XCode C compiler (XSI vs GNU) need some ifdefs. I don't have a working MacOS environment yet. Will take some days.

ihedvall commented 1 year ago

It's not possible to build the mdfview(er) or mdf_test executable. Using CLion editor.

ihedvall commented 1 year ago

FYI Some of the CMAKE_TOOLCHAIN_FILE paths are fixed, not using the VCPKG_ROOT environment varaible. I patched them temporary.

Simplxss commented 1 year ago

I have added CMakeUserPresets.json to .gitignore, but it didn't take effect... You should config it according to your own environment.

ihedvall commented 1 year ago

The gitignore trouble is that the *user.json already is in the repository so you need to manually delete it in the repository.

Simplxss commented 1 year ago

Can you provide your cmake version, visual studio verison. And did you use ninja as generator? In addition, cmake build command and full log.

ihedvall commented 1 year ago

Tried with Rider (C#) editor. It freaks out as it uses the vcproj/sln not cmake solution. Moving/renaming directories causing problems. Gussing that VS studio have the same problem with the solution file.

Another new feature is that the mdf_test do build with Ninja but when running no test are found. Guessing it's just some cmake "enable test" magic missing.

Simplxss commented 1 year ago

Can you try to build mdflibrary with generator "Visual Studio 17 2022", the config defined in CMakeUserPresets.json.(remember to change the vcpkg directory)

ihedvall commented 1 year ago

All C++ projects uses CMake solution and CLion as editor in Windows/Linux/MacOs. Well the last one is in progress. CMake 3.26.4 VS2022 Community 17.0 (window). GUI through WxWidgets.

All C++/CLI and C# applications uses Visual Studio (Windows Only) or JetBrains Rider (All OS) and SLN solution files (not cmake). VS2022 as above. GUI through Avalonia and .NET Core. The C++/CLI interfaces are not for new designs as it doesn't work well with .NET core and Linux. Instead is the gRPC used.

Simplxss commented 1 year ago

Can you try to build with config msvc-multi-vcpkg? I have tested in CLion and it works well

ihedvall commented 1 year ago

I have tested with just adding the CMAKE_TOOLCHAIN_FILE and with several modifications, almost everything works but the following doesn't work or is a no go.

  1. The project now require VCPKG to build.
  2. Many source files have moved to other directories of no reason.
  3. The C++/CLI mdflibrary doesn't load in debug (but in release?). Excluding the .NET from the CMake will solve this problem.
  4. Many directories has changed name without any reason.
  5. The executables are dependent on Util Lib but it seems that the files has been copied instead.
  6. The JetBrain Rider cannot load the .NET mdflibrary. This mainly due to changed libraries.

I fixed some minor problem with unit test (found no tests problem)

ihedvall commented 1 year ago

I have tried but the .NET stuff are not compiling. Can we just drop the .NET and C--/CLI out of the CMake project ?

Simplxss commented 1 year ago
  1. I will re-add the sln solution for mdflib and mdflibrary as an optional, and add flag to control the cmake project. Besides, It is okey to build but there are some bugs of Visual Studio that also exist in the environment of github action making it fall to build.
  2. Some source files are moved to other directory to make it clear and easy to identify the funtion of it(for example ./src -> ./mdflib/src, static library)
  3. Vcpkg is more easy to building dependences. You just need to add "CMAKE_TOOLCHAIN_FILE": "[vcpkg root]/scripts/buildsystems/vcpkg.cmake" to cmake command and all things will be done. If you think its better to manually download and build all of dependence, I will add it as an optional.
  4. I use VS/VSCode to coding c++, and not very familiar with CLion, if you can't use cmake to build mdflibrary, you can try to turn MDF_BUILD_SHARED_LIB OFF to avoid loading it.
  5. Ninja is NOT SUPPORT CLR, please nor use ninja as generate when building mdflibrary.
Simplxss commented 1 year ago

VCPKG should be an option to install packages now. In addition, build on windows will be disabled because MSVC 19.35.32217.1 does not support condition_variable in clr

Simplxss commented 1 year ago

Another question. The current filepath uses ANSI coding. It will cause error when containing not ASCII words. Is it okey to change it to utf8 coding?

ihedvall commented 1 year ago

It's OK to change it to UTF8 coding. Mdflib should not be compiled with /clr option?

Simplxss commented 1 year ago

Mdflib won't be compiled with /clr option, but Mdflibrary will. Maybe I can disable building shared library in workflow? I will try it.

Simplxss commented 1 year ago

Notice that presets that don't use vcpkg should be added.