Avoiding Additional ExternalProject Downloads

Let's say I have the following project setup with these dependencies:

MainProject โ”œโ”€ Dependency_1 โ”‚ โ””โ”€ Dependency_2 โ””โ”€ Dependency_2 

These dependencies are handled in MainProject and Dependency_1 using ExternalProject .

Problem Dependency_2 will be downloaded twice: Dependency_1 download a copy for itself, and MainProject download a copy for itself.

This does not make for an efficient build process, is there a way when I can load Dependency_2 once for both projects?


It has been suggested that this question be a duplicate of this . This question is slightly different from mine, as I cannot assume that these libraries will be installed on the host system using ExternalProject. I would also like the CMake solution, for which this question was not required.

+7
external installation build dependencies cmake
source share
1 answer

From the main CMakeLists.txt, set the environment variable containing the common root path for loading and building external projects, for example:

 set (ENV EXTERNAL_PROJ_DOWNLOAD_DIR "${CMAKE_SOURCE_DIR}/externalProjects") 

for use as root folders for downloading and creating dependencies. You can install (and use) it in your main project and read this value from your first dependency (one that also depends on your second dependency).

In practice, this applies to the project associated with your comments, you set EXTERNAL_PROJ_DOWNLOAD_DIR IN Khronos, and then for the link to PortAudio in the Khronos and tritium projects you will have:

 find_package(PortAudio) if (${PORTAUDIO_FOUND}) include_directories(${PORTAUDIO_INCLUDE_DIRS}) else () ExternalProject_Add( PortAudio GIT_REPOSITORY "https://github.com/syb0rg/PortAudio2.git" SOURCE_DIR "$ENV{EXTERNAL_PROJ_DOWNLOAD_DIR}/PortAudio" UPDATE_COMMAND "" INSTALL_COMMAND "" BUILD_IN_SOURCE ON LOG_DOWNLOAD ON LOG_UPDATE ON LOG_CONFIGURE ON LOG_BUILD ON LOG_TEST ON LOG_INSTALL ON ) ExternalProject_Get_Property(PortAudio SOURCE_DIR) ExternalProject_Get_Property(PortAudio BINARY_DIR) set(PORTAUDIO_SOURCE_DIR ${SOURCE_DIR}) set(PORTAUDIO_BINARY_DIR ${BINARY_DIR}) set(PORTAUDIO_LIBRARIES ${PORTAUDIO_SOURCE_DIR}/libportaudio_static.a) set(DEPENDENCIES ${DEPENDENCIES} PortAudio) include_directories(${PORTAUDIO_SOURCE_DIR}/include) endif () SET(LIBS ${LIBS} ${PORTAUDIO_LIBRARIES}) 

You can also use set (ENV EXTERNAL_PROJ_BINARY_DIR "${CMAKE_BINARY_DIR}/externalProjects") if you want to activate the source assembly.

I suggest using an environment variable because I don't know if the cache variable from Khronos to tritium will be displayed ...

See the documentation for set and env .

+1
source share

All Articles