CMakeDetermineRCCompiler.cmake 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #=============================================================================
  2. # Copyright 2004-2009 Kitware, Inc.
  3. #
  4. # Distributed under the OSI-approved BSD License (the "License");
  5. # see accompanying file Copyright.txt for details.
  6. #
  7. # This software is distributed WITHOUT ANY WARRANTY; without even the
  8. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. # See the License for more information.
  10. #=============================================================================
  11. # (To distribute this file outside of CMake, substitute the full
  12. # License text for the above reference.)
  13. # determine the compiler to use for RC programs
  14. # NOTE, a generator may set CMAKE_RC_COMPILER before
  15. # loading this file to force a compiler.
  16. # use environment variable RC first if defined by user, next use
  17. # the cmake variable CMAKE_GENERATOR_RC which can be defined by a generator
  18. # as a default compiler
  19. if(NOT CMAKE_RC_COMPILER)
  20. # prefer the environment variable RC
  21. if(NOT $ENV{RC} STREQUAL "")
  22. get_filename_component(CMAKE_RC_COMPILER_INIT $ENV{RC} PROGRAM PROGRAM_ARGS CMAKE_RC_FLAGS_ENV_INIT)
  23. if(CMAKE_RC_FLAGS_ENV_INIT)
  24. set(CMAKE_RC_COMPILER_ARG1 "${CMAKE_RC_FLAGS_ENV_INIT}" CACHE STRING "First argument to RC compiler")
  25. endif()
  26. if(EXISTS ${CMAKE_RC_COMPILER_INIT})
  27. else()
  28. message(FATAL_ERROR "Could not find compiler set in environment variable RC:\n$ENV{RC}.")
  29. endif()
  30. endif()
  31. # next try prefer the compiler specified by the generator
  32. if(CMAKE_GENERATOR_RC)
  33. if(NOT CMAKE_RC_COMPILER_INIT)
  34. set(CMAKE_RC_COMPILER_INIT ${CMAKE_GENERATOR_RC})
  35. endif()
  36. endif()
  37. # finally list compilers to try
  38. if(CMAKE_RC_COMPILER_INIT)
  39. set(CMAKE_RC_COMPILER_LIST ${CMAKE_RC_COMPILER_INIT})
  40. else()
  41. set(CMAKE_RC_COMPILER_LIST rc)
  42. endif()
  43. # Find the compiler.
  44. find_program(CMAKE_RC_COMPILER NAMES ${CMAKE_RC_COMPILER_LIST} DOC "RC compiler")
  45. if(CMAKE_RC_COMPILER_INIT AND NOT CMAKE_RC_COMPILER)
  46. set(CMAKE_RC_COMPILER "${CMAKE_RC_COMPILER_INIT}" CACHE FILEPATH "RC compiler" FORCE)
  47. endif()
  48. endif()
  49. mark_as_advanced(CMAKE_RC_COMPILER)
  50. get_filename_component(_CMAKE_RC_COMPILER_NAME_WE ${CMAKE_RC_COMPILER} NAME_WE)
  51. if(_CMAKE_RC_COMPILER_NAME_WE STREQUAL "windres")
  52. set(CMAKE_RC_OUTPUT_EXTENSION .obj)
  53. else()
  54. set(CMAKE_RC_OUTPUT_EXTENSION .res)
  55. endif()
  56. # configure variables set in this file for fast reload later on
  57. configure_file(${CMAKE_ROOT}/Modules/CMakeRCCompiler.cmake.in
  58. ${CMAKE_PLATFORM_INFO_DIR}/CMakeRCCompiler.cmake)
  59. set(CMAKE_RC_COMPILER_ENV_VAR "RC")