0

I added -rdynamic option in debug build in CMakeLists.txt like following.
Is there a better or simple way to this?

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    target_link_libraries(${PROJECT_NAME}
        -rdynamic -lm -lpthread -lboost_system
        )   
else()
    target_link_libraries(${PROJECT_NAME}
        -lm -lpthread -lboost_system
        )
endif()

There is an similar question at What is the modern method for setting general compile flags in CMake? And that answer is a general solution.
But I need a more specific answer for this question.

Hill
  • 3,391
  • 3
  • 24
  • 28
  • 1
    Does this answer your question? [What is the modern method for setting general compile flags in CMake?](https://stackoverflow.com/questions/23995019/what-is-the-modern-method-for-setting-general-compile-flags-in-cmake) (using `target_link_options` instead of `target_compile_options`). – Alex Reinking Feb 28 '22 at 06:43
  • On the other hand, enabling `-rdynamic` only on certain configurations seems like asking for trouble. Why not just set [`ENABLE_EXPORTS`](https://cmake.org/cmake/help/latest/prop_tgt/ENABLE_EXPORTS.html) on your executable and be done with it? – Alex Reinking Feb 28 '22 at 06:45
  • Last comment: it is _never_ correct to inspect the value of `CMAKE_BUILD_TYPE`. You _must_ use generator expressions or your project won't work with multi-config generators. – Alex Reinking Feb 28 '22 at 06:45

0 Answers0