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
with ExternalProject.
The problem is Dependency_2
will be downloaded twice: Dependency_1
will download a copy for itself, and MainProject
will download a copy for itself.
This doesn't make for an efficient build process, is there a way where I can download Dependency_2
once for both projects?
Is has been suggested that this question is a duplicate of this one. That question slightly varies from mine, in that I cannot assume these libraries will be installed to the host system with ExternalProject. I would also like a CMake only solution, to which that question did not require.
From the main CMakeLists.txt, set an environment variable containing a common root path for downloading and building external projects, for example:
set (ENV EXTERNAL_PROJ_DOWNLOAD_DIR "${CMAKE_SOURCE_DIR}/externalProjects")
to be used as root folders for the download and the builds of the dependencies. You can set (and use) it in your main project, and read this value from within your first dependency (the one that also depends to your second dependency).
Seen it in practice applied to the project linked in your comments, you'll set EXTERNAL_PROJ_DOWNLOAD_DIR
IN Khronos, and then to link to PortAudio in both 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 could also use set (ENV EXTERNAL_PROJ_BINARY_DIR "${CMAKE_BINARY_DIR}/externalProjects")
if you wanted to activate the out of source build.
I suggest to use an environment variable because I don't know if a cache variable set from Khronos would be visible in tritium...
See documentation for set and env.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With