diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c9eb627fff..a6028d20d02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -230,9 +230,17 @@ zephyr_compile_options(${CONFIG_COMPILER_OPT_AS_LIST}) # TODO: Include arch compiler options at this point. -# TODO: This Clang check is broken if(CMAKE_C_COMPILER_ID STREQUAL "Clang") zephyr_cc_option( + #FIXME: need to fix all of those + -Wno-sometimes-uninitialized + -Wno-shift-overflow + -Wno-missing-braces + -Wno-self-assign + -Wno-address-of-packed-member + -Wno-unused-function + -Wno-initializer-overrides + -Wno-section -Wno-unknown-warning-option -Wno-unused-variable -Wno-format-invalid-specifier diff --git a/arch/x86/core/CMakeLists.txt b/arch/x86/core/CMakeLists.txt index 2b9e6ce72a1..ed0cd5ce96a 100644 --- a/arch/x86/core/CMakeLists.txt +++ b/arch/x86/core/CMakeLists.txt @@ -1,12 +1,12 @@ zephyr_library() -if (COMPILER STREQUAL "clang") +if (CMAKE_LANG_COMPILER_ID STREQUAL "Clang") # We rely on GAS for assembling, so don't use the integrated assembler zephyr_compile_options_ifndef(CONFIG_X86_IAMCU $<$:-no-integrated-as>) +elseif(CMAKE_LANG_COMPILER_ID STREQUAL "GNU") + zephyr_compile_options($<$:-Wa,--divide>) endif() -zephyr_compile_options($<$:-Wa,--divide>) - zephyr_library_sources( cache.c cache_s.S diff --git a/cmake/compiler/llvm.cmake b/cmake/compiler/llvm.cmake new file mode 100644 index 00000000000..5548353f9bc --- /dev/null +++ b/cmake/compiler/llvm.cmake @@ -0,0 +1,22 @@ +# Configuration for host installed llvm +# + +set(NOSTDINC "") + +foreach(file_name include include-fixed) + execute_process( + COMMAND ${CMAKE_C_COMPILER} --print-file-name=${file_name} + OUTPUT_VARIABLE _OUTPUT + ) + string(REGEX REPLACE "\n" "" _OUTPUT ${_OUTPUT}) + + list(APPEND NOSTDINC ${_OUTPUT}) +endforeach() + +foreach(isystem_include_dir ${NOSTDINC}) + list(APPEND isystem_include_flags -isystem ${isystem_include_dir}) +endforeach() + +set(CMAKE_REQUIRED_FLAGS -nostartfiles -nostdlib ${isystem_include_flags} -Wl,--unresolved-symbols=ignore-in-object-files) +string(REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") + diff --git a/cmake/toolchain/clang.cmake b/cmake/toolchain/clang.cmake new file mode 100644 index 00000000000..740b547cb83 --- /dev/null +++ b/cmake/toolchain/clang.cmake @@ -0,0 +1,24 @@ +set(CLANG_ROOT $ENV{CLANG_ROOT_DIR}) +set_ifndef(CLANG_ROOT /usr) +set(COMPILER clang) + +if(CONFIG_ARM) +set(triple arm-none-eabi) +set(CMAKE_EXE_LINKER_FLAGS_INIT "--specs=nosys.specs") +elseif(CONFIG_X86) +set(triple i686-pc-none-elf) +endif() + +set(CMAKE_C_COMPILER ${CLANG_ROOT}/bin/clang) +set(CMAKE_C_COMPILER_TARGET ${triple}) +set(CMAKE_ASM_COMPILER_TARGET ${triple}) +set(CMAKE_CXX_COMPILER ${CLANG_ROOT}/bin/clang++) +set(CMAKE_CXX_COMPILER_TARGET ${triple}) +set(CMAKE_AR "${CLANG_ROOT}/bin/llvm-ar" CACHE INTERNAL " " FORCE) +set(CMAKE_LINKER "${CLANG_ROOT}/bin/llvm-link" CACHE INTERNAL " " FORCE) +SET(CMAKE_NM "${CLANG_ROOT}/bin/llvm-nm" CACHE INTERNAL " " FORCE) +SET(CMAKE_OBJDUMP "${CLANG_ROOT}/bin/llvm-objdump" CACHE INTERNAL " " FORCE) +SET(CMAKE_RANLIB "${CLANG_ROOT}/bin/llvm-ranlib" CACHE INTERNAL " " FORCE) +set(CMAKE_OBJCOPY objcopy CACHE INTERNAL " " FORCE) +set(CMAKE_READELF readelf CACHE INTERNAL " " FORCE) +