Giter Club home page Giter Club logo

Comments (8)

HexDecimal avatar HexDecimal commented on June 14, 2024

Libtcod should already support being fetched. The CMake scripts themselves are agnostic, with libtcod searching for packages with find_package and will pick packages gotten with FetchContent, as far as I know.

I don't have enough experience with FetchContent to make an example or template.

I'd be interested in libtcod using FetchContent for its own dependencies when it itself is downloaded with FetchContent, but I'm not confident that those dependencies fully support CMake.

from libtcod.

Journeyman1337 avatar Journeyman1337 commented on June 14, 2024

As of CMake version 24, you can add FIND_PACKAGE_ARGS as an argument to FetchContent_Declare and it will first attempt to use find_package. In this case, it only fetches the content if no package was found.

from libtcod.

HexDecimal avatar HexDecimal commented on June 14, 2024

I found OVERRIDE_FIND_PACKAGE which seems to make them work seamlessly with find_package.

Trying to figure out examples for libtcod's dependencies:

FetchContent_Declare(
    SDL2
    GIT_REPOSITORY https://github.com/libsdl-org/SDL
    GIT_TAG release-2.26.1
    OVERRIDE_FIND_PACKAGE
)
FetchContent_Declare(
    UTF8PROC
    GIT_REPOSITORY https://github.com/JuliaStrings/utf8proc
    GIT_TAG v2.8.0
    OVERRIDE_FIND_PACKAGE
)
FetchContent_Declare(
    ZLIB
    GIT_REPOSITORY https://github.com/madler/zlib
    GIT_TAG v1.2.13
    OVERRIDE_FIND_PACKAGE
)

LodePNG is missing a CMakeLists. STB is also not a CMake project.

from libtcod.

Journeyman1337 avatar Journeyman1337 commented on June 14, 2024

I got stb working with FetchContent here:
https://github.com/Journeyman-dev/roguelike.h/blob/0e1994082e8f6f06486a9bb404e1a47314e97eb9/example/CMakeLists.txt#L32

from libtcod.

HexDecimal avatar HexDecimal commented on June 14, 2024

Using stb_SOURCE_DIR makes sense in hindsight. With this it should be possible to build the library for LodePNG too, but I want these to export an alias matching the ones provided by Vcpkg and make them into a portable script which can be copied across projects with similar requirements.

So for a simple example. Could something like this could be made into FindStb.cmake:

FetchContent_Declare(
        stb
        GIT_REPOSITORY https://github.com/nothings/stb
)
FetchContent_MakeAvailable(stb)
set(Stb_INCLUDE_DIR "${stb_SOURCE_DIR}" CACHE PATH "Stb header directory.")

Which would seamlessly integrate with libtcod's current use of the same library from Vcpkg:

find_package(Stb REQUIRED)
target_include_directories(${PROJECT_NAME} PRIVATE ${Stb_INCLUDE_DIR})

Then something like this for FindLodePNG-c.cmake:

FetchContent_Declare(
        LodePNG
        ...
)
FetchContent_MakeAvailable(LodePNG)
... # copy lodepng.cpp, lodepng_util.cpp to *.c
add_library(lodepng-c lodepng.c lodepng_util.c)
target_include_directories(lodepng-c LodePNG_SOURCE_DIR)

I barely have any idea what I'm talking about. I'll have to re-read the CMake docs on these topics.

from libtcod.

Journeyman1337 avatar Journeyman1337 commented on June 14, 2024

Maybe you could use check_variable_exists to see if Stb_INCLUDE_DIR was defined when you called FetchContent_Declare. If not, set the variable manually.

from libtcod.

HexDecimal avatar HexDecimal commented on June 14, 2024

Current attempts are generating errors such as the following:

-- Configuring done
CMake Error: install(EXPORT "libtcodTargets" ...) includes target "libtcod" which requires target "SDL2-static" that is not in any export set.
CMake Error: install(EXPORT "libtcodTargets" ...) includes target "libtcod" which requires target "utf8proc" that is not in any export set.
-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

See https://github.com/libtcod/libtcod/actions/runs/3780000589/jobs/6425717835

from libtcod.

HexDecimal avatar HexDecimal commented on June 14, 2024

All of my previous examples can be ignored. harryisgamer pointed out how to solve the install issue and then posted multiple working examples of setting up a libtcod project using FetchContent in issue #153:

FetchContent libtcod, simple/minimal version

FetchContent libtcod, with un-vendored dependencies

What's next would be to write official instructions on how to setup a project using these.

from libtcod.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.