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.3 KiB

  1. cmake_minimum_required(VERSION 3.0)
  2. set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
  3. if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
  4. set(RAYLIB_IS_MAIN TRUE)
  5. else()
  6. set(RAYLIB_IS_MAIN FALSE)
  7. endif()
  8. # Config options
  9. option(BUILD_EXAMPLES "Build the examples." ${RAYLIB_IS_MAIN})
  10. option(ENABLE_ASAN "Enable AddressSanitizer (ASAN) for debugging (degrades performance)" OFF)
  11. option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer (UBSan) for debugging" OFF)
  12. option(ENABLE_MSAN "Enable MemorySanitizer (MSan) for debugging (not recommended to run with ASAN)" OFF)
  13. # This helps support the case where emsdk toolchain file is used
  14. # either by setting it with -DCMAKE_TOOLCHAIN_FILE=<path_to_emsdk>/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake
  15. # or by using "emcmake cmake -B build -S ." as described in https://emscripten.org/docs/compiling/Building-Projects.html
  16. if(EMSCRIPTEN)
  17. SET(PLATFORM Web CACHE STRING "Forcing PLATFORM_WEB because EMSCRIPTEN was detected")
  18. endif()
  19. if(CMAKE_VERSION VERSION_LESS "3.1")
  20. if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
  21. set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")
  22. endif()
  23. else()
  24. set (CMAKE_C_STANDARD 99)
  25. endif()
  26. include(AddIfFlagCompiles)
  27. add_if_flag_compiles(-Werror=pointer-arith CMAKE_C_FLAGS)
  28. add_if_flag_compiles(-Werror=implicit-function-declaration CMAKE_C_FLAGS)
  29. # src/external/jar_xm.h does shady stuff
  30. add_if_flag_compiles(-fno-strict-aliasing CMAKE_C_FLAGS)
  31. if (ENABLE_ASAN)
  32. add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  33. add_if_flag_compiles(-fsanitize=address CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  34. endif()
  35. if (ENABLE_UBSAN)
  36. add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  37. add_if_flag_compiles(-fsanitize=undefined CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  38. endif()
  39. if (ENABLE_MSAN)
  40. add_if_flag_compiles(-fno-omit-frame-pointer CMAKE_C_FLAGS CMAKE_LINKER_FLAGS)
  41. add_if_flag_compiles(-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)
  47. if (${BUILD_EXAMPLES})
  48. MESSAGE(STATUS "Building examples is enabled")
  49. add_subdirectory(examples)
  50. endif()
  51. enable_testing()