cmake, fetchcontent from github

Having trouble installing or compiling FreeCAD? Get help here.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
user1234
Veteran
Posts: 3319
Joined: Mon Jul 11, 2016 5:08 pm

cmake, fetchcontent from github

Post by user1234 »

Hello!

Today i get the sources to my machines, which have no internet and want to build it. As i run cmake, i get an error, because it want to fetch something from github. Besides, there is no switch to turn that of and now not able to compile it, because it have no internet, if i run cmake, i do not expect, that it want connect to the internet and fetch something from a random place. It is in my opinion a major security issue, since i do not await a connection to the internet, when i do not explicit go for it.


cmake output

Code: Select all

Compiler: GNU, version: 10.2.1
prefix: /usr/local
bindir: bin
datadir: share
docdir: share/doc/FreeCAD
includedir: include
libdir: lib
cmake: 3.18.4
Compiling with Qt 5
Checking for connection to GitHub...
GitHub connection established for FetchContent
[ 11%] Performing download step (download, verify and extract) for 'fmt-populate'
-- verifying file...
       file='/home/user/Programs/FreeCAD/build/_deps/fmt-subbuild/fmt-populate-prefix/src/9.1.0.zip'
-- MD5 hash of
    /home/user/Programs/FreeCAD/build/_deps/fmt-subbuild/fmt-populate-prefix/src/9.1.0.zip
  does not match expected value
    expected: 'e6754011ff56bfc37631fcc90961e377'
      actual: 'd41d8cd98f00b204e9800998ecf8427e'
-- File already exists but hash mismatch. Removing...
-- Downloading...
   dst='/home/user/Programs/FreeCAD/build/_deps/fmt-subbuild/fmt-populate-prefix/src/9.1.0.zip'
   timeout='none'
