0

I'm adding Google's native webrtc library as an external dependency to a CMake project I'm working on. The build process for the webrtc library is rather convoluted but the initial steps are as follows:

  1. Cloning chromium depot_tools repo
  2. Adding depot_tools to environment PATH
  3. Running fetch --nohooks webrtc (fetch tool is found in PATH from previous step)
  4. Several further steps I'll omit as they're not relevant to the question

I can successfully perform all these steps manually from the command line to build the library.

To simply my build process I thought I'd use ExternalProject_Add with several ExternalProject_Add_Steps to create a target that my main project can use as a dependency:

ExternalProject_Add(
        ${PROJECT_NAME} 
        GIT_REPOSITORY https://chromium.googlesource.com/chromium/tools/depot_tools.git
        CONFIGURE_COMMAND "" 
        UPDATE_COMMAND "" 
        PATCH_COMMAND "" 
        BUILD_COMMAND "" 
        INSTALL_COMMAND ""
)

ExternalProject_Add_Step(
        ${PROJECT_NAME} fetch-webrtc
        COMMAND fetch --nohooks webrtc # <--- how to get fetch into PATH?
        DEPENDEES mkdir-webrtc
)

...

The problem I have is that when the fetch-webrtc step is run the fetch tool is not in the PATH. Now I could "cheat" and change the above step to the following:

ExternalProject_Get_Property(${PROJECT_NAME} SOURCE_DIR)
ExternalProject_Add_Step(
        ${PROJECT_NAME} fetch-webrtc
        COMMAND ${SOURCE_DIR}/fetch --nohooks webrtc # fetch is found!
        DEPENDEES mkdir-webrtc
)

This partly solves the issue, however the fetch command itself requires the depot_tools repo to be in the path as it looks for many files there - thus things ultimately fail.

So how can I go about getting the depot_tools directory into the PATH environment variable (ideally prefixed to the front of all the PATH directories) available for all ExternalProject_Add_Step steps?

dbotha
  • 1,501
  • 4
  • 20
  • 38
  • COMMAND clause in `ExternalProject_Add_Step` denotes the same as COMMAND clause in the `add_custom_command`/`add_custom_target`. So the answers from [the question about custom target](https://stackoverflow.com/questions/35029277/how-to-modify-environment-variables-passed-to-custom-cmake-target) are applicable for your case too. – Tsyvarev Aug 13 '21 at 21:23
  • Thanks @Tsyvarev . I had actually tried the selected answer in that post, which for whatever reason did not work for me so I dismissed it. Your `wrapper.bat` / `wrapper.sh` approach did though! – dbotha Aug 16 '21 at 12:05

0 Answers0