From 3464df8c28c59b24c02c0c9b28aedd75d7bd8fd0 Mon Sep 17 00:00:00 2001 From: William Kent Date: Fri, 13 May 2022 18:33:14 -0400 Subject: [PATCH] [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. --- toolchain-gcc.cmake | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/toolchain-gcc.cmake b/toolchain-gcc.cmake index a7cc3bc82aa..1462e47b354 100644 --- a/toolchain-gcc.cmake +++ b/toolchain-gcc.cmake @@ -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 " crT ") set(CMAKE_CXX_CREATE_STATIC_LIBRARY ${CMAKE_C_CREATE_STATIC_LIBRARY})