In my particular CMake project, I have three C++ files:
a.cpp
b.cpp
c.cpp
I want ‘a.cpp’ to be compiled in all configurations (release & debug).
I only want ‘b.cpp’ to be compiled in DEBUG configuration.
I only want ‘c.cpp’ to be compiled in RELEASE configuration.
How can I do this? I need something similar to the debug and optimized keywords that are accepted by the target_link_libraries() CMake operation.
As far as I know cmake does not provide a way to exclude some files based on configuration. So you need a workaround to achieve this behavior.
For example, you can wrap the whole content of
b.cppandc.cppwith some guard macro:and next set configuration-specific compiler definitions in cmake: