wl2776
wl2776

Reputation: 4327

How to turn off a project for Debug config in CMake-generated Visual Studio solution

Right-click on the solution title in the Solution Explorer window, then go to Configuration Properties -> Configuration. The table appears, showing check-boxes, allowing to turn off/on a build of particular projects for certain configurations.

My solution and projects are generated with CMake.

Is it possible to turn off a particular project for Debug build configuration from CMakeLists.txt?

==

Background of a problem is failing build of Cython project for Debug config. Release builds fine. CMake module was taken from this example on Github.

Debug config wants debug Python library python27_d.lib, that is forced by pyconfig.h. I use Anaconda python, which is missing this library.

Moreover, I don't need debug build of that project. I've unsuccessfully spent several hours, modifying CMakeLists.txt in various ways, trying to remove definition of _DEBUG macro from compiler command line. CLI parameter /D_DEBUG was absent in all dialogs with properties and "complete command line" listings, that Visual Studio has shown me. Nevertheless, something has always appended it.

So, I'd like to simply disable this project in Debug build for now.

Upvotes: 0

Views: 2966

Answers (1)

wl2776
wl2776

Reputation: 4327

This sets that check-box from the first part of the question to unchecked state:

set_property(TARGET <my Cython module>
             PROPERTY EXCLUDE_FROM_DEFAULT_BUILD_DEBUG TRUE)

Now I wonder, where did compiler command line come from, because /D_DEBUG was absent in all dialogs with properties, that Visual Studio has shown me (second part of the question).

I am building this project in VS2013. Initially, that string /D_DEBUG was present in Project properties -> C/C++ -> Preprocessor -> Preprocessor definitions for the Debug configuration. Then I've added

string(REPLACE "/D_DEBUG" "" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")

to my CMakeLists.txt file, building the Cython code, and that macro has disappeared from the Project properties.

Nevertheless, the project was still requiring python27_d.dll.

I've also added

#define _DEBUG

in one of files, and have got the following compiler warning

C:\projects\project\file.cpp(9): warning C4005: '_DEBUG' : macro redefinition
          command-line arguments :  see previous definition of '_DEBUG'

Upvotes: 1

Related Questions