-- Using src='https://github.com/fmtlib/fmt/archive/refs/tags/9.1.0.zip'
-- Retrying...
-- Using src='https://github.com/fmtlib/fmt/archive/refs/tags/9.1.0.zip'
-- Retry after 5 seconds (attempt #2) ...
-- Using src='https://github.com/fmtlib/fmt/archive/refs/tags/9.1.0.zip'
-- Retry after 5 seconds (attempt #3) ...
-- Using src='https://github.com/fmtlib/fmt/archive/refs/tags/9.1.0.zip'
-- Retry after 15 seconds (attempt #4) ...
-- Using src='https://github.com/fmtlib/fmt/archive/refs/tags/9.1.0.zip'
-- Retry after 60 seconds (attempt #5) ...
-- Using src='https://github.com/fmtlib/fmt/archive/refs/tags/9.1.0.zip'
CMake Error at fmt-subbuild/fmt-populate-prefix/src/fmt-populate-stamp/download-fmt-populate.cmake:159 (message):
  Each download failed!

    error: downloading 'https://github.com/fmtlib/fmt/archive/refs/tags/9.1.0.zip' failed
         status_code: 6
         status_string: "Couldn't resolve host name"
         log:
         --- LOG BEGIN ---
         Could not resolve host: github.com

  Closing connection 0

  

         --- LOG END ---
         error: downloading 'https://github.com/fmtlib/fmt/archive/refs/tags/9.1.0.zip' failed
         status_code: 6
         status_string: "Couldn't resolve host name"
         log:
         --- LOG BEGIN ---
         Could not resolve host: github.com

  Closing connection 0

  

         --- LOG END ---
         error: downloading 'https://github.com/fmtlib/fmt/archive/refs/tags/9.1.0.zip' failed
         status_code: 6
         status_string: "Couldn't resolve host name"
         log:
         --- LOG BEGIN ---
         Could not resolve host: github.com

  Closing connection 0

  

         --- LOG END ---
         error: downloading 'https://github.com/fmtlib/fmt/archive/refs/tags/9.1.0.zip' failed
         status_code: 6
         status_string: "Couldn't resolve host name"
         log:
         --- LOG BEGIN ---
         Could not resolve host: github.com

  Closing connection 0

  

         --- LOG END ---
         error: downloading 'https://github.com/fmtlib/fmt/archive/refs/tags/9.1.0.zip' failed
         status_code: 6
         status_string: "Couldn't resolve host name"
         log:
         --- LOG BEGIN ---
         Could not resolve host: github.com

  Closing connection 0

  

         --- LOG END ---
         error: downloading 'https://github.com/fmtlib/fmt/archive/refs/tags/9.1.0.zip' failed
         status_code: 6
         status_string: "Couldn't resolve host name"
         log:
         --- LOG BEGIN ---
         Could not resolve host: github.com

  Closing connection 0

  

         --- LOG END ---
         
    


gmake[2]: *** [CMakeFiles/fmt-populate.dir/build.make:111: fmt-populate-prefix/src/fmt-populate-stamp/fmt-populate-download] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:95: CMakeFiles/fmt-populate.dir/all] Error 2
gmake: *** [Makefile:103: all] Error 2

CMake Error at /usr/share/cmake-3.18/Modules/FetchContent.cmake:987 (message):
  Build step for fmt failed: 2
Call Stack (most recent call first):
  /usr/share/cmake-3.18/Modules/FetchContent.cmake:1082:EVAL:2 (__FetchContent_directPopulate)
  /usr/share/cmake-3.18/Modules/FetchContent.cmake:1082 (cmake_language)
  /usr/share/cmake-3.18/Modules/FetchContent.cmake:1125 (FetchContent_Populate)
  cMake/FreeCAD_Helpers/SetupLibFmt.cmake:38 (FetchContent_MakeAvailable)
  CMakeLists.txt:45 (SetupLibFmt)


Configuring incomplete, errors occurred!
See also "/home/user/Programs/FreeCAD/build/CMakeFiles/CMakeOutput.log".

Thoughts?

Greetings
user1234
user1234
Veteran
Posts: 3319
Joined: Mon Jul 11, 2016 5:08 pm

Re: cmake, fetchcontent from github

Post by user1234 »

Now i have found the switch

Code: Select all

-DFETCHCONTENT_FULL_DISCONNECTED
Even when i switch it on (just saying, that is somehow double inverted, it should be named FETCHCONTENT = TRUE/FALSE, that is much clearer), i get on cmake the message

Code: Select all

Checking for connection to GitHub...
GitHub connection established for FetchContent
CMake Error at cMake/FreeCAD_Helpers/SetupLibFmt.cmake:39 (set_target_properties):
  set_target_properties Can not find target to add properties to: fmt
Call Stack (most recent call first):
  CMakeLists.txt:45 (SetupLibFmt)


fmt was downloaded using FetchContent into /home/user/Programs/FreeCAD/build/_deps/fmt-src
, which is misleading, because i get still messages, while i switch the connection off and still writing

Checking for connection to GitHub...,
GitHub connection established for FetchContent and
fmt was downloaded using FetchContent into /home/user/Programs/FreeCAD/build/_deps/fmt-src

. Also it refuses to compile.

This whole fetch thing should be opt in, not opt out.


Greetings
user1234
User avatar
waebbl
Posts: 200
Joined: Thu Aug 16, 2018 3:12 pm

Re: cmake, fetchcontent from github

Post by waebbl »

If you install the fmt library (using your package manager) before configuring FC, it should work. Cmake first uses a find_package(fmt) before using the fetch_content approach.
user1234
Veteran
Posts: 3319
Joined: Mon Jul 11, 2016 5:08 pm

Re: cmake, fetchcontent from github

Post by user1234 »

waebbl wrote: Sat Apr 01, 2023 10:38 am If you install the fmt library (using your package manager) before configuring FC, it should work.
Does not make this implementation better. For what is this new dependency?


Greetings
user1234
User avatar
waebbl
Posts: 200
Joined: Thu Aug 16, 2018 3:12 pm

Re: cmake, fetchcontent from github

Post by waebbl »

user1234 wrote: Sat Apr 01, 2023 3:11 pm Does not make this implementation better. For what is this new dependency?
I'm not a fan of the fetch_content method either. It's not very distribution friendly and won't run without issues inside a sandbox.
Haven't checked where the library is used within FC. But it's increasingly used with C++ projects and IIRC is planned to be included with one of the next C++ standard library verions.
User avatar
chennes
Veteran
Posts: 3876
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: cmake, fetchcontent from github

Post by chennes »

FetchContent of fmt is provided predominantly for Windows users, since it is not yet part of a LibPack. Linux and Mac users will most likely install fmt using their system's package manager, the same as all of our other dependencies. This library provides the C++20 fmt capabilities to non-C++20 compilers. We expect to phase out the dependency as support for C++20 becomes ubiquitous.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: cmake, fetchcontent from github

Post by wmayer »

user1234 wrote:Even when i switch it on (just saying, that is somehow double inverted, it should be named FETCHCONTENT = TRUE/FALSE, that is much clearer), i get on cmake the message
The variable name FETCHCONTENT_FULL_DISCONNECTED comes from CMake, not FreeCAD so nothing we can do on this.
This whole fetch thing should be opt in, not opt out.
We should explicitly try with find_package beforehand.
waebbl wrote:If you install the fmt library (using your package manager) before configuring FC, it should work. Cmake first uses a find_package(fmt) before using the fetch_content approach.
IIRC then fetch_content checks for a package since a very recent CMake version (3.23 or so). With older versions it always tries to fetch the sources from remote.
Does not make this implementation better. For what is this new dependency?
Currently it's used for our Console class. The advantage compared to C format specifiers is that the fmt library does some proper type checks and raises an exception instead of randomly crashing if there is a mismatch.

Further use cases are already planned...
I'm not a fan of the fetch_content method either. It's not very distribution friendly and won't run without issues inside a sandbox.
We should change the check for the fmt in FreeCAD. Instead of relying on how fetch_content works we should explicitly check for the fmt package with find_package and only if this fails we try fetch_content as fallback.
User avatar
waebbl
Posts: 200
Joined: Thu Aug 16, 2018 3:12 pm

Re: cmake, fetchcontent from github

Post by waebbl »

wmayer wrote: Sun Apr 02, 2023 9:11 am We should change the check for the fmt in FreeCAD. Instead of relying on how fetch_content works we should explicitly check for the fmt package with find_package and only if this fails we try fetch_content as fallback.
This is already done in the current SetupLibFmt.cmake file. So if the package is installed prior to configuring FreeCAD, all should work as expected.
wmayer
Founder
Posts: 20241
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: cmake, fetchcontent from github

Post by wmayer »

waebbl wrote: Sun Apr 02, 2023 9:38 am This is already done in the current SetupLibFmt.cmake file. So if the package is installed prior to configuring FreeCAD, all should work as expected.
Ah, great! I haven't checked this for a while. So, then if the fmt package is installed things should work without internet connection, no?

On my system I get this message in the CMake output:
find_package() was used to locate fmt version 8.1.1
User avatar
waebbl
Posts: 200
Joined: Thu Aug 16, 2018 3:12 pm

Re: cmake, fetchcontent from github

Post by waebbl »

wmayer wrote: Sun Apr 02, 2023 2:34 pm So, then if the fmt package is installed things should work without internet connection, no?
Yes it should. And it did work for me in the sandboxed environment a couple of days ago.
Post Reply