Verified Commit d57e6c09 authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

CMake: Better handling of external submodules

The function include_from_source() now checks if the source directory
for a external dependency is empty. If so, it will provide instructions
for the user to solve the issue (such as properly initializing
submodules).
parent 5ae10082
Loading
Loading
Loading
Loading
Loading
+16 −3
Original line number Diff line number Diff line
@@ -208,13 +208,26 @@ function(include_from_source contentName)
  include(FetchContent)

  if (EXISTS ${ARGS_SOURCE_DIR})
    message(STATUS "Found Git submodule for \"${contentName}\": building it.")
    file(GLOB_RECURSE SOURCE_FILES "${ARGS_SOURCE_DIR}/*")
    if(SOURCE_FILES STREQUAL "")
      message(FATAL_ERROR
        "The '${ARGS_SOURCE_DIR}' source directory appears "
        "to be empty. If it corresponds to a git submodule it may not have "
        "been properly initialized. Running:\n"
        "  'git submodule update --init --recursive'\n"
        "may fix the issue. If the directory corresponds to a manually "
        "downloaded dependency, please download it again.")
    endif()

    message(STATUS "Found source directory for '${contentName}'. Building.")
    FetchContent_Declare(
      ${contentName}
      SOURCE_DIR ${ARGS_SOURCE_DIR}
    )
  else()
    message(STATUS "Git submodule for \"${contentName}\" not found. Downloading and building from Git repository.")
    message(STATUS
      "Source directory for '${contentName}' not found.\n"
      "Downloading and building from remote Git repository.")

    if(NOT ARGS_GIT_REPOSITORY)
      message(FATAL_ERROR "GIT_REPOSITORY for \"${contentName}\" not defined")
+5 −4
Original line number Diff line number Diff line
@@ -217,12 +217,13 @@ find_package(Filesystem REQUIRED)
# Search for 'source-only' dependencies
###############################################################################

set(GIT_SUBMODULES_PATH ${CMAKE_SOURCE_DIR}/external)
# the directory where external dependencies should be searched for
set(GKFS_DEPENDENCIES_PATH ${CMAKE_SOURCE_DIR}/external)

### {fmt}: required for sensible output formatting
include_from_source(fmt
  MESSAGE "[${PROJECT_NAME}] Searching for {fmt}"
  SOURCE_DIR ${GIT_SUBMODULES_PATH}/fmt
  SOURCE_DIR ${GKFS_DEPENDENCIES_PATH}/fmt
  GIT_REPOSITORY https://github.com/fmtlib/fmt
  GIT_TAG f94b7364b9409f05207c3af3fa4666730e11a854 # v6.1.2
)
@@ -233,7 +234,7 @@ set_property(TARGET fmt PROPERTY POSITION_INDEPENDENT_CODE ON)
### spdlog: required for logging
include_from_source(spdlog
  MESSAGE "[${PROJECT_NAME}] Searching for spdlog"
  SOURCE_DIR ${GIT_SUBMODULES_PATH}/spdlog
  SOURCE_DIR ${GKFS_DEPENDENCIES_PATH}/spdlog
  GIT_REPOSITORY https://github.com/gabime/spdlog.git
  GIT_TAG eb3220622e73a4889eee355ffa37972b3cac3df5 # v1.9.2
  )
@@ -241,7 +242,7 @@ include_from_source(spdlog
### CLI11: used for parsing command-line options
include_from_source(cli11
  MESSAGE "[${PROJECT_NAME}] Searching for CLI11"
  SOURCE_DIR ${GIT_SUBMODULES_PATH}/CLI11
  SOURCE_DIR ${GKFS_DEPENDENCIES_PATH}/CLI11
  GIT_REPOSITORY https://github.com/CLIUtils/CLI11
  GIT_TAG v2.2.0
  )