CMakeLists.txt 3.8 KB

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