CMakeLists.txt 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. cmake_minimum_required(VERSION 3.5)
  2. project(esp-idf C CXX ASM)
  3. if(CMAKE_CURRENT_LIST_DIR STREQUAL CMAKE_SOURCE_DIR)
  4. message(FATAL_ERROR "Current directory '${CMAKE_CURRENT_LIST_DIR}' is not buildable. "
  5. "Change directories to one of the example projects in '${CMAKE_CURRENT_LIST_DIR}/examples' and try "
  6. "again.")
  7. endif()
  8. unset(compile_options)
  9. unset(c_compile_options)
  10. unset(cxx_compile_options)
  11. unset(compile_definitions)
  12. unset(link_options)
  13. # Add the following build specifications here, since these seem to be dependent
  14. # on config values on the root Kconfig.
  15. if(NOT BOOTLOADER_BUILD)
  16. if(CONFIG_COMPILER_OPTIMIZATION_SIZE)
  17. list(APPEND compile_options "-Os")
  18. list(APPEND compile_options "-freorder-blocks")
  19. elseif(CONFIG_COMPILER_OPTIMIZATION_DEFAULT)
  20. list(APPEND compile_options "-Og")
  21. elseif(CONFIG_COMPILER_OPTIMIZATION_NONE)
  22. list(APPEND compile_options "-O0")
  23. elseif(CONFIG_COMPILER_OPTIMIZATION_PERF)
  24. list(APPEND compile_options "-O2")
  25. endif()
  26. else() # BOOTLOADER_BUILD
  27. if(CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE)
  28. list(APPEND compile_options "-Os")
  29. list(APPEND compile_options "-freorder-blocks")
  30. elseif(CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG)
  31. list(APPEND compile_options "-Og")
  32. elseif(CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_NONE)
  33. list(APPEND compile_options "-O0")
  34. elseif(CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF)
  35. list(APPEND compile_options "-O2")
  36. endif()
  37. endif()
  38. if(CONFIG_COMPILER_CXX_EXCEPTIONS)
  39. list(APPEND cxx_compile_options "-fexceptions")
  40. else()
  41. list(APPEND cxx_compile_options "-fno-exceptions")
  42. endif()
  43. if(CONFIG_COMPILER_CXX_RTTI)
  44. list(APPEND cxx_compile_options "-frtti")
  45. else()
  46. list(APPEND cxx_compile_options "-fno-rtti")
  47. list(APPEND link_options "-fno-rtti") # used to invoke correct multilib variant (no-rtti) during linking
  48. endif()
  49. if(CONFIG_COMPILER_DISABLE_GCC8_WARNINGS)
  50. list(APPEND compile_options "-Wno-parentheses"
  51. "-Wno-sizeof-pointer-memaccess"
  52. "-Wno-clobbered")
  53. list(APPEND compile_options "-Wno-format-overflow"
  54. "-Wno-stringop-truncation"
  55. "-Wno-misleading-indentation"
  56. "-Wno-cast-function-type"
  57. "-Wno-implicit-fallthrough"
  58. "-Wno-unused-const-variable"
  59. "-Wno-switch-unreachable"
  60. "-Wno-format-truncation"
  61. "-Wno-memset-elt-size"
  62. "-Wno-int-in-bool-context")
  63. endif()
  64. if(CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE)
  65. list(APPEND compile_definitions "-DNDEBUG")
  66. endif()
  67. if(CONFIG_COMPILER_STACK_CHECK_MODE_NORM)
  68. list(APPEND compile_options "-fstack-protector")
  69. elseif(CONFIG_COMPILER_STACK_CHECK_MODE_STRONG)
  70. list(APPEND compile_options "-fstack-protector-strong")
  71. elseif(CONFIG_COMPILER_STACK_CHECK_MODE_ALL)
  72. list(APPEND compile_options "-fstack-protector-all")
  73. endif()
  74. list(APPEND link_options "-fno-lto")
  75. idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND)
  76. idf_build_set_property(C_COMPILE_OPTIONS "${c_compile_options}" APPEND)
  77. idf_build_set_property(CXX_COMPILE_OPTIONS "${cxx_compile_options}" APPEND)
  78. idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND)
  79. idf_build_set_property(LINK_OPTIONS "${link_options}" APPEND)
  80. idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS)
  81. # Add each component as a subdirectory, processing each component's CMakeLists.txt
  82. foreach(component_target ${build_component_targets})
  83. __component_get_property(dir ${component_target} COMPONENT_DIR)
  84. __component_get_property(_name ${component_target} COMPONENT_NAME)
  85. __component_get_property(prefix ${component_target} __PREFIX)
  86. __component_get_property(alias ${component_target} COMPONENT_ALIAS)
  87. set(COMPONENT_NAME ${_name})
  88. set(COMPONENT_DIR ${dir})
  89. set(COMPONENT_ALIAS ${alias})
  90. set(COMPONENT_PATH ${dir}) # for backward compatibility only, COMPONENT_DIR is preferred
  91. idf_build_get_property(build_prefix __PREFIX)
  92. set(__idf_component_context 1)
  93. if(NOT prefix STREQUAL build_prefix)
  94. add_subdirectory(${dir} ${prefix}_${_name})
  95. else()
  96. add_subdirectory(${dir} ${_name})
  97. endif()
  98. set(__idf_component_context 0)
  99. endforeach()