CMakeForceCompiler¶
Deprecated since version 3.6: Do not use.
The commands provided by this module were once intended for use by cross-compiling toolchain files when CMake was not able to automatically detect the compiler identification. Since the introduction of this module, CMake's compiler identification capabilities have improved and can now be taught to recognize any compiler. Furthermore, the suite of information CMake detects from a compiler is now too extensive to be provided by toolchain files using these macros.
One common use case for this module was to skip CMake's checks for a
working compiler when using a cross-compiler that cannot link binaries
without special flags or custom linker scripts. This case is now supported
by setting the CMAKE_TRY_COMPILE_TARGET_TYPE
variable in the
toolchain file instead.
Load this module in a CMake toolchain file:
include(CMakeForceCompiler)
Commands¶
This module provides the following commands:
- cmake_force_c_compiler¶
Sets the
CMAKE_C_COMPILER
variable to the given compiler and theCMAKE_C_COMPILER_ID
variable to the given compiler-id:cmake_force_c_compiler(<compiler> <compiler-id>)
This command also bypasses the check for working compiler and basic compiler information tests.
- cmake_force_cxx_compiler¶
Sets the
CMAKE_CXX_COMPILER
variable to the given compiler and theCMAKE_CXX_COMPILER_ID
variable to the given compiler-id:cmake_force_cxx_compiler(<compiler> <compiler-id>)
This command also bypasses the check for working compiler and basic compiler information tests.
- cmake_force_fortran_compiler¶
Sets the
CMAKE_Fortran_COMPILER
variable to the given compiler and theCMAKE_Fortran_COMPILER_ID
variable to the given compiler-id:cmake_force_fortran_compiler(<compiler> <compiler-id>)
This command also bypasses the check for working compiler and basic compiler information tests.
Examples¶
A simple toolchain file using this module could look like this:
cmake/toolchains/example-toolchain.cmake
¶include(CMakeForceCompiler)
set(CMAKE_SYSTEM_NAME Generic)
cmake_force_c_compiler(chc12 MetrowerksHicross)
cmake_force_cxx_compiler(chc12 MetrowerksHicross)
In new CMake code, compiler is detected automatically when setting required variables instead:
cmake/toolchains/example-toolchain.cmake
¶set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_COMPILER chc12)
set(CMAKE_CXX_COMPILER chc12)