CMakeLists.txt 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. cmake_minimum_required(VERSION 3.5)
  2. project(esp-idf C CXX ASM)
  3. unset(compile_options)
  4. unset(c_compile_options)
  5. unset(cxx_compile_options)
  6. unset(compile_definitions)
  7. unset(link_options)
  8. # Add the following build specifications here, since these seem to be dependent
  9. # on config values on the root Kconfig.
  10. if(CONFIG_COMPILER_OPTIMIZATION_LEVEL_RELEASE)
  11. list(APPEND compile_options "-Os")
  12. list(APPEND compile_options "-freorder-blocks")
  13. else()
  14. list(APPEND compile_options "-Og")
  15. endif()
  16. if(CONFIG_COMPILER_CXX_EXCEPTIONS)
  17. list(APPEND cxx_compile_options "-fexceptions")
  18. else()
  19. list(APPEND cxx_compile_options "-fno-exceptions")
  20. endif()
  21. if(CONFIG_COMPILER_CXX_RTTI)
  22. list(APPEND cxx_compile_options "-frtti")
  23. else()
  24. list(APPEND cxx_compile_options "-fno-rtti")
  25. list(APPEND link_options "-fno-rtti") # used to invoke correct multilib variant (no-rtti) during linking
  26. endif()
  27. if(CONFIG_COMPILER_DISABLE_GCC8_WARNINGS)
  28. list(APPEND compile_options "-Wno-parentheses"
  29. "-Wno-sizeof-pointer-memaccess"
  30. "-Wno-clobbered")
  31. # doesn't use GCC_NOT_5_2_0 because idf_set_global_variables was not called before
  32. if(GCC_NOT_5_2_0)
  33. list(APPEND compile_options "-Wno-format-overflow"
  34. "-Wno-stringop-truncation"
  35. "-Wno-misleading-indentation"
  36. "-Wno-cast-function-type"
  37. "-Wno-implicit-fallthrough"
  38. "-Wno-unused-const-variable"
  39. "-Wno-switch-unreachable"
  40. "-Wno-format-truncation"
  41. "-Wno-memset-elt-size"
  42. "-Wno-int-in-bool-context")
  43. endif()
  44. endif()
  45. if(CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE)
  46. list(APPEND compile_definitions "-DNDEBUG")
  47. endif()
  48. if(CONFIG_COMPILER_STACK_CHECK_MODE_NORM)
  49. list(APPEND compile_options "-fstack-protector")
  50. elseif(CONFIG_COMPILER_STACK_CHECK_MODE_STRONG)
  51. list(APPEND compile_options "-fstack-protector-strong")
  52. elseif(CONFIG_COMPILER_STACK_CHECK_MODE_ALL)
  53. list(APPEND compile_options "-fstack-protector-all")
  54. endif()
  55. list(APPEND link_options "-fno-lto")
  56. idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND)
  57. idf_build_set_property(C_COMPILE_OPTIONS "${c_compile_options}" APPEND)
  58. idf_build_set_property(CXX_COMPILE_OPTIONS "${cxx_compile_options}" APPEND)
  59. idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND)
  60. idf_build_set_property(LINK_OPTIONS "${link_options}" APPEND)
  61. idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS)
  62. # Add each component as a subdirectory, processing each component's CMakeLists.txt
  63. foreach(component_target ${build_component_targets})
  64. __component_get_property(dir ${component_target} COMPONENT_DIR)
  65. __component_get_property(_name ${component_target} COMPONENT_NAME)
  66. __component_get_property(prefix ${component_target} __PREFIX)
  67. __component_get_property(alias ${component_target} COMPONENT_ALIAS)
  68. set(COMPONENT_NAME ${_name})
  69. set(COMPONENT_DIR ${dir})
  70. set(COMPONENT_ALIAS ${alias})
  71. set(COMPONENT_PATH ${dir}) # for backward compatibility only, COMPONENT_DIR is preferred
  72. idf_build_get_property(build_prefix __PREFIX)
  73. set(__idf_component_context 1)
  74. if(NOT prefix STREQUAL build_prefix)
  75. add_subdirectory(${dir} ${prefix}_${_name})
  76. else()
  77. add_subdirectory(${dir} ${_name})
  78. endif()
  79. set(__idf_component_context 0)
  80. endforeach()