Add custom config in subdir

Gary Oberbrunner
Mon, 29 Apr 2024 21:24:57 +0000
Usage

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:

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.

2 posts - 2 participants