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.

54 lines
1.8 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(BUILD_GAMES "Build the example games." ON)
  6. option(ENABLE_ASAN "Enable AddressSanitizer (ASAN) for debugging (degrades performance)" OFF)
  7. option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan) for debugging" OFF)
  8. option(ENABLE_MSAN "Enable MemorySanitizer (MSan) for debugging (not recommended to run with ASAN)" OFF)
  9. if(CMAKE_VERSION VERSION_LESS "3.1")
  10. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  11. set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")
  12. endif()
  13. else()
  14. set (CMAKE_C_STANDARD 99)
  15. endif()
  16. include(AddIfFlagCompiles)
  17. add_if_flag_compiles(-Werror=pointer-arith CMAKE_C_FLAGS)
  18. add_if_flag_compiles(-Werror=implicit-function-declaration CMAKE_C_FLAGS)
  19. # src/external/jar_xm.h does shady stuff
  20. add_if_flag_compiles(-fno-strict-aliasing CMAKE_C_FLAGS)
  21. include(CheckFileSystemSymlinkSupport)
  22. if (ENABLE_ASAN)
  23. add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  24. add_if_flag_compiles(-fsanitize=address CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  25. endif()
  26. if (ENABLE_UBSAN)
  27. add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  28. add_if_flag_compiles(-fsanitize=undefined CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  29. endif()
  30. if (ENABLE_MSAN)
  31. add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  32. add_if_flag_compiles(-fsanitize=memory CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  33. endif()
  34. if (ENABLE_MSAN AND ENABLE_ASAN)
  35. MESSAGE(WARNING "Compiling with both AddressSanitizer and MemorySanitizer is not recommended")
  36. endif()
  37. add_subdirectory(src release)
  38. if (${BUILD_EXAMPLES})
  39. add_subdirectory(examples)
  40. endif()
  41. if (${BUILD_GAMES})
  42. add_subdirectory(games)
  43. endif()
  44. enable_testing()