# Add custom config in subdir

**URL:** https://discourse.cmake.org/t/add-custom-config-in-subdir/10761
**Category:** Usage
**Tags:** os:windows, lang:cuda
**Created:** [April 29, 2024, 9:24pm UTC](https://discourse.cmake.org/t/add-custom-config-in-subdir/10761 "2024-04-29T21:24:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![garyo](https://discourse.cmake.org/user_avatar/discourse.cmake.org/garyo/32/4364_2.png) [@garyo](https://discourse.cmake.org/u/garyo)
#### Post date: [April 29, 2024, 9:24pm UTC](https://discourse.cmake.org/t/add-custom-config-in-subdir/10761/1 "2024-04-29T21:24:57Z")

</div>

I have a set of subdirs with example programs that cmake builds. To keep things simple, the subdirs don’t have their own CMake files, just the sources; they all follow a common template. So the top-level CMake file looks like this:

```cmake
set(PLUGINS
	Basic
	ChoiceParams
	ColorSpace
        ....
)

foreach(PLUGIN IN LISTS PLUGINS)
	file(GLOB_RECURSE PLUGIN_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/${PLUGIN}/*.cpp")

        set(TGT example-${PLUGIN})
	add_ofx_plugin(${TGT} ${PLUGIN}) # this is a custom step
	target_sources(${TGT} PUBLIC ${PLUGIN_SOURCES})
	target_link_libraries(${TGT} ${CONAN_LIBS})
	target_include_directories(${TGT} PUBLIC ${OFX_HEADER_DIR} ${OFX_SUPPORT_HEADER_DIR})
endforeach()

```

But now I want one of those subdirs to have some customization (add a lib from conan, maybe different compiler flags). I could omit it from the `${PLUGINS}` list and use `add_subdir` and add a `CMakeLists.txt` to it, but then it’ll get built and installed into a subdir, differently from all the others. Any hints on how to do this cleanly? It’s an open-source project so I want it to follow best practices, but I’m no cmake expert.

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [April 30, 2024, 6:04am UTC](https://discourse.cmake.org/t/add-custom-config-in-subdir/10761/2 "2024-04-30T06:04:24Z")

</div>

If you want to follow best practises, you shouldn’t be globbing the source files.  
A canonical way is really having a CMakeLists.txt in subdirectories. The stuff you’re doing in the foreach loop now, could be extracted to a function/macro, and then you can do whatever you like with the resulting target.
