123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
- # file Copyright.txt or https://cmake.org/licensing for details.
- # This module is shared by multiple languages; use include blocker.
- if(__COMPILER_CLANG)
- return()
- endif()
- set(__COMPILER_CLANG 1)
- include(Compiler/CMakeCommonCompilerMacros)
- if("x${CMAKE_C_SIMULATE_ID}" STREQUAL "xMSVC"
- OR "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC"
- OR "x${CMAKE_Fortran_SIMULATE_ID}" STREQUAL "xMSVC")
- macro(__compiler_clang lang)
- endmacro()
- else()
- include(Compiler/GNU)
- macro(__compiler_clang lang)
- __compiler_gnu(${lang})
- set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
- # Link options for PIE are already set in 'Compiler/GNU.cmake'
- # but clang may require alternate syntax on some platforms
- if (APPLE)
- set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_${lang}_COMPILE_OPTIONS_PIE} -Xlinker -pie)
- set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE -Xlinker -no_pie)
- endif()
- set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
- set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
- if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4.0)
- set(CMAKE_${lang}_COMPILE_OPTIONS_TARGET "-target ")
- set(CMAKE_${lang}_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN "-gcc-toolchain ")
- else()
- set(CMAKE_${lang}_COMPILE_OPTIONS_TARGET "--target=")
- set(CMAKE_${lang}_COMPILE_OPTIONS_EXTERNAL_TOOLCHAIN "--gcc-toolchain=")
- endif()
- set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Xlinker" " ")
- set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP)
- if(CMAKE_${lang}_COMPILER_TARGET)
- if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4.0)
- list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "-target" "${CMAKE_${lang}_COMPILER_TARGET}")
- else()
- list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "--target=${CMAKE_${lang}_COMPILER_TARGET}")
- endif()
- endif()
- set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES)
- set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
- string(COMPARE EQUAL "${CMAKE_${lang}_COMPILER_ID}" "AppleClang" __is_apple_clang)
- # '-flto=thin' available since Clang 3.9 and Xcode 8
- # * http://clang.llvm.org/docs/ThinLTO.html#clang-llvm
- # * https://trac.macports.org/wiki/XcodeVersionInfo
- set(_CMAKE_LTO_THIN TRUE)
- if(__is_apple_clang)
- if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 8.0)
- set(_CMAKE_LTO_THIN FALSE)
- endif()
- else()
- if(CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.9)
- set(_CMAKE_LTO_THIN FALSE)
- endif()
- endif()
- if(_CMAKE_LTO_THIN)
- set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "-flto=thin")
- else()
- set(CMAKE_${lang}_COMPILE_OPTIONS_IPO "-flto")
- endif()
- if(ANDROID)
- # https://github.com/android-ndk/ndk/issues/242
- set(CMAKE_${lang}_LINK_OPTIONS_IPO "-fuse-ld=gold")
- endif()
- if(ANDROID OR __is_apple_clang)
- set(__ar "${CMAKE_AR}")
- set(__ranlib "${CMAKE_RANLIB}")
- else()
- set(__ar "${CMAKE_${lang}_COMPILER_AR}")
- set(__ranlib "${CMAKE_${lang}_COMPILER_RANLIB}")
- endif()
- set(CMAKE_${lang}_ARCHIVE_CREATE_IPO
- "\"${__ar}\" cr <TARGET> <LINK_FLAGS> <OBJECTS>"
- )
- set(CMAKE_${lang}_ARCHIVE_APPEND_IPO
- "\"${__ar}\" r <TARGET> <LINK_FLAGS> <OBJECTS>"
- )
- set(CMAKE_${lang}_ARCHIVE_FINISH_IPO
- "\"${__ranlib}\" <TARGET>"
- )
- set(CMAKE_PCH_EXTENSION .pch)
- if (NOT CMAKE_GENERATOR MATCHES "Xcode")
- set(CMAKE_PCH_PROLOGUE "#pragma clang system_header")
- endif()
- set(CMAKE_${lang}_COMPILE_OPTIONS_USE_PCH -Xclang -include-pch -Xclang <PCH_FILE>)
- set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -Xclang -emit-pch -Xclang -include -Xclang <PCH_HEADER>)
- endmacro()
- endif()
|