In our project, some modules are included only in specific configurations. Currently, we achieve this using an approach like this:
if (CMAKE_BUILD_TYPE STREQUAL "my_config")
add_subdirectory(only_in_my_config)
endif()
However, the problem with this approach is that it doesn't play nicely with multi-config generators (it seems currently those are only Visual Studio and Xcode).
To properly support multi-config generators, AFAIK, we should use $<CONFIG:my_config>
generator expression. However, those cannot be used with add_subdirectory
.
How to work around this?
I guess we must add all subdirectories always. But then how to prevent their targets from being build in configurations other than my_config
?