Skip to content

[CMake error] FetchContent_MakeAvailable(volk) breaks subsequent FetchContent_MakeAvailable #815

@xerpi

Description

@xerpi

Summary

I'm trying to use VOLK (as a static library) in my project, and for that I'm using FetchContent_MakeAvailable(volk).
After volk is made available, a subsequent FetchContent_MakeAvailable(...) (e.g. spdlog) fails with:

CMake Error at /usr/share/cmake/Modules/FetchContent.cmake:1591 (message):
  Internal error: SUBBUILD_DIR not set
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FetchContent.cmake:2155:EVAL:2 (__FetchContent_doPopulation)
  /usr/share/cmake/Modules/FetchContent.cmake:2155 (cmake_language)
  /usr/share/cmake/Modules/FetchContent.cmake:2394 (__FetchContent_Populate)
  CMakeLists.txt:26 (FetchContent_MakeAvailable)

This appears to be caused by VOLK mutating global CMake directory variables.

Environment

  • CMake: 4.2.3
  • OS: Linux (x86_64)
  • VOLK: main (511fff053e190316919733fb148b70946f139a9e)

Minimal Reproducer

CMakeLists.txt:

cmake_minimum_required(VERSION 3.24)
project(volk_fetchcontent_repro LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)

# Avoid unrelated cpu_features min-CMake issue on this setup
set(VOLK_CPU_FEATURES OFF CACHE BOOL "Disable cpu_features for repro" FORCE)

# 1) Fetch VOLK first
FetchContent_Declare(
  volk
  GIT_REPOSITORY https://github.com/gnuradio/volk.git
  GIT_TAG main
)
FetchContent_MakeAvailable(volk)

# 2) Then fetch another project (spdlog)
FetchContent_Declare(
  spdlog
  GIT_REPOSITORY https://github.com/gabime/spdlog.git
  GIT_TAG v1.17.0
)
FetchContent_MakeAvailable(spdlog)

add_executable(repro main.cpp)
target_link_libraries(repro PRIVATE volk spdlog::spdlog)

main.cpp:

#include <volk/volk.h>
#include <spdlog/spdlog.h>

int main()
{
    spdlog::info("Includes from VOLK and spdlog are visible");
    return 0;
}

Repro Command

cmake --fresh -S . -B build

Actual Result

Configuration fails at the second FetchContent_MakeAvailable(spdlog) with Internal error: SUBBUILD_DIR not set.

Expected Result

FetchContent_MakeAvailable(spdlog) should work normally after FetchContent_MakeAvailable(volk).

Additional Notes

  • spdlog alone configures successfully.
  • spdlog first, then volk, also configures successfully.
  • So this appears order-dependent (volk first triggers it).

Suspected Root Cause

VOLK top-level CMakeLists.txt reassigns global CMake vars:

set(CMAKE_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) #allows this to be a sub-project
set(CMAKE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) #allows this to be a sub-project

These should not be overridden by a subproject and likely break FetchContent internals for later dependencies.

Suggested Fix

Remove those assignments and use CMAKE_CURRENT_SOURCE_DIR / CMAKE_CURRENT_BINARY_DIR directly where needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions