Creating subdirectories within `_deps` when using FetchContent

Hello,

I am developing a small embedded system project, and have chosen CMake to be our build generator. I have a bunch of components being developed independently, and brought into the main project using the FetchContent command. The current problem I’m facing (more of an annoyance) is that each target is being installed under build/Debug/_deps. Is there a way to create subdirectories within the _deps directory to better organize all my dependencies? For example, creating a build/Debug/_deps/uart_deps for my UART components?

Thanks,
Vink

  • Do you want to control were libs and exe are build?
  • Or do you meean, were the sources are cloned?

For first one, this helps:

set(stageDir ${CMAKE_CURRENT_BINARY_DIR}/stage)
include(GNUInstallDirs)

if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${stageDir}/${CMAKE_INSTALL_BINDIR})
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${stageDir}/${CMAKE_INSTALL_LIBDIR})
endif()
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${stageDir}/${CMAKE_INSTALL_LIBDIR})
endif()

Hi Claus,

Thanks for your reply, I mean where the sources are cloned.

FetchContent — CMake 3.29.0-rc1 Documentation

see FETCHCONTENT_BASE_DIR

1 Like

With CPM.cmake you would have more options:

  • With CPM.cmake, you may use a central cache for the cloned external projects.
  • Wo it is very fast, if found in cpm_source_cache.
  • And you have the option to use local installed packages if found (CPM_USE_LOCAL_PACKAGES).

see CPM.cmake options

1 Like

Setting the FETCHCONTENT_BASE_DIR var solved my problem, but it seems that the CPM.cmake tool makes everything a lot cleaner! Thanks for the recommendation!