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#[=======================================================================[.rst:
5CMakeForceCompiler
6------------------
7
8.. deprecated:: 3.6
9
10  Do not use.
11
12The macros provided by this module were once intended for use by
13cross-compiling toolchain files when CMake was not able to automatically
14detect the compiler identification.  Since the introduction of this module,
15CMake's compiler identification capabilities have improved and can now be
16taught to recognize any compiler.  Furthermore, the suite of information
17CMake detects from a compiler is now too extensive to be provided by
18toolchain files using these macros.
19
20One common use case for this module was to skip CMake's checks for a
21working compiler when using a cross-compiler that cannot link binaries
22without special flags or custom linker scripts.  This case is now supported
23by setting the :variable:`CMAKE_TRY_COMPILE_TARGET_TYPE` variable in the
24toolchain file instead.
25
26-------------------------------------------------------------------------
27
28Macro ``CMAKE_FORCE_C_COMPILER`` has the following signature:
29
30::
31
32   CMAKE_FORCE_C_COMPILER(<compiler> <compiler-id>)
33
34It sets :variable:`CMAKE_C_COMPILER <CMAKE_<LANG>_COMPILER>` to
35the given compiler and the cmake internal variable
36:variable:`CMAKE_C_COMPILER_ID <CMAKE_<LANG>_COMPILER_ID>` to the given
37compiler-id.  It also bypasses the check for working compiler and basic
38compiler information tests.
39
40Macro ``CMAKE_FORCE_CXX_COMPILER`` has the following signature:
41
42::
43
44   CMAKE_FORCE_CXX_COMPILER(<compiler> <compiler-id>)
45
46It sets :variable:`CMAKE_CXX_COMPILER <CMAKE_<LANG>_COMPILER>` to
47the given compiler and the cmake internal variable
48:variable:`CMAKE_CXX_COMPILER_ID <CMAKE_<LANG>_COMPILER_ID>` to the given
49compiler-id.  It also bypasses the check for working compiler and basic
50compiler information tests.
51
52Macro ``CMAKE_FORCE_Fortran_COMPILER`` has the following signature:
53
54::
55
56   CMAKE_FORCE_Fortran_COMPILER(<compiler> <compiler-id>)
57
58It sets :variable:`CMAKE_Fortran_COMPILER <CMAKE_<LANG>_COMPILER>` to
59the given compiler and the cmake internal variable
60:variable:`CMAKE_Fortran_COMPILER_ID <CMAKE_<LANG>_COMPILER_ID>` to the given
61compiler-id.  It also bypasses the check for working compiler and basic
62compiler information tests.
63
64So a simple toolchain file could look like this:
65
66::
67
68   include (CMakeForceCompiler)
69   set(CMAKE_SYSTEM_NAME Generic)
70   CMAKE_FORCE_C_COMPILER   (chc12 MetrowerksHicross)
71   CMAKE_FORCE_CXX_COMPILER (chc12 MetrowerksHicross)
72#]=======================================================================]
73
74macro(CMAKE_FORCE_C_COMPILER compiler id)
75  message(DEPRECATION "The CMAKE_FORCE_C_COMPILER macro is deprecated.  "
76    "Instead just set CMAKE_C_COMPILER and allow CMake to identify the compiler.")
77  set(CMAKE_C_COMPILER "${compiler}")
78  set(CMAKE_C_COMPILER_ID_RUN TRUE)
79  set(CMAKE_C_COMPILER_ID ${id})
80  set(CMAKE_C_COMPILER_FORCED TRUE)
81
82  # Set old compiler id variables.
83  if(CMAKE_C_COMPILER_ID MATCHES "GNU")
84    set(CMAKE_COMPILER_IS_GNUCC 1)
85  endif()
86endmacro()
87
88macro(CMAKE_FORCE_CXX_COMPILER compiler id)
89  message(DEPRECATION "The CMAKE_FORCE_CXX_COMPILER macro is deprecated.  "
90    "Instead just set CMAKE_CXX_COMPILER and allow CMake to identify the compiler.")
91  set(CMAKE_CXX_COMPILER "${compiler}")
92  set(CMAKE_CXX_COMPILER_ID_RUN TRUE)
93  set(CMAKE_CXX_COMPILER_ID ${id})
94  set(CMAKE_CXX_COMPILER_FORCED TRUE)
95
96  # Set old compiler id variables.
97  if("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
98    set(CMAKE_COMPILER_IS_GNUCXX 1)
99  endif()
100endmacro()
101
102macro(CMAKE_FORCE_Fortran_COMPILER compiler id)
103  message(DEPRECATION "The CMAKE_FORCE_Fortran_COMPILER macro is deprecated.  "
104    "Instead just set CMAKE_Fortran_COMPILER and allow CMake to identify the compiler.")
105  set(CMAKE_Fortran_COMPILER "${compiler}")
106  set(CMAKE_Fortran_COMPILER_ID_RUN TRUE)
107  set(CMAKE_Fortran_COMPILER_ID ${id})
108  set(CMAKE_Fortran_COMPILER_FORCED TRUE)
109
110  # Set old compiler id variables.
111  if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
112    set(CMAKE_COMPILER_IS_GNUG77 1)
113  endif()
114endmacro()
115