target.cmake 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # SPDX-License-Identifier: Apache-2.0
  2. # Configuration for host installed clang
  3. #
  4. set(NOSTDINC "")
  5. # Note that NOSYSDEF_CFLAG may be an empty string, and
  6. # set_ifndef() does not work with empty string.
  7. if(NOT DEFINED NOSYSDEF_CFLAG)
  8. set(NOSYSDEF_CFLAG -undef)
  9. endif()
  10. if(DEFINED TOOLCHAIN_HOME)
  11. set(find_program_clang_args PATHS ${TOOLCHAIN_HOME} NO_DEFAULT_PATH)
  12. endif()
  13. find_program(CMAKE_C_COMPILER clang ${find_program_clang_args})
  14. find_program(CMAKE_CXX_COMPILER clang++ ${find_program_clang_args})
  15. if(NOT "${ARCH}" STREQUAL "posix")
  16. include(${ZEPHYR_BASE}/cmake/gcc-m-cpu.cmake)
  17. if("${ARCH}" STREQUAL "arm")
  18. list(APPEND TOOLCHAIN_C_FLAGS
  19. -fshort-enums
  20. )
  21. list(APPEND TOOLCHAIN_LD_FLAGS
  22. -fshort-enums
  23. )
  24. include(${ZEPHYR_BASE}/cmake/compiler/gcc/target_arm.cmake)
  25. endif()
  26. foreach(file_name include/stddef.h)
  27. execute_process(
  28. COMMAND ${CMAKE_C_COMPILER} --print-file-name=${file_name}
  29. OUTPUT_VARIABLE _OUTPUT
  30. )
  31. get_filename_component(_OUTPUT "${_OUTPUT}" DIRECTORY)
  32. string(REGEX REPLACE "\n" "" _OUTPUT ${_OUTPUT})
  33. list(APPEND NOSTDINC ${_OUTPUT})
  34. endforeach()
  35. foreach(isystem_include_dir ${NOSTDINC})
  36. list(APPEND isystem_include_flags -isystem "\"${isystem_include_dir}\"")
  37. endforeach()
  38. if(CONFIG_X86)
  39. if(CONFIG_64BIT)
  40. string(APPEND TOOLCHAIN_C_FLAGS "-m64")
  41. else()
  42. string(APPEND TOOLCHAIN_C_FLAGS "-m32")
  43. endif()
  44. endif()
  45. # This libgcc code is partially duplicated in compiler/*/target.cmake
  46. execute_process(
  47. COMMAND ${CMAKE_C_COMPILER} ${TOOLCHAIN_C_FLAGS} --print-libgcc-file-name
  48. OUTPUT_VARIABLE LIBGCC_FILE_NAME
  49. OUTPUT_STRIP_TRAILING_WHITESPACE
  50. )
  51. get_filename_component(LIBGCC_DIR ${LIBGCC_FILE_NAME} DIRECTORY)
  52. list(APPEND LIB_INCLUDE_DIR "-L\"${LIBGCC_DIR}\"")
  53. if(LIBGCC_DIR)
  54. list(APPEND TOOLCHAIN_LIBS gcc)
  55. endif()
  56. list(APPEND CMAKE_REQUIRED_FLAGS -nostartfiles -nostdlib ${isystem_include_flags})
  57. string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
  58. endif()
  59. # Load toolchain_cc-family macros
  60. macro(toolchain_cc_nostdinc)
  61. if(NOT "${ARCH}" STREQUAL "posix")
  62. zephyr_compile_options( -nostdinc)
  63. endif()
  64. endmacro()