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

Petr Kmoch petr.kmoch at gmail.com
Fri Jul 17 09:42:50 EDT 2015


Hi.

Looking at the documentation (
http://www.cmake.org/cmake/help/v3.3/manual/cmake-properties.7.html#properties-on-directories
,
http://www.cmake.org/cmake/help/v3.3/manual/cmake-properties.7.html#properties-on-targets
), you will find that neither the directory property nor the target
property COMPILE_DEFINITIONS has per-configuration variants. They do
support generator expressions, however, so you could use these instead:

  set_property(DIRECTORY PROPERTY COMPILE_DEFINITIONS
$<$<CONFIG:Debug>:FOO> $<$<CONFIG:Release>:BAR>)

Petr


On Fri, Jul 17, 2015 at 3:08 PM, Xi Yang <jiandingzhe at 163.com> wrote:

> 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!
>
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150717/1a412d95/attachment.html>


More information about the CMake mailing list