Skip targets to be built in certain configuration


I have next problem:

I’m using cmake to configure and build my project for both Linux and Windows OSs. For Windows it uses multi-generator to configure the solution with different configs and for Linux I have separate configuration be generated for Release and for Debug.

That’s being said, for Windows configuration I do not have CMAKE_BUILD_TYPE variable specified.

Now to the problem:
I have a project, let’s call it projectA that has UnitTest within it. That project is tested with UnitTest, and the “definition” of the project and of the UnitTest related project are done in scope of the same CMakeLists.txt file, something like this:

add_library(projectA SHARED main.cpp)

add_executable(projectATest test.cpp)

so far so good, everything works as expected, the ProjectA compiles on both platforms without any problems, the tests are also executed on both platforms without any problems.

Now I’d like my tests to be build (compiled and run) ONLY on debug configuration, on Linux I can do simply by checking CMAKE_BUILD_TYPE being ‘Debug’ and include tests project generation only then, though I’m not sure if this is correct approach to take. For Windows however the approach above won’t work due to multi-configuration. Therefore, I tried playing with target_properties…

In my main CMakeFiles.txt I set configuration to be only Debug and Release (by default there are two more added, I don’t need then for now):


then, on ProjectA’s CMakeFiles.txt file I did next:


I got next:
The ProjectATest project is excluded from the Release configuration (I can see this by opening my entire solution, via .sln file generated, and looking into the Configuration Manager.

However, I’m not using VS solution to compile my project, I’m using Jenkins that uses the .py script that does next:

  1. generates the project:
    cmake . -A x64 -T v141 -B

  2. builds the projects
    cmake --build --config Debug
    cmake --build --config Release

and when I do build as is described above - the ProjectATest is still being built for Release configuration, even though the Property EXCLUDE_FROM_DEFAULT_BUILD_RELEASE is set to TRUE

Would appreciate any suggestions on how to address the case.
Thanks in advance.