[CMake] config-specific compiler definitions don't work properly

Xi Yang jiandingzhe at 163.com
Fri Jul 17 09:08:46 EDT 2015


Hi everyone!


I'm trying to use config-specific definitions, but it seems doesn't work in VS2013.


This is the CMakeLists.txt:


cmake_minimum_required(VERSION 3.0)


set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS_DEBUG
    FOO
)


set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS_RELEASE
    BAR
)


add_executable(main main.cpp)
set_target_properties(main
    PROPERTIES
        COMPILE_DEFINITIONS_DEBUG   FOO
        COMPILE_DEFINITIONS_RELEASE BAR
)


Both target property and directory property are tried. And this is the source code main.cpp:


#ifdef FOO
#error got foo
#endif


#ifdef BAR
#error got bar
#endif


int main(int argc, char** argv)
{
    return 0;
}


If the definitions are sent to compilers, it should die with foo on Debug config, and die with bar on Release config. However, it finished compilation on both Debug and Release.


I also have a look at the command line parameters of the Debug and Release config, it don't have "/D FOO" and "/D BAR".


Thanks for a lot!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150717/90b497e2/attachment.html>


More information about the CMake mailing list