# Building CLI Extension copies to wrong output directories (cmake issue)

**URL:** <https://discourse.slicer.org/t/building-cli-extension-copies-to-wrong-output-directories-cmake-issue/1024>\
**Category:** Development\
**Created:** [September 8, 2017, 9:01pm UTC](https://discourse.slicer.org/t/building-cli-extension-copies-to-wrong-output-directories-cmake-issue/1024 "2017-09-08T21:01:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mschwier](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschwier/32/394_2.png) [@mschwier](https://discourse.slicer.org/u/mschwier)\
**Post date:** [September 8, 2017, 9:01pm UTC](https://discourse.slicer.org/t/building-cli-extension-copies-to-wrong-output-directories-cmake-issue/1024/1 "2017-09-08T21:01:28Z")

</div>

I hope I might find some help here. I recently started working on the PkModeling extension an I am trying to get it to build on various continuous integration platforms (Appveyor for Win and Travis CI for Linux and Mac).

[https://github.com/michaelschwier/PkModeling/tree/CI](https://github.com/michaelschwier/PkModeling/tree/CI)

I got the build working on Appveyor but it copies some of the generated files to the wrong output. So the expected output would be “[pkmodeling-build]/bin/Release” (expected files there are: PkModeling.exe, PkModelingLib.dll, PkModelingTest.exe, PkSolver.lib, PkModeling.xml). This works fine when I also build all the dependencies (ITK, DCMTK, ZLIB). However, to avoid building these dependencies on the CI platform I download them pre-built and then tell cmake to use those instead of building them again:

```
cmake -G "Visual Studio 12 2013 Win64" -DITK_DIR:PATH=C:\ITK-install\lib\cmake\ITK-4.10 -DSlicerExecutionModel_DIR:PATH=C:\SlicerExecutionModel\SlicerExecutionModel-build -DDCMTK_DIR:PATH=C:\DCMTK-install\cmake -DZLIB_ROOT:PATH=c:\zlib-install -DZLIB_INCLUDE_DIR:PATH=c:\zlib-install\include -DZLIB_LIBRARY:FILEPATH=c:\zlib-install\lib\zlib.lib c:\pkmodeling

```

And now suddenly the files “PkModeling.exe” and “PkModelingLib.dll” are going to “[pkmodeling-build]/CLI/bin/Release” and the XML is going nowhere 😕 The output directories are defined around line 120 in the main CMakeLists.txt. But I think the SEMMacroBuildCLI from Slicer Execution Model is also setting output dirs. However I can’t seem to figure out why the little difference in calling cmake causes this behavior.

I fixed this with a hack in the appveyor.yml by copying the files via cmd, so that the test can run. But this does not seem like the right way 😉

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [September 8, 2017, 9:33pm UTC](https://discourse.slicer.org/t/building-cli-extension-copies-to-wrong-output-directories-cmake-issue/1024/2 "2017-09-08T21:33:10Z")

</div>

Nice work adding support for CI 👍

You will find below some more details to help you make progress

> the XML is going nowhere

That is strange, here is the code taking care of this:

> <https://github.com/Slicer/SlicerExecutionModel/blob/fa5f22e6346f8115381c1a242c4c50afe0ee8a50/CMake/SEMMacroBuildCLI.cmake#L203-L209>

### Details about handling of `*_OUTPUT_DIRECTORY` and `INSTALL_*_DESTINATION`

When building against SlicerExecutionModel, by default the output\_dirs and install\_dirs are the one used to configure/build SlicerExecutionModel specifying variables like:

- `SlicerExecutionModel_DEFAULT_CLI_${type}_OUTPUT_DIRECTORY`
- `SlicerExecutionModel_DEFAULT_CLI_INSTALL_${type}_DESTINATION`

with `${type}` being any of `RUNTIME`, `LIBRARY` or `ARCHIVE`,

If for some reason, the default install and output dirs used to configure SlicerExecutionModel are not satisfactory. These can be globally overridden in the project by setting these variables before calling the macro:

- `SlicerExecutionModel_CLI_${type}_OUTPUT_DIRECTORY`
- `SlicerExecutionModel_CLI_INSTALL_${type}_DESTINATION`

Last, these can also be overridden on a per CLI basis by passing parameters to the macro:

- `${type}_OUTPUT_DIRECTORY`
- `INSTALL_${type}_DESTINATION`

The logic can be found here for output dir:

> <https://github.com/Slicer/SlicerExecutionModel/blob/fa5f22e6346f8115381c1a242c4c50afe0ee8a50/CMake/SEMMacroBuildCLI.cmake#L182-L194>

and here for install destination:

> <https://github.com/Slicer/SlicerExecutionModel/blob/fa5f22e6346f8115381c1a242c4c50afe0ee8a50/CMake/SEMMacroBuildCLI.cmake#L212-L223>

---

<div class="post-metadata">

**Author:** ![mschwier](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschwier/32/394_2.png) [@mschwier](https://discourse.slicer.org/u/mschwier)\
**Post date:** [September 8, 2017, 10:41pm UTC](https://discourse.slicer.org/t/building-cli-extension-copies-to-wrong-output-directories-cmake-issue/1024/3 "2017-09-08T22:41:15Z")

</div>

Thanks, explicitly passing the output dirs to the macro helped with the libs and exes already. Now I’ll see about the xml.

---

<div class="post-metadata">

**Author:** ![mschwier](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschwier/32/394_2.png) [@mschwier](https://discourse.slicer.org/u/mschwier)\
**Post date:** [September 11, 2017, 8:03pm UTC](https://discourse.slicer.org/t/building-cli-extension-copies-to-wrong-output-directories-cmake-issue/1024/4 "2017-09-11T20:03:11Z")

</div>

OK, found the problem with the XML copying: I was cloning a branch, which didn’t contain the code to copy the XML yet. 🙄
