# ExternalProject\_Add error finding source directory

**URL:** <https://discourse.cmake.org/t/externalproject-add-error-finding-source-directory/2922>\
**Category:** Code\
**Created:** [March 8, 2021, 8:12pm UTC](https://discourse.cmake.org/t/externalproject-add-error-finding-source-directory/2922 "2021-03-08T20:12:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kmilo9999](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kmilo9999/32/1246_2.png) [@kmilo9999](https://discourse.cmake.org/u/kmilo9999)\
**Post date:** [March 8, 2021, 8:12pm UTC](https://discourse.cmake.org/t/externalproject-add-error-finding-source-directory/2922/1 "2021-03-08T20:12:09Z")

</div>

Hello,

I am writing a C.I script for my c++ project, and I would like to use ExternalProject\_Add command to autodownload and build the dependencies. One of those is glew (graphics library) which I get from the url “[https://sourceforge.net/projects/glew/files/glew/2.1.0/glew-2.1.0.zip](https://sourceforge.net/projects/glew/files/glew/2.1.0/glew-2.1.0.zip)”. This is the cmake command:

```cmake
ExternalProject_Add(${SUBPROJECT_NAME}
    PREFIX ${SUBPROJECT_NAME}
    DOWNLOAD_DIR ${SUBPROJECT_NAME}
    STAMP_DIR ${SUBPROJECT_STAMP_PATH}
    SOURCE_DIR ${SUBPROJECT_SOURCE_PATH}
    BINARY_DIR ${SUBPROJECT_BUILD_PATH}
    URL ${GLEW_URL}
    LIST_SEPARATOR | # Use the alternate list separator
    CMAKE_ARGS
      -DCMAKE_BUILD_TYPE=Release
      -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
      -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
      -DCMAKE_INSTALL_PREFIX:PATH=${SUBPROJECT_INSTALL_PATH}
      -DCMAKE_INSTALL_INCLUDEDIR=${CMAKE_INSTALL_INCLUDEDIR}
      -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
      -DCMAKE_INSTALL_DOCDIR=${CMAKE_INSTALL_DOCDIR}
      -DCMAKE_INSTALL_BINDIR=${CMAKE_INSTALL_BINDIR}
      -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
      ${BUILD_SUBPROJECT_BUILD_ARGS}
    BUILD_COMMAND "cmake -G ${CMAKE_GENERATOR} -S ${EXTERNAL_DIR_LOCATION}/${SUBPROJECT_NAME}/source/build/cmake --build ."
    BUILD_ALWAYS OFF
  )

```

Now, the problem is when I try to build the glew project I get the error:

```
CMake error : The source directory "D:/VR-Volumeviewer/superbuild/build/install" does not exist.

```

I dont really know where the error is coming from. I checked the visual studio project, and it seems that path comes from the DCMAKE\_PREFIX\_PATH, but not sure.

Any thoughts on how to overcome it ?

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [March 8, 2021, 9:07pm UTC](https://discourse.cmake.org/t/externalproject-add-error-finding-source-directory/2922/2 "2021-03-08T21:07:34Z")

</div>

(I reformatted your post a little to make the example code clearer)

It looks like you’ve tried to combine the configure and build steps into the one command. These are separate steps. I’m assuming that you found that the configure and build commands that CMake normally creates for you automatically don’t do what you want, presumably because you want to use a different source directory than just the top of the source tree obtained from the URL? I would suggest you use the `SOURCE_SUBDIR` option to specify that instead of trying to provide your own configure/build commands. You shouldn’t need to specify `BUILD_COMMAND` or `BUILD_ALWAYS` here.

You may also want to check the contents of the `BUILD_SUBPROJECT_BUILD_ARGS` variable. Do they contain what you expect them to? Are they valid arguments to a `cmake` command? Do they contain any words that would be picked up as keywords for the `ExternalProject_Add()` command?

---

<div class="post-metadata">

**Author:** ![kmilo9999](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kmilo9999/32/1246_2.png) [@kmilo9999](https://discourse.cmake.org/u/kmilo9999)\
**Post date:** [March 9, 2021, 2:48am UTC](https://discourse.cmake.org/t/externalproject-add-error-finding-source-directory/2922/3 "2021-03-09T02:48:01Z")

</div>

`SOURCE_SUBDIR` made the trick.

Thanks,
