Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Modules / Compiler / IntelLLVM.cmake
1 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
3
4
5 # This module is shared by multiple languages; use include blocker.
6 if(__COMPILER_LLVM_INTEL)
7   return()
8 endif()
9 set(__COMPILER_LLVM_INTEL 1)
10
11 include(Compiler/CMakeCommonCompilerMacros)
12
13 set(__pch_header_C "c-header")
14 set(__pch_header_CXX "c++-header")
15 set(__pch_header_OBJC "objective-c-header")
16 set(__pch_header_OBJCXX "objective-c++-header")
17
18 # Variables that are common across front-end variants
19 macro(__compiler_intel_llvm_common lang)
20   set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES)
21   set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
22   set(CMAKE_${lang}_ARCHIVE_CREATE_IPO "\"${CMAKE_${lang}_COMPILER_AR}\" cr <TARGET> <LINK_FLAGS> <OBJECTS>")
23   set(CMAKE_${lang}_ARCHIVE_APPEND_IPO "\"${CMAKE_${lang}_COMPILER_AR}\" r <TARGET> <LINK_FLAGS> <OBJECTS>")
24   set(CMAKE_${lang}_ARCHIVE_FINISH_IPO "\"${CMAKE_${lang}_COMPILER_RANLIB}\" <TARGET>")
25 endmacro()
26
27 if(CMAKE_HOST_WIN32)
28   # MSVC-like
29   macro(__compiler_intel_llvm lang)
30     if("x${lang}" STREQUAL "xFortran")
31       set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-warn:errors")
32     else()
33       set(CMAKE_${lang}_COMPILE_OPTIONS_INVALID_PCH -Winvalid-pch)
34       set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-WX")
35     endif()
36     __compiler_intel_llvm_common(${lang})
37     set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "-Qipo")
38     set(CMAKE_${lang}_LINK_OPTIONS_IPO "-Qipo")
39   endmacro()
40 else()
41   # GNU-like
42   macro(__compiler_intel_llvm lang)
43     set(CMAKE_${lang}_VERBOSE_FLAG "-v")
44
45     string(APPEND CMAKE_${lang}_FLAGS_INIT " ")
46     string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g")
47     string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Os")
48     string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3")
49     string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g")
50
51     set(_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER YES)
52     set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
53     set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
54     set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_${lang}_COMPILE_OPTIONS_PIE} "-pie")
55     set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "-no-pie")
56
57     set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
58     set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
59
60     set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
61     set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",")
62
63     # distcc does not transform -o to -MT when invoking the preprocessor
64     # internally, as it ought to.  Work around this bug by setting -MT here
65     # even though it isn't strictly necessary.
66     set(CMAKE_DEPFILE_FLAGS_${lang} "-MD -MT <DEP_TARGET> -MF <DEP_FILE>")
67
68     set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
69     set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
70     set(CMAKE_${lang}_COMPILE_OPTIONS_TARGET "--target=")
71     set(CMAKE_${lang}_COMPILE_OPTIONS_SYSROOT "--sysroot=")
72     set(CMAKE_${lang}_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN "--gcc-toolchain=")
73     set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Xlinker" " ")
74     set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP)
75
76     __compiler_intel_llvm_common(${lang})
77     set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "-ipo")
78     set(CMAKE_${lang}_LINK_OPTIONS_IPO "-ipo")
79
80     set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
81     set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
82
83     set(CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "${CMAKE_${lang}_COMPILER}")
84     if(CMAKE_${lang}_COMPILER_ARG1)
85       separate_arguments(_COMPILER_ARGS NATIVE_COMMAND "${CMAKE_${lang}_COMPILER_ARG1}")
86       list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND ${_COMPILER_ARGS})
87       unset(_COMPILER_ARGS)
88     endif()
89     list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "-dM" "-E" "-c" "${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp")
90     if(CMAKE_${lang}_COMPILER_TARGET)
91       list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "--target=${CMAKE_${lang}_COMPILER_TARGET}")
92     endif()
93
94     if("x${lang}" STREQUAL "xFortran")
95       set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-warn" "errors")
96     else()
97       # Precompile Headers
98       set(CMAKE_PCH_EXTENSION .pch)
99       set(CMAKE_PCH_PROLOGUE "#pragma clang system_header")
100       set(CMAKE_${lang}_COMPILE_OPTIONS_INSTANTIATE_TEMPLATES_PCH -fpch-instantiate-templates)
101       set(CMAKE_${lang}_COMPILE_OPTIONS_INVALID_PCH -Winvalid-pch)
102       set(CMAKE_${lang}_COMPILE_OPTIONS_USE_PCH -Xclang -include-pch -Xclang <PCH_FILE> -Xclang -include -Xclang <PCH_HEADER>)
103       set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -Xclang -emit-pch -Xclang -include -Xclang <PCH_HEADER> -x ${__pch_header_${lang}})
104
105       # COMPILE_WARNING_AS_ERROR
106       set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-Werror")
107     endif()
108   endmacro()
109 endif()