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.

61 lines
2.0 KiB

  1. cmake_minimum_required(VERSION 3.0)
  2. # Config options
  3. option(BUILD_EXAMPLES "Build the examples." ON)
  4. option(BUILD_GAMES "Build the example games." 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 for 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(CheckCCompilerFlag)
  16. function(add_if_flag_works flag)
  17. CHECK_C_COMPILER_FLAG("${flag}" COMPILER_HAS_THOSE_TOGGLES)
  18. set(outcome "Failed")
  19. if(COMPILER_HAS_THOSE_TOGGLES)
  20. foreach(var ${ARGN})
  21. set(${var} "${flag} ${${var}}" PARENT_SCOPE)
  22. endforeach()
  23. set(outcome "works")
  24. endif()
  25. message(STATUS "Testing if ${flag} can be used -- ${outcome}")
  26. endfunction()
  27. add_if_flag_works(-Werror=pointer-arith CMAKE_C_FLAGS)
  28. add_if_flag_works(-Werror=implicit-function-declaration CMAKE_C_FLAGS)
  29. # src/external/jar_xm.h does shady stuff
  30. add_if_flag_works(-fno-strict-aliasing CMAKE_C_FLAGS)
  31. if (ENABLE_ASAN)
  32. add_if_flag_works(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  33. add_if_flag_works(-fsanitize=address CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  34. endif()
  35. if (ENABLE_UBSAN)
  36. add_if_flag_works(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  37. add_if_flag_works(-fsanitize=undefined CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  38. endif()
  39. if (ENABLE_MSAN)
  40. add_if_flag_works(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  41. add_if_flag_works(-fsanitize=memory CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  42. endif()
  43. if (ENABLE_MSAN AND ENABLE_ASAN)
  44. MESSAGE(WARNING "Compiling with both AddressSanitizer and MemorySanitizer is not recommended")
  45. endif()
  46. add_subdirectory(src release)
  47. if (${BUILD_EXAMPLES})
  48. add_subdirectory(examples)
  49. endif()
  50. if (${BUILD_GAMES})
  51. add_subdirectory(games)
  52. endif()