[CMAKE] Search the PATH for the compilers and cache the results

We are deliberately using a macro here instead of REQUIRED parameter
because it is available only in CMake 3.18+, so it won't work with
CMake version that is being shipped with RosBE.

On my dev box the RosBE tools are only in the PATH when needed.
Since my IDE inherits the PATH from the system and not from my shell,
I needed to be able to run configure.sh with the tools in my PATH
and then be able to successfully reconfigure when building
from a "regular" command prompt.
This commit is contained in:
William Kent 2022-05-13 18:33:14 -04:00 committed by Stanislav Motylkov
parent 6c38b251cf
commit 3464df8c28
No known key found for this signature in database
GPG key ID: AFE513258CBA9E92

View file

@ -1,4 +1,11 @@
macro(require_program varname execname)
find_program(${varname} ${execname})
if(NOT ${varname})
message(FATAL_ERROR "${execname} not found")
endif()
endmacro()
# pass variables necessary for the toolchain (needed for try_compile)
set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES ARCH)
@ -28,15 +35,15 @@ set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR i686)
# Which tools to use
set(CMAKE_C_COMPILER ${MINGW_TOOLCHAIN_PREFIX}gcc${MINGW_TOOLCHAIN_SUFFIX} CACHE FILEPATH "The C Compiler")
set(CMAKE_CXX_COMPILER ${MINGW_TOOLCHAIN_PREFIX}g++${MINGW_TOOLCHAIN_SUFFIX} CACHE FILEPATH "The C++ Compiler")
set(CMAKE_ASM_COMPILER ${MINGW_TOOLCHAIN_PREFIX}gcc${MINGW_TOOLCHAIN_SUFFIX} CACHE FILEPATH "The ASM Compiler")
require_program(CMAKE_C_COMPILER ${MINGW_TOOLCHAIN_PREFIX}gcc${MINGW_TOOLCHAIN_SUFFIX})
require_program(CMAKE_CXX_COMPILER ${MINGW_TOOLCHAIN_PREFIX}g++${MINGW_TOOLCHAIN_SUFFIX})
require_program(CMAKE_ASM_COMPILER ${MINGW_TOOLCHAIN_PREFIX}gcc${MINGW_TOOLCHAIN_SUFFIX})
set(CMAKE_ASM_COMPILER_ID "GNU")
set(CMAKE_MC_COMPILER ${MINGW_TOOLCHAIN_PREFIX}windmc)
set(CMAKE_RC_COMPILER ${MINGW_TOOLCHAIN_PREFIX}windres)
set(CMAKE_DLLTOOL ${MINGW_TOOLCHAIN_PREFIX}dlltool)
require_program(CMAKE_MC_COMPILER ${MINGW_TOOLCHAIN_PREFIX}windmc)
require_program(CMAKE_RC_COMPILER ${MINGW_TOOLCHAIN_PREFIX}windres)
require_program(CMAKE_DLLTOOL ${MINGW_TOOLCHAIN_PREFIX}dlltool)
#set(CMAKE_AR ${MINGW_TOOLCHAIN_PREFIX}gcc-ar${MINGW_TOOLCHAIN_SUFFIX})
set(CMAKE_OBJCOPY ${MINGW_TOOLCHAIN_PREFIX}objcopy)
require_program(CMAKE_OBJCOPY ${MINGW_TOOLCHAIN_PREFIX}objcopy)
set(CMAKE_C_CREATE_STATIC_LIBRARY "<CMAKE_AR> crT <TARGET> <LINK_FLAGS> <OBJECTS>")
set(CMAKE_CXX_CREATE_STATIC_LIBRARY ${CMAKE_C_CREATE_STATIC_LIBRARY})