如何仅在cmake中为DEBUG构建设置GLIBCXX_FORCE_NEW = 1? [英] How do I set GLIBCXX_FORCE_NEW=1 in cmake for DEBUG builds only?
问题描述
我只需要在cmake中为DEBUG构建设置环境变量GLIBCXX_FORCE_NEW = 1。
I need to set the environment variable GLIBCXX_FORCE_NEW=1 for DEBUG builds only, in cmake.
在cmake文档中,我只能找到:
In the cmake documentation, I could only find:
-
CMAKE_CXX_COMPILER
CMAKE_CXX_COMPILER
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_RELWITHDEBINFO
推荐答案
环境变量 GLIBCXX_FORCE_NEW
仅影响运行时已编译程序的行为(请参见 gcc文档)。将其作为预处理器定义添加到程序的编译期间(例如,通过设置CMAKE_CXX_FLAGS)将不会起作用。
The environment variable GLIBCXX_FORCE_NEW
only affects the behavior of a compiled program at runtime (see the gcc documentation). Adding it as a preprocessor define during compile time of a program (e.g., by setting the CMAKE_CXX_FLAGS) will not have an effect.
使用CMake可以设置一个环境变量仅对 CMake测试影响已构建目标的运行时间。以下命令添加了一个对DEBUG构建有效的测试,该测试将运行带有 GLIBCXX_FORCE_NEW
变量集的可执行文件:
With CMake you can set an environment variable that affects the runtime of a built target only for CMake tests. The following commands add a test valid for DEBUG builds, which will run an executable with the GLIBCXX_FORCE_NEW
variable set:
add_test(NAME MyTest CONFIGURATIONS Debug COMMAND MyExecutable)
set_tests_properties(MyTest PROPERTIES ENVIRONMENT "GLIBCXX_FORCE_NEW=1")
这篇关于如何仅在cmake中为DEBUG构建设置GLIBCXX_FORCE_NEW = 1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!