# Skip targets to be built in certain configuration

**URL:** https://discourse.cmake.org/t/skip-targets-to-be-built-in-certain-configuration/1874
**Category:** Usage
**Created:** [September 21, 2020, 6:03pm UTC](https://discourse.cmake.org/t/skip-targets-to-be-built-in-certain-configuration/1874 "2020-09-21T18:03:48Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![andriy](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/8edcca/32.png) [@andriy](https://discourse.cmake.org/u/andriy)
#### Post date: [September 21, 2020, 6:03pm UTC](https://discourse.cmake.org/t/skip-targets-to-be-built-in-certain-configuration/1874/1 "2020-09-21T18:03:48Z")

</div>

Hello,

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)  
add\_test(…)

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):

_set(CMAKE\_CONFIGURATION\_TYPES Debug Release CACHE STRING “” FORCE)_

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

_set\_target\_properties(ProjectATest PROPERTIES EXCLUDE\_FROM\_DEFAULT\_BUILD\_RELEASE TRUE)_

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.
