CMakeDetermineRCCompiler.cmake 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. # determine the compiler to use for RC programs
  4. # NOTE, a generator may set CMAKE_RC_COMPILER before
  5. # loading this file to force a compiler.
  6. # use environment variable RC first if defined by user, next use
  7. # the cmake variable CMAKE_GENERATOR_RC which can be defined by a generator
  8. # as a default compiler
  9. if(NOT CMAKE_RC_COMPILER)
  10. # prefer the environment variable RC
  11. if(NOT $ENV{RC} STREQUAL "")
  12. get_filename_component(CMAKE_RC_COMPILER_INIT $ENV{RC} PROGRAM PROGRAM_ARGS CMAKE_RC_FLAGS_ENV_INIT)
  13. if(CMAKE_RC_FLAGS_ENV_INIT)
  14. set(CMAKE_RC_COMPILER_ARG1 "${CMAKE_RC_FLAGS_ENV_INIT}" CACHE STRING "First argument to RC compiler")
  15. endif()
  16. if(EXISTS ${CMAKE_RC_COMPILER_INIT})
  17. else()
  18. message(FATAL_ERROR "Could not find compiler set in environment variable RC:\n$ENV{RC}.")
  19. endif()
  20. endif()
  21. # next try prefer the compiler specified by the generator
  22. if(CMAKE_GENERATOR_RC)
  23. if(NOT CMAKE_RC_COMPILER_INIT)
  24. set(CMAKE_RC_COMPILER_INIT ${CMAKE_GENERATOR_RC})
  25. endif()
  26. endif()
  27. # finally list compilers to try
  28. if(CMAKE_RC_COMPILER_INIT)
  29. set(CMAKE_RC_COMPILER_LIST ${CMAKE_RC_COMPILER_INIT})
  30. else()
  31. set(CMAKE_RC_COMPILER_LIST rc)
  32. endif()
  33. # Find the compiler.
  34. find_program(CMAKE_RC_COMPILER NAMES ${CMAKE_RC_COMPILER_LIST} DOC "RC compiler")
  35. if(CMAKE_RC_COMPILER_INIT AND NOT CMAKE_RC_COMPILER)
  36. set(CMAKE_RC_COMPILER "${CMAKE_RC_COMPILER_INIT}" CACHE FILEPATH "RC compiler" FORCE)
  37. endif()
  38. endif()
  39. mark_as_advanced(CMAKE_RC_COMPILER)
  40. get_filename_component(_CMAKE_RC_COMPILER_NAME_WE ${CMAKE_RC_COMPILER} NAME_WE)
  41. if(_CMAKE_RC_COMPILER_NAME_WE STREQUAL "windres")
  42. set(CMAKE_RC_OUTPUT_EXTENSION .obj)
  43. else()
  44. set(CMAKE_RC_OUTPUT_EXTENSION .res)
  45. endif()
  46. # configure variables set in this file for fast reload later on
  47. configure_file(${CMAKE_ROOT}/Modules/CMakeRCCompiler.cmake.in
  48. ${CMAKE_PLATFORM_INFO_DIR}/CMakeRCCompiler.cmake)
  49. set(CMAKE_RC_COMPILER_ENV_VAR "RC")