CompilerFlags.cmake 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Compiler flags for SmartBotic
  2. # Warning flags
  3. if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
  4. add_compile_options(
  5. -Wall
  6. -Wextra
  7. -Wpedantic
  8. -Wno-unused-parameter
  9. -Wno-missing-field-initializers
  10. )
  11. # Debug flags
  12. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  13. add_compile_options(-g -O0 -DDEBUG)
  14. # Note: _GLIBCXX_DEBUG is disabled because it causes ABI incompatibility
  15. # with pre-compiled system libraries (gRPC, etc.)
  16. # add_compile_definitions(_GLIBCXX_DEBUG)
  17. endif()
  18. # Release flags
  19. if(CMAKE_BUILD_TYPE STREQUAL "Release")
  20. add_compile_options(-O3 -DNDEBUG)
  21. add_compile_options(-flto)
  22. add_link_options(-flto)
  23. endif()
  24. # RelWithDebInfo flags
  25. if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
  26. add_compile_options(-O2 -g -DNDEBUG)
  27. endif()
  28. endif()
  29. # MSVC flags (for potential Windows support)
  30. if(MSVC)
  31. add_compile_options(/W4 /permissive-)
  32. add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
  33. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  34. add_compile_options(/Od /Zi)
  35. else()
  36. add_compile_options(/O2)
  37. endif()
  38. endif()
  39. # Enable colored output
  40. if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
  41. add_compile_options(-fdiagnostics-color=always)
  42. elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  43. add_compile_options(-fcolor-diagnostics)
  44. endif()
  45. # Position independent code
  46. set(CMAKE_POSITION_INDEPENDENT_CODE ON)