# Need more than one local source directory in ExternalProject

**URL:** <https://discourse.cmake.org/t/need-more-than-one-local-source-directory-in-externalproject/5514>\
**Category:** Code\
**Created:** [April 21, 2022, 7:47pm UTC](https://discourse.cmake.org/t/need-more-than-one-local-source-directory-in-externalproject/5514 "2022-04-21T19:47:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![drlangnh](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/b5a626/32.png) [@drlangnh](https://discourse.cmake.org/u/drlangnh)\
**Post date:** [April 21, 2022, 7:47pm UTC](https://discourse.cmake.org/t/need-more-than-one-local-source-directory-in-externalproject/5514/1 "2022-04-21T19:47:51Z")

</div>

I have a project consisting of a CMake “external project” that creates a custom target for a Microchip PIC MCU. I would like to extend this project to build an additional custom target for a second MCU in the same family as the first. Each MCU would have its own configuration and driver files, but most of the task-level code would be shared between the two MCUs. Consequently, two external projects would be needed, each pulling in the shared code as well as the code specific to its corresponding MCU. I would like to keep all of the source code local: each external project would have its own source directory, and there would be a shared source directory. However, the ExternalProject\_Add() function only accommodates a single local URL when specifying where source files are to be obtained from. Is there any way to overcome this limitation? Thanks.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [April 22, 2022, 11:58am UTC](https://discourse.cmake.org/t/need-more-than-one-local-source-directory-in-externalproject/5514/2 "2022-04-22T11:58:21Z")

</div>

Would this work?

```cmake
set(common_source_dir "${CMAKE_CURRENT_BINARY_DIR}/src")
ExternalProject_add(common-src
  # Source args…
  SOURCE_DIR "${common_source_dir}/common"
  CONFIGURE_COMMAND ""
  BUILD_COMMAND ""
  INSTALL_COMMAND "")
ExternalProject_add(src-variant-1
  # Source args…
  SOURCE_DIR "${common_source_dir}/variant-1"
  CONFIGURE_COMMAND ""
  BUILD_COMMAND ""
  INSTALL_COMMAND "")
ExternalProject_add(build-variant-1
  DEPENDS common-src variant-1-src
  SOURCE_DIR "${common_source_dir}/common"
  CMAKE_ARGS
    -DVARIANT_DIR:PATH=${common_source_dir}/variant-1"
  …)

```

---

<div class="post-metadata">

**Author:** ![drlangnh](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/d/b5a626/32.png) [@drlangnh](https://discourse.cmake.org/u/drlangnh)\
**Post date:** [May 2, 2022, 7:56pm UTC](https://discourse.cmake.org/t/need-more-than-one-local-source-directory-in-externalproject/5514/3 "2022-05-02T19:56:24Z")

</div>

Ben, thanks for your rapid feedback and apologies for my delayed response. I incorporated your suggestions into my code and got closer to the desired outcome, but no cigar. Then I took a step back and realized that Microchip provides a Makefile generation tool that I could use instead of CMake. The resulting solution is actually quite elegant. The developer who previously worked on this project had used CMake exclusively, and I had assumed that simply extending his implementation would be the way to go. Again, thanks for your feedback and sorry for the trouble.
