Issue
I need to set the environment variable GLIBCXX_FORCE_NEW=1 for DEBUG builds only, in cmake.
In the cmake documentation, I could only find:
CMAKE_CXX_COMPILER
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
Solution
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.
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")
Answered By - sakra Answer Checked By - Gilberto Lyons (WPSolving Admin)