1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
5 # This module is shared by multiple languages; use include blocker.
11 include(Compiler/CMakeCommonCompilerMacros)
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")
18 macro(__compiler_lcc lang)
20 set(CMAKE_${lang}_VERBOSE_FLAG "-v")
21 set(CMAKE_${lang}_COMPILE_OPTIONS_WARNING_AS_ERROR "-Werror")
22 set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
23 set (_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER NO)
24 set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
25 # Support of PIE at link stage depends on various elements : platform, compiler, linker
26 # so to activate it, module CheckPIESupported must be used.
27 set (_CMAKE_${lang}_PIE_MAY_BE_SUPPORTED_BY_LINKER YES)
28 set(CMAKE_${lang}_LINK_OPTIONS_PIE ${CMAKE_${lang}_COMPILE_OPTIONS_PIE} "-pie")
29 set(CMAKE_${lang}_LINK_OPTIONS_NO_PIE "-no-pie")
30 set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
31 set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
32 set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
33 set(CMAKE_${lang}_COMPILE_OPTIONS_SYSROOT "--sysroot=")
35 set(CMAKE_${lang}_LINKER_WRAPPER_FLAG "-Wl,")
36 set(CMAKE_${lang}_LINKER_WRAPPER_FLAG_SEP ",")
38 # Older versions of gcc (< 4.5) contain a bug causing them to report a missing
39 # header file as a warning if depfiles are enabled, causing check_header_file
40 # tests to always succeed. Work around this by disabling dependency tracking
41 # in try_compile mode.
42 get_property(_IN_TC GLOBAL PROPERTY IN_TRY_COMPILE)
43 if(CMAKE_${lang}_COMPILER_ID STREQUAL "LCC" AND _IN_TC AND NOT CMAKE_FORCE_DEPFILES)
45 # distcc does not transform -o to -MT when invoking the preprocessor
46 # internally, as it ought to. Work around this bug by setting -MT here
47 # even though it isn't strictly necessary.
48 set(CMAKE_DEPFILE_FLAGS_${lang} "-MD -MT <DEP_TARGET> -MF <DEP_FILE>")
51 # Initial configuration flags.
52 string(APPEND CMAKE_${lang}_FLAGS_INIT " ")
53 string(APPEND CMAKE_${lang}_FLAGS_DEBUG_INIT " -g")
54 string(APPEND CMAKE_${lang}_FLAGS_MINSIZEREL_INIT " -Os -DNDEBUG")
55 string(APPEND CMAKE_${lang}_FLAGS_RELEASE_INIT " -O3 -DNDEBUG")
56 string(APPEND CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT " -O2 -g -DNDEBUG")
57 set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
58 set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
59 set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
60 set(_CMAKE_${lang}_IPO_SUPPORTED_BY_CMAKE YES)
61 set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER NO)
62 set(_CMAKE_${lang}_IPO_MAY_BE_SUPPORTED_BY_COMPILER YES)
63 set(__lto_flags -flto)
64 list(APPEND __lto_flags -fno-fat-lto-objects)
65 set(CMAKE_${lang}_COMPILE_OPTIONS_IPO ${__lto_flags})
67 set(CMAKE_${lang}_ARCHIVE_CREATE_IPO
68 "\"${CMAKE_${lang}_COMPILER_AR}\" cr <TARGET> <LINK_FLAGS> <OBJECTS>"
71 set(CMAKE_${lang}_ARCHIVE_APPEND_IPO
72 "\"${CMAKE_${lang}_COMPILER_AR}\" r <TARGET> <LINK_FLAGS> <OBJECTS>"
75 set(CMAKE_${lang}_ARCHIVE_FINISH_IPO
76 "\"${CMAKE_${lang}_COMPILER_RANLIB}\" <TARGET>"
79 set(CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "${CMAKE_${lang}_COMPILER}")
80 if(CMAKE_${lang}_COMPILER_ARG1)
81 separate_arguments(_COMPILER_ARGS NATIVE_COMMAND "${CMAKE_${lang}_COMPILER_ARG1}")
82 list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND ${_COMPILER_ARGS})
85 list(APPEND CMAKE_${lang}_COMPILER_PREDEFINES_COMMAND "-dM" "-E" "-c" "${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp")
87 if(NOT "x${lang}" STREQUAL "xFortran")
88 set(CMAKE_PCH_EXTENSION .gch)
89 if (NOT CMAKE_GENERATOR MATCHES "Xcode")
90 set(CMAKE_PCH_PROLOGUE "#pragma GCC system_header")
92 set(CMAKE_${lang}_COMPILE_OPTIONS_INVALID_PCH -Winvalid-pch)
93 set(CMAKE_${lang}_COMPILE_OPTIONS_USE_PCH -include <PCH_HEADER>)
94 set(CMAKE_${lang}_COMPILE_OPTIONS_CREATE_PCH -x ${__pch_header_${lang}} -include <PCH_HEADER>)