CMake-如何为目标可执行文件设置多个编译定义? [英] CMake - how to set multiple compile definitions for target executable?

查看:508
本文介绍了CMake-如何为目标可执行文件设置多个编译定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为要在CMake中编译的一个可执行文件设置多个编译定义(以激活用于调试的宏)。这是我尝试的方法:

I'm trying to set multiple compile definitions for one of the executables I'm trying to compile in CMake (in order to activate macros used for debugging). Here's what I tried:

add_executable (trie_io_test trie_io_test.c trie.c word_list.c)
    set_target_properties(
            trie_io_test
            PROPERTIES
            COMPILE_DEFINITIONS UNIT_TESTING=1)
    set_target_properties(
            trie_io_test
            PROPERTIES
            COMPILE_DEFINITIONS IO_TEST=1)

不幸的是,这仅导致定义了IO_TEST。

Unfortunately this causes only the IO_TEST to be defined.

我也尝试了以下:

add_executable (trie_io_test trie_io_test.c trie.c word_list.c)
    set_target_properties(
            trie_io_test
            PROPERTIES
            COMPILE_DEFINITIONS UNIT_TESTING=1 IO_TEST=1)

但是另一方面,会导致CMake错误。

But this, on the other hand, causes CMake error.

如何为我要构建的可执行文件设置这两个定义?

How to set both of these definitions for the executable I'm trying to build?

推荐答案

您想要 target_compile_definitions 代替的 set_target_properties

target_compile_definitions(trie_io_test PRIVATE UNIT_TESTING=1 IO_TEST=1)

这篇关于CMake-如何为目标可执行文件设置多个编译定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