Ryan Prichard | 7aea7e9 | 2022-01-13 17:30:17 -0800 | [diff] [blame] | 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 | |
| 5 | # determine the compiler to use for RC programs |
| 6 | # NOTE, a generator may set CMAKE_RC_COMPILER before |
| 7 | # loading this file to force a compiler. |
| 8 | # use environment variable RC first if defined by user, next use |
| 9 | # the cmake variable CMAKE_GENERATOR_RC which can be defined by a generator |
| 10 | # as a default compiler |
| 11 | if(NOT CMAKE_RC_COMPILER) |
| 12 | # prefer the environment variable RC |
| 13 | if(NOT $ENV{RC} STREQUAL "") |
| 14 | get_filename_component(CMAKE_RC_COMPILER_INIT $ENV{RC} PROGRAM PROGRAM_ARGS CMAKE_RC_FLAGS_ENV_INIT) |
| 15 | if(CMAKE_RC_FLAGS_ENV_INIT) |
| 16 | set(CMAKE_RC_COMPILER_ARG1 "${CMAKE_RC_FLAGS_ENV_INIT}" CACHE STRING "Arguments to RC compiler") |
| 17 | endif() |
| 18 | if(EXISTS ${CMAKE_RC_COMPILER_INIT}) |
| 19 | else() |
| 20 | message(FATAL_ERROR "Could not find compiler set in environment variable RC:\n$ENV{RC}.") |
| 21 | endif() |
| 22 | endif() |
| 23 | |
| 24 | # next try prefer the compiler specified by the generator |
| 25 | if(CMAKE_GENERATOR_RC) |
| 26 | if(NOT CMAKE_RC_COMPILER_INIT) |
| 27 | set(CMAKE_RC_COMPILER_INIT ${CMAKE_GENERATOR_RC}) |
| 28 | endif() |
| 29 | endif() |
| 30 | |
| 31 | # finally list compilers to try |
| 32 | if(CMAKE_RC_COMPILER_INIT) |
| 33 | set(CMAKE_RC_COMPILER_LIST ${CMAKE_RC_COMPILER_INIT}) |
| 34 | else() |
| 35 | set(CMAKE_RC_COMPILER_LIST rc) |
| 36 | endif() |
| 37 | |
| 38 | # Find the compiler. |
| 39 | find_program(CMAKE_RC_COMPILER NAMES ${CMAKE_RC_COMPILER_LIST} DOC "RC compiler") |
| 40 | if(CMAKE_RC_COMPILER_INIT AND NOT CMAKE_RC_COMPILER) |
| 41 | set(CMAKE_RC_COMPILER "${CMAKE_RC_COMPILER_INIT}" CACHE FILEPATH "RC compiler" FORCE) |
| 42 | endif() |
| 43 | endif() |
| 44 | |
| 45 | mark_as_advanced(CMAKE_RC_COMPILER) |
| 46 | |
| 47 | get_filename_component(_CMAKE_RC_COMPILER_NAME_WE ${CMAKE_RC_COMPILER} NAME_WE) |
| 48 | if(_CMAKE_RC_COMPILER_NAME_WE STREQUAL "windres") |
| 49 | set(CMAKE_RC_OUTPUT_EXTENSION .obj) |
| 50 | else() |
| 51 | set(CMAKE_RC_OUTPUT_EXTENSION .res) |
| 52 | endif() |
| 53 | |
| 54 | # configure variables set in this file for fast reload later on |
| 55 | configure_file(${CMAKE_ROOT}/Modules/CMakeRCCompiler.cmake.in |
| 56 | ${CMAKE_PLATFORM_INFO_DIR}/CMakeRCCompiler.cmake) |
| 57 | set(CMAKE_RC_COMPILER_ENV_VAR "RC") |