You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.6 KiB

  1. cmake_minimum_required(VERSION 3.0)
  2. set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
  3. # Config options
  4. option(BUILD_EXAMPLES "Build the examples." ON)
  5. option(ENABLE_ASAN "Enable AddressSanitizer (ASAN) for debugging (degrades performance)" OFF)
  6. option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan) for debugging" OFF)
  7. option(ENABLE_MSAN "Enable MemorySanitizer (MSan) for debugging (not recommended to run with ASAN)" OFF)
  8. if(CMAKE_VERSION VERSION_LESS "3.1")
  9. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  10. set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")
  11. endif()
  12. else()
  13. set (CMAKE_C_STANDARD 99)
  14. endif()
  15. include(AddIfFlagCompiles)
  16. add_if_flag_compiles(-Werror=pointer-arith CMAKE_C_FLAGS)
  17. add_if_flag_compiles(-Werror=implicit-function-declaration CMAKE_C_FLAGS)
  18. # src/external/jar_xm.h does shady stuff
  19. add_if_flag_compiles(-fno-strict-aliasing CMAKE_C_FLAGS)
  20. if (ENABLE_ASAN)
  21. add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  22. add_if_flag_compiles(-fsanitize=address CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  23. endif()
  24. if (ENABLE_UBSAN)
  25. add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  26. add_if_flag_compiles(-fsanitize=undefined CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  27. endif()
  28. if (ENABLE_MSAN)
  29. add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  30. add_if_flag_compiles(-fsanitize=memory CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  31. endif()
  32. if (ENABLE_MSAN AND ENABLE_ASAN)
  33. MESSAGE(WARNING "Compiling with both AddressSanitizer and MemorySanitizer is not recommended")
  34. endif()
  35. add_subdirectory(src)
  36. if (${BUILD_EXAMPLES})
  37. add_subdirectory(examples)
  38. endif()
  39. enable_testing()