Fix: make GCC.cmake host compatible
GCC.cmake holds generic functionality like running the preprocessor
on a file, creating raw binary output and so on. Common parts of the
file were executing cross-compilation specific code which made the
file incompatible to compiling code targeting the host machine. This
change makes these cross-compilation specific part execute conditionally
and thus allows using generic functionality when targeting the host.
Change-Id: I962ea47868d876c02a3c5ff9e18af13ff0813429
Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
diff --git a/tools/cmake/compiler/GCC.cmake b/tools/cmake/compiler/GCC.cmake
index 77eff9a..993bae0 100644
--- a/tools/cmake/compiler/GCC.cmake
+++ b/tools/cmake/compiler/GCC.cmake
@@ -40,12 +40,6 @@
include_guard(DIRECTORY)
-if(NOT CROSS_COMPILE AND NOT DEFINED ENV{CROSS_COMPILE})
- message(FATAL_ERROR "'CROSS_COMPILE' is not defined. Set it to the gcc prefix triplet, ie. cmake <..>-DCROSS_COMPILE=aarch64-elf-")
-endif()
-
-set(CROSS_COMPILE $ENV{CROSS_COMPILE} CACHE STRING "Prefix of the cross-compiler commands")
-
#Generate a list of tool names to look for. Store the result in CMAKE_<lang>_COMPILER.
function(gcc_find_tool NAME LANG)
string(REGEX REPLACE "([^;]+);" "\\1${NAME};\\1${NAME}.exe;" _gcc_names "${CROSS_COMPILE};")
@@ -57,11 +51,19 @@
set(CMAKE_${LANG}_COMPILER ${_cross_compile_gcc} CACHE STRING "${LANG} compiler executable.")
endfunction()
-gcc_find_tool(gcc C)
-gcc_find_tool(g++ CXX)
+if(CMAKE_CROSSCOMPILING)
+ if(NOT CROSS_COMPILE AND NOT DEFINED ENV{CROSS_COMPILE})
+ message(FATAL_ERROR "'CROSS_COMPILE' is not defined. Set it to the gcc prefix triplet, ie. cmake <..>-DCROSS_COMPILE=aarch64-elf-")
+ endif()
-#Official solution to disable compiler checks
-set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+ set(CROSS_COMPILE $ENV{CROSS_COMPILE} CACHE STRING "Prefix of the cross-compiler commands")
+
+ gcc_find_tool(gcc C)
+ gcc_find_tool(g++ CXX)
+
+ #Official solution to disable compiler checks
+ set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+endif()
#By default when INTERFACE_INCUDES of libraries linked to an exe are treated
#as system includes. gcc-arm-8.2-2019.01-i686-mingw32-aarch64-elf (gcc 8.2.1) will