Software Development with C++: CMake Libraries

Поділитися
Вставка
  • Опубліковано 18 жов 2024
  • In this video we look at the basics of building and using libraries with CMake!
    CMake Libraries: cmake.org/cmak...
    For code samples: github.com/coff...
    For live content: / coffeebeforearch

КОМЕНТАРІ • 4

  • @MrAlFuture
    @MrAlFuture 7 місяців тому +1

    Wow this is such an excellent series. Thank you!

  • @sebastianwilke626
    @sebastianwilke626 Рік тому

    Thanks for the video! @6:53: "So here we want to find this _?_ package Threads" - this what package? I'm having trouble understanding the find_package and target_link_libraries commands of the 2nd and 3rd example. From the docs on the target_link_libraries command: "Items containing ::, such as Foo::Bar, are assumed to be IMPORTED or ALIAS library target names [...]". I'm assuming they (Threads and benchmark) are imported here (since we're not aliasing anything). We're not choosing the package name of the find_package command ourselves, right? What does it mean for Threads::Threads to be populated @7:03? Is the former 'Threads' in Threads::Threads of the target_link_libraries command the same as in the find_package command and if so what's the latter 'Threads'?

    • @CoffeeBeforeArch
      @CoffeeBeforeArch  Рік тому +2

      As stated in the documentation, "Threads" is the thread implementation of the system you are building on (cmake.org/cmake/help/latest/module/FindThreads.html ).
      From the documentation "find_package" finds a package of a specified name, and loads package-specific details if it's found (cmake.org/cmake/help/latest/command/find_package.html ). In the case of "Threads", it defines the target "Threads::Threads", which is the thread library for your machine.
      No, we're not choosing our own name to pass to the "find_package" command (unless you wrote a package that you are now trying to find). CMake searches through files like "FindThreads.cmake" (as shown in the video), to match names to real packages. Google benchmark (used in the video), provides the name ("benchmark") to use in the "find_target" command in its documentation, and says that you should use "benchmark::benchmark" to link against it.
      From the documentation, "target_link_libraries" allows you to specify things you want to link against (cmake.org/cmake/help/latest/command/target_link_libraries.html ). So "find_target" is used to import targets, and "target_link_libraries" can be used to say you want to link against a target you just imported.

    • @sebastianwilke626
      @sebastianwilke626 Рік тому

      @@CoffeeBeforeArch Gotcha! I just didn't know where these names were coming from but this cleared things up, thank you!