libfmt and windows

I wanted arguments and you gave one. So no need to excuse for being blunt :wink: this is how it should work.

As you need it for a feature, fine with me. I (think I) need to assure that the development process is not stuck because of this. If chennes solution works, fine, also if it turned out not to be feasible, if somebody tells me how to add fmt as library to the LibPack.
So as long as developer on Windows can continue their work without the need to adapt their build system much, it should be fine.

Concerning the release cycle, when people would start to send in patches to use the fmt library to make changes of existing code, I would like to postpone this to after the next major release.

OK – I now have PR 8508 playing nice with the CI, which means that as far as I am aware it compiles on Windows (MSVC - I didn’t test MSYS2), Mac OS, Ubuntu 20.04, and Ubuntu 22.04. It should handle lack of internet connectivity as long as your original cMake run after cloning had connectivity. It’s probably a little too verbose right now, but we can dial that back once we know it’s working.

ETA: This is a pure cMake solution, no libraries need to be manually added anywhere. My understanding of how the cMake feature works is that it will try to use find_package(fmt) first, and only download and compile the fmt library if it cannot find it.

Does this require a specific version of CMake (or later)?

Gene

Yes – the reason we haven’t been able to do this sort of thing with more of our 3rd-party dependencies is because it requires at least cMake 3.11, which we’ve only recently switched to requiring.

Ok, that has been around for a long time. I thought I saw something in your PR about requiring 3.24 or later. That could be a problem. (No doubt I misunderstood the reference to 3.24. :blush: )

Gene

I tried compiling the test case. Failed.

Checking for connection to GitHub...
GitHub connection established for FetchContent
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.22621.
CMake Error at C:/Program Files/CMake/share/cmake-3.24/Modules/ExternalProject.cmake:2786 (message):
error: could not find git for clone of fmt-populate
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.24/Modules/ExternalProject.cmake:4167 (_ep_add_download_command)
CMakeLists.txt:23 (ExternalProject_Add)


-- Configuring incomplete, errors occurred!
See also "D:/Applications/FreeCAD-Build/2023-02-16-Build-0.21.31925/Binary/_deps/fmt-subbuild/CMakeFiles/CMakeOutput.log".
CMake Error at C:/Program Files/CMake/share/cmake-3.24/Modules/FetchContent.cmake:1589 (message):
CMake step for fmt failed: 1
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.24/Modules/FetchContent.cmake:1741:EVAL:2 (__FetchContent_directPopulate)
C:/Program Files/CMake/share/cmake-3.24/Modules/FetchContent.cmake:1741 (cmake_language)
C:/Program Files/CMake/share/cmake-3.24/Modules/FetchContent.cmake:1955 (FetchContent_Populate)
cMake/FreeCAD_Helpers/SetupLibFmt.cmake:29 (FetchContent_MakeAvailable)
CMakeLists.txt:45 (SetupLibFmt)
Configuring incomplete, errors occurred!
See also "D:/Applications/FreeCAD-Build/2023-02-16-Build-0.21.31925/Binary/CMakeFiles/CMakeOutput.log".

(It is possible I made a complete mess.)

Gene

They’ve refined the feature in 3.24 to add additional options controlling the find_package() calls – I mentioned it uptopic in reference to things that package maintainers might be interested in. I don’t think those options are of much use to the general developer.

Ah, the plot thickens. It appears cMake doesn’t have any sort of fallback if there is no git executable available. So if we go this route, then people who want to compile, but don’t want to install git, will indeed have to resort to using vcpkg to install libfmt. (I presume you don’t have git installed? Or do you have some other idea of why it wouldn’t be able to find git?)

OK, I just pushed a new commit to that PR that switches from using git to using a direct zip download. GeneFC if you have time, could you try that one and see if it works?

We could also actually detect the presence of git, and switch between the two methods: the downside there is that if a person runs cMake without git, and then again with git, they will get an error because cMake will try to use git fetch on the existing (non-git) directory.

Correct.

I installed git, and the process now works.

Gene

Correct.

I installed git, and the CMake process now works.

The full compile sorta worked, but FreeCAD was missing some GUI files. (Probably to be expected with this experiment.)

Gene

Huh. I have no idea there, this shouldn’t touch the GUI. I’m a little out of date with master, I can rebase and push a new copy. Maybe that will fix it.

My turn to be blunt. The above statement is rediculous and likely self-serving. As abdullah points out, feature freeze is still months away.

Every code improvement is worthwhile, and often leads to futher improvements. fmt makes many worthwhile improvements possible.

I trust the powers that be will discuss this and ensure artificial hand-brakes are not arbitarily placed on normal development.

Might I ask a silly question: is there a way to use QString::arg() instead of libfmt?

Might I ask a silly question: is there a way to use QString::arg() instead of libfmt?

Using QString::arg() is an option and we already do that a lot but it’s not always practical to build a QString first when a std::string is needed. Then libfmt is more than fast & easily creating strings, one of its key features is to replace the latent unsafe variadic C functions like sprintf, printf, … with a type safe equivalent function.

OK – I now have PR 8508 playing nice with the CI, which means that as far as I am aware it compiles on Windows (MSVC - I didn’t test MSYS2),

I have tested it with MSVC and MSYS2 and it works without any problems.

Thank you very much Chris. I really appreciate it.

I wanted to note one thing, which may become relevant:

  • You solution sets POSITION_INDEPENDENT_CODE (see cMake/FreeCAD_Helpers/SetupLibFmt.cmake)

If FreeCAD Library as LGPL is used as a shared library, then this is necessary.

However, the version that comes with the linux package does not have the POSITION_INDEPENDENT_CODE ON. The author claims it is slightly faster without, as there is one less indirection in the calls.

https://fmt.dev/latest/usage.html

The reason why I say this is that, if FreeCAD is built as a shared library for other code, the outcome will be different when using the local package from ubuntu and when using the cMake solution (and only the cMake solution will work).

It is just for us to be aware of it.

Thanks again.

I had to turn that on to get FreeCAD to link on the CI systems – if there is some other option we can use instead, or if we want to make that a user-configurable parameter, that would work.

I compiled the exact same master with all other conditions the same (except the five test files) and everything worked perfectly.

Something is killing the generation of GUI files.

Gene

Ok, I guess it makes the most sense to start at the beginning then: can you post the output from cMake?