summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeDetermineCCompiler.cmake
diff options
context:
space:
mode:
authorAlexander Neundorf <neundorf@kde.org>2007-05-17 17:20:44 (GMT)
committerAlexander Neundorf <neundorf@kde.org>2007-05-17 17:20:44 (GMT)
commit61d3444f93600955ca12840b0e62503584bb8910 (patch)
treeed21dca2d6c506618088533bcfe62f734b497272 /Modules/CMakeDetermineCCompiler.cmake
parent9bfe711ef10a02db0cb63c7fcb797fbc0df705ab (diff)
downloadCMake-61d3444f93600955ca12840b0e62503584bb8910.zip
CMake-61d3444f93600955ca12840b0e62503584bb8910.tar.gz
CMake-61d3444f93600955ca12840b0e62503584bb8910.tar.bz2
ENH: merge CMake-CrossCompileBasic to HEAD
-add a RESULT_VARIABLE to INCLUDE() -add CMAKE_TOOLCHAIN_FILE for specifiying your (potentially crosscompiling) toolchain -have TRY_RUN() complain if you try to use it in crosscompiling mode (which were compiled but cannot run on this system) -use CMAKE_EXECUTABLE_SUFFIX in TRY_RUN(), probably TRY_RUN won't be able to run the executables if they have a different suffix because they are probably crosscompiled, but nevertheless it should be able to find them -make several cmake variables presettable by the user: CMAKE_C/CXX_COMPILER, CMAKE_C/CXX_OUTPUT_EXTENSION, CMAKE_SYSTEM_NAME, CMAKE_SYSTEM_INFO_FILE -support prefix for GNU toolchains (arm-elf-gcc, arm-elf-ar, arm-elf-strip etc.) -move ranlib on OSX from the file command to a command in executed in cmake_install.cmake -add support for stripping during install in cmake_install.cmake -split out cl.cmake from Windows-cl.cmake, first (very incomplete) step to support MS crosscompiling tools -remove stdio.h from the simple C program which checks if the compiler works, since this may not exist for some embedded platforms -create a new CMakeFindBinUtils.cmake which collects the search fro ar, ranlib, strip, ld, link, install_name_tool and other tools like these -add support for CMAKE_FIND_ROOT_PATH for all FIND_XXX commands, which is a list of directories which will be prepended to all search directories, right now as a cmake variable, turning it into a global cmake property may need some more work -remove cmTestTestHandler::TryExecutable(), it's unused -split cmFileCommand::HandleInstall() into slightly smaller functions Alex
Diffstat (limited to 'Modules/CMakeDetermineCCompiler.cmake')
-rw-r--r--Modules/CMakeDetermineCCompiler.cmake86
1 files changed, 71 insertions, 15 deletions
diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake
index d80452f..0ee390b 100644
--- a/Modules/CMakeDetermineCCompiler.cmake
+++ b/Modules/CMakeDetermineCCompiler.cmake
@@ -2,9 +2,26 @@
# determine the compiler to use for C programs
# NOTE, a generator may set CMAKE_C_COMPILER before
# loading this file to force a compiler.
-# use environment variable CCC first if defined by user, next use
+# use environment variable CC first if defined by user, next use
# the cmake variable CMAKE_GENERATOR_CC which can be defined by a generator
# as a default compiler
+# If the internal cmake variable _CMAKE_TOOLCHAIN_PREFIX is set, this is used
+# as prefix for the tools (e.g. arm-elf-gcc, arm-elf-ar etc.). This works
+# currently with the GNU crosscompilers.
+# It also tries to detect a MS crosscompiler and find out its
+# suffix (clarm.exe), which will be stored in _CMAKE_TOOLCHAIN_SUFFIX and
+# reused for the CXX compiler.
+#
+#
+# Sets the following variables:
+# CMAKE_C_COMPILER
+# CMAKE_AR
+# CMAKE_RANLIB
+# CMAKE_COMPILER_IS_GNUCC
+#
+# If not already set before, it also sets
+# _CMAKE_TOOLCHAIN_PREFIX
+# _CMAKE_TOOLCHAIN_SUFFIX
IF(NOT CMAKE_C_COMPILER)
SET(CMAKE_CXX_COMPILER_INIT NOTFOUND)
@@ -15,10 +32,9 @@ IF(NOT CMAKE_C_COMPILER)
IF(CMAKE_C_FLAGS_ENV_INIT)
SET(CMAKE_C_COMPILER_ARG1 "${CMAKE_C_FLAGS_ENV_INIT}" CACHE STRING "First argument to C compiler")
ENDIF(CMAKE_C_FLAGS_ENV_INIT)
- IF(EXISTS ${CMAKE_C_COMPILER_INIT})
- ELSE(EXISTS ${CMAKE_C_COMPILER_INIT})
+ IF(NOT EXISTS ${CMAKE_C_COMPILER_INIT})
MESSAGE(FATAL_ERROR "Could not find compiler set in environment variable CC:\n$ENV{CC}.")
- ENDIF(EXISTS ${CMAKE_C_COMPILER_INIT})
+ ENDIF(NOT EXISTS ${CMAKE_C_COMPILER_INIT})
ENDIF($ENV{CC} MATCHES ".+")
# next try prefer the compiler specified by the generator
@@ -32,26 +48,64 @@ IF(NOT CMAKE_C_COMPILER)
IF(CMAKE_C_COMPILER_INIT)
SET(CMAKE_C_COMPILER_LIST ${CMAKE_C_COMPILER_INIT})
ELSE(CMAKE_C_COMPILER_INIT)
- SET(CMAKE_C_COMPILER_LIST gcc cc cl bcc xlc)
+ SET(CMAKE_C_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}gcc ${_CMAKE_TOOLCHAIN_PREFIX}cc cl${_CMAKE_TOOLCHAIN_SUFFIX} bcc xlc)
ENDIF(CMAKE_C_COMPILER_INIT)
# Find the compiler.
+ IF (_CMAKE_USER_CXX_COMPILER_PATH)
+ FIND_PROGRAM(CMAKE_C_COMPILER NAMES ${CMAKE_C_COMPILER_LIST} PATHS ${_CMAKE_USER_CXX_COMPILER_PATH} DOC "C compiler" NO_DEFAULT_PATH)
+ ENDIF (_CMAKE_USER_CXX_COMPILER_PATH)
FIND_PROGRAM(CMAKE_C_COMPILER NAMES ${CMAKE_C_COMPILER_LIST} DOC "C compiler")
+
IF(CMAKE_C_COMPILER_INIT AND NOT CMAKE_C_COMPILER)
SET(CMAKE_C_COMPILER "${CMAKE_C_COMPILER_INIT}" CACHE FILEPATH "C compiler" FORCE)
ENDIF(CMAKE_C_COMPILER_INIT AND NOT CMAKE_C_COMPILER)
+ELSE(NOT CMAKE_C_COMPILER)
+
+ # if a compiler was specified by the user but without path,
+ # now try to find it with the full path and force it into the cache
+ GET_FILENAME_COMPONENT(_CMAKE_USER_C_COMPILER_PATH "${CMAKE_C_COMPILER}" PATH)
+ IF(NOT _CMAKE_USER_C_COMPILER_PATH)
+ FIND_PROGRAM(CMAKE_C_COMPILER_WITH_PATH NAMES ${CMAKE_C_COMPILER})
+ MARK_AS_ADVANCED(CMAKE_C_COMPILER_WITH_PATH)
+ SET(CMAKE_C_COMPILER ${CMAKE_C_COMPILER_WITH_PATH} CACHE FILEPATH "C compiler" FORCE)
+ ENDIF(NOT _CMAKE_USER_C_COMPILER_PATH)
ENDIF(NOT CMAKE_C_COMPILER)
-MARK_AS_ADVANCED(CMAKE_C_COMPILER)
-GET_FILENAME_COMPONENT(COMPILER_LOCATION "${CMAKE_C_COMPILER}"
- PATH)
+MARK_AS_ADVANCED(CMAKE_C_COMPILER)
+
+IF (NOT _CMAKE_TOOLCHAIN_LOCATION)
+ GET_FILENAME_COMPONENT(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_C_COMPILER}" PATH)
+ENDIF (NOT _CMAKE_TOOLCHAIN_LOCATION)
+
+# if we have a gcc cross compiler, they have usually some prefix, like
+# e.g. powerpc-linux-gcc, arm-elf-gcc or i586-mingw32msvc-gcc
+# the other tools of the toolchain usually have the same prefix
+IF (NOT _CMAKE_TOOLCHAIN_PREFIX)
+ GET_FILENAME_COMPONENT(COMPILER_BASENAME "${CMAKE_C_COMPILER}" NAME_WE)
+ IF (COMPILER_BASENAME MATCHES "^(.+-)g?cc")
+ STRING(REGEX REPLACE "^(.+-)g?cc" "\\1" _CMAKE_TOOLCHAIN_PREFIX "${COMPILER_BASENAME}")
+ ENDIF (COMPILER_BASENAME MATCHES "^(.+-)g?cc")
+ENDIF (NOT _CMAKE_TOOLCHAIN_PREFIX)
-FIND_PROGRAM(CMAKE_AR NAMES ar PATHS ${COMPILER_LOCATION} )
+# if we have a MS cross compiler, it usually has a suffix, like
+# e.g. clarm.exe or clmips.exe. Use this suffix for the CXX compiler too.
+IF (NOT _CMAKE_TOOLCHAIN_SUFFIX)
+ GET_FILENAME_COMPONENT(COMPILER_BASENAME "${CMAKE_C_COMPILER}" NAME)
+ IF (COMPILER_BASENAME MATCHES "^cl(.+)\\.exe$")
+ STRING(REGEX REPLACE "^cl(.+)\\.exe$" "\\1" _CMAKE_TOOLCHAIN_SUFFIX "${COMPILER_BASENAME}")
+ ENDIF (COMPILER_BASENAME MATCHES "^cl(.+)\\.exe$")
+ENDIF (NOT _CMAKE_TOOLCHAIN_SUFFIX)
+
+# some exotic compilers have different extensions (e.g. sdcc uses .rel)
+# so don't overwrite it if it has been already defined by the user
+IF(NOT CMAKE_C_OUTPUT_EXTENSION)
+ IF(UNIX)
+ SET(CMAKE_C_OUTPUT_EXTENSION .o)
+ ELSE(UNIX)
+ SET(CMAKE_C_OUTPUT_EXTENSION .obj)
+ ENDIF(UNIX)
+ENDIF(NOT CMAKE_C_OUTPUT_EXTENSION)
-FIND_PROGRAM(CMAKE_RANLIB NAMES ranlib)
-IF(NOT CMAKE_RANLIB)
- SET(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib")
-ENDIF(NOT CMAKE_RANLIB)
-MARK_AS_ADVANCED(CMAKE_RANLIB)
# Build a small source file to identify the compiler.
IF(${CMAKE_GENERATOR} MATCHES "Visual Studio")
@@ -62,6 +116,7 @@ IF(${CMAKE_GENERATOR} MATCHES "Visual Studio")
# the user may be using an integrated Intel compiler.
# SET(CMAKE_C_COMPILER_ID "MSVC")
ENDIF(${CMAKE_GENERATOR} MATCHES "Visual Studio")
+
IF(NOT CMAKE_C_COMPILER_ID_RUN)
SET(CMAKE_C_COMPILER_ID_RUN 1)
@@ -81,9 +136,10 @@ IF(NOT CMAKE_C_COMPILER_ID_RUN)
ENDIF("${CMAKE_C_PLATFORM_ID}" MATCHES "MinGW")
ENDIF(NOT CMAKE_C_COMPILER_ID_RUN)
+INCLUDE(CMakeFindBinUtils)
+
# configure variables set in this file for fast reload later on
CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeCCompiler.cmake.in
"${CMAKE_PLATFORM_ROOT_BIN}/CMakeCCompiler.cmake" IMMEDIATE)
-MARK_AS_ADVANCED(CMAKE_AR)
SET(CMAKE_C_COMPILER_ENV_VAR "CC")