CMakeLists.txt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. cmake_minimum_required(VERSION 3.5)
  2. include(CheckCSourceCompiles)
  3. include(CheckFunctionExists)
  4. include(CheckCCompilerFlag)
  5. include(CheckIncludeFiles)
  6. include(CheckSymbolExists)
  7. set(CMAKE_C_STANDARD 11)
  8. set(CMAKE_C_STANDARD_REQUIRED ON)
  9. add_definitions("-Wall -Werror -Wextra -Wno-unused-parameter -D_GNU_SOURCE")
  10. macro(c_attribute_required attrname code)
  11. if (NOT DEFINED ATTRIBUTE_${attrname}_SUPPORT OR
  12. NOT ATTRIBUTE_${attrname}_SUPPORT)
  13. message(STATUS "Checking if compiler supports __attribute__((${attrname}))")
  14. check_c_source_compiles("${code}" ATTRIBUTE_${attrname}_SUPPORT)
  15. if (NOT ATTRIBUTE_${attrname}_SUPPORT)
  16. message(FATAL_ERROR "Compiler must support __attribute__((${attrname}))")
  17. endif()
  18. endif()
  19. endmacro()
  20. macro(c_function_required f)
  21. if (NOT DEFINED FUNCTION_${f}_SUPPORT)
  22. check_function_exists("${f}" FUNCTION_${f}_SUPPORT)
  23. if (NOT FUNCTION_${f}_SUPPORT)
  24. message(FATAL_ERROR "libc must support ${f}")
  25. endif()
  26. endif()
  27. endmacro()
  28. c_attribute_required(packed "struct s { int a; } __attribute__((packed)); main;")
  29. c_attribute_required(constructor "void __attribute__((constructor)) f(){}main;")
  30. c_attribute_required(format
  31. "void __attribute__((format (printf, 1, 2))) f(const char *, ...);main;")
  32. c_function_required(asprintf)
  33. check_c_compiler_flag("-mfp16-format=alternative" MFP16_FLAG_SUPPORT)
  34. if (MFP16_FLAG_SUPPORT)
  35. add_definitions("-mfp16-format=alternative")
  36. else()
  37. # Check to make sure we can still use __fp16 with the compiler
  38. check_c_source_compiles("__fp16 f; main;" MFP16_BUILTIN_SUPPORT)
  39. if (NOT MFP16_BUILTIN_SUPPORT)
  40. message(FATAL_ERROR "Compiler doesn't support __fp16 type")
  41. endif()
  42. endif()
  43. # Optional checks
  44. check_symbol_exists(PAGE_SIZE "sys/user.h" HAVE_USER_H)
  45. if (HAVE_USER_H)
  46. add_definitions("-DHAVE_USER_H")
  47. endif()
  48. check_c_source_compiles("int main(){return __builtin_ffs(1);}" HAVE_BUILTIN_FFS)
  49. if (HAVE_BUILTIN_FFS)
  50. add_definitions("-DHAVE_BUILTIN_FFS")
  51. endif()
  52. # Configurable project options options
  53. option(PRECOMPILED_SHADER "whether to use precompiled shaders" 0)
  54. option(BUILD_SYNTHESISER "whether to build the synthesiser and prototype" 0)
  55. include_directories("include")
  56. add_subdirectory(panwrap)
  57. add_subdirectory(driver)
  58. add_subdirectory(decoder)
  59. add_subdirectory(replay)
  60. if (BUILD_SYNTHESISER)
  61. add_subdirectory(prototype)
  62. endif()
  63. # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab :