CMakeForceCompiler.cmake 4.1 KB

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