Skip to content

Adding Dependencies

Ken Johnson edited this page Oct 25, 2022 · 1 revision

Currently, NovelRT uses the CMake-based FetchContent to retrieve dependencies and build them from source. This allows us to let CMake either handle making the dependency project available to us, or to allow us to fine-tune some of the options provided by the module.

In order to add a new dependency to NovelRT's Core, you will need to take a few steps as follows:
(Please note, this covers basic usage of the FetchContent module and is using Box2D as an example - feel free to take a look at CMake's documentation or our current dependencies for more advanced usage.)

  1. Inside of the repo's internal folder, create a folder using the name of the dependency (or another name of your choice).

    Showing a new folder called 'Box2D' inside of the 'internal' folder inside the NovelRT repository.

  2. Inside of the new folder you created, create a text file called CMakeLists.txt.

    Showing a new file called 'CMakeLists.txt' inside of the 'Box2D' folder inside created in Step 1.

  3. Open the newly created CMakeLists.txt file, and paste the following:

include(FetchContent)
message(STATUS "Fetching [Dependency Name]")

FetchContent_Declare([Dependency Name]
  URL [Dependency Source URL]
  URL_HASH SHA512=[SHA512 of Dependency Source zip/tgz/etc.]

  PREFIX "${CMAKE_CURRENT_BINARY_DIR}"
  TMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/tmp"
  STAMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/stamp"
  DOWNLOAD_DIR "${CMAKE_CURRENT_BINARY_DIR}/dl"
  SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/src"
  SUBBUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/build"
  INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/inst"
  LOG_DIR "${CMAKE_CURRENT_BINARY_DIR}/log"
)

FetchContent_MakeAvailable([Dependency Name])

You will need to replace the following:

  • Replace [Dependency Name] with how you will identify the dependency (Please keep in mind that this name is case-sensitive.)
  • Replace [Dependency Source URL] with the URL for the dependency's ZIP/Tarball package
  • Replace [SHA512 of Dependency Source zip/tgz/etc.] with the SHA512 for the dependency's ZIP/Tarball package

Showing the modified contents of 'CMakeLists.txt' inside an IDE

  1. Open the CMakeLists.txt file inside the internal directory itself, and add the following prior to the NOVELRT_BUILD_TESTS if statement:
    add_subdirectory([Directory Name of Dependency])

    Showing the modified contents of 'CMakeLists.txt' from the 'internal' directory inside an IDE

Now, as long as there's nothing wrong with any of the information you provided in either of the CMakeLists.txt files, you should be able to re-configure NovelRT with CMake and it should begin to download and prepare your dependency to be built!

Clone this wiki locally