diff options
author | Alexander Neundorf <neundorf@kde.org> | 2007-05-17 17:20:44 (GMT) |
---|---|---|
committer | Alexander Neundorf <neundorf@kde.org> | 2007-05-17 17:20:44 (GMT) |
commit | 61d3444f93600955ca12840b0e62503584bb8910 (patch) | |
tree | ed21dca2d6c506618088533bcfe62f734b497272 /Modules/CMakeDetermineCXXCompiler.cmake | |
parent | 9bfe711ef10a02db0cb63c7fcb797fbc0df705ab (diff) | |
download | CMake-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/CMakeDetermineCXXCompiler.cmake')
-rw-r--r-- | Modules/CMakeDetermineCXXCompiler.cmake | 75 |
1 files changed, 61 insertions, 14 deletions
diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake index 4ba152a..41b5e47 100644 --- a/Modules/CMakeDetermineCXXCompiler.cmake +++ b/Modules/CMakeDetermineCXXCompiler.cmake @@ -5,13 +5,21 @@ # use environment variable CXX first if defined by user, next use # the cmake variable CMAKE_GENERATOR_CXX 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-g++, arm-elf-ar etc.) +# 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 C compiler. # # Sets the following variables: # CMAKE_CXX_COMPILER # CMAKE_COMPILER_IS_GNUCXX # CMAKE_AR # CMAKE_RANLIB - +# +# If not already set before, it also sets +# _CMAKE_TOOLCHAIN_PREFIX +# _CMAKE_TOOLCHAIN_SUFFIX IF(NOT CMAKE_CXX_COMPILER) SET(CMAKE_CXX_COMPILER_INIT NOTFOUND) @@ -22,10 +30,9 @@ IF(NOT CMAKE_CXX_COMPILER) IF(CMAKE_CXX_FLAGS_ENV_INIT) SET(CMAKE_CXX_COMPILER_ARG1 "${CMAKE_CXX_FLAGS_ENV_INIT}" CACHE STRING "First argument to CXX compiler") ENDIF(CMAKE_CXX_FLAGS_ENV_INIT) - IF(EXISTS ${CMAKE_CXX_COMPILER_INIT}) - ELSE(EXISTS ${CMAKE_CXX_COMPILER_INIT}) + IF(NOT EXISTS ${CMAKE_CXX_COMPILER_INIT}) MESSAGE(FATAL_ERROR "Could not find compiler set in environment variable CXX:\n$ENV{CXX}.\n${CMAKE_CXX_COMPILER_INIT}") - ENDIF(EXISTS ${CMAKE_CXX_COMPILER_INIT}) + ENDIF(NOT EXISTS ${CMAKE_CXX_COMPILER_INIT}) ENDIF($ENV{CXX} MATCHES ".+") # next prefer the generator specified compiler @@ -39,27 +46,65 @@ IF(NOT CMAKE_CXX_COMPILER) IF(CMAKE_CXX_COMPILER_INIT) SET(CMAKE_CXX_COMPILER_LIST ${CMAKE_CXX_COMPILER_INIT}) ELSE(CMAKE_CXX_COMPILER_INIT) - SET(CMAKE_CXX_COMPILER_LIST c++ g++ CC aCC cl bcc xlC) + SET(CMAKE_CXX_COMPILER_LIST ${_CMAKE_TOOLCHAIN_PREFIX}c++ ${_CMAKE_TOOLCHAIN_PREFIX}g++ CC aCC cl${_CMAKE_TOOLCHAIN_SUFFIX} bcc xlC) ENDIF(CMAKE_CXX_COMPILER_INIT) # Find the compiler. + IF (_CMAKE_USER_C_COMPILER_PATH) + FIND_PROGRAM(CMAKE_CXX_COMPILER NAMES ${CMAKE_CXX_COMPILER_LIST} PATHS ${_CMAKE_USER_C_COMPILER_PATH} DOC "C++ compiler" NO_DEFAULT_PATH) + ENDIF (_CMAKE_USER_C_COMPILER_PATH) FIND_PROGRAM(CMAKE_CXX_COMPILER NAMES ${CMAKE_CXX_COMPILER_LIST} DOC "C++ compiler") + IF(CMAKE_CXX_COMPILER_INIT AND NOT CMAKE_CXX_COMPILER) SET(CMAKE_CXX_COMPILER "${CMAKE_CXX_COMPILER_INIT}" CACHE FILEPATH "C++ compiler" FORCE) ENDIF(CMAKE_CXX_COMPILER_INIT AND NOT CMAKE_CXX_COMPILER) +ELSE(NOT CMAKE_CXX_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_CXX_COMPILER_PATH "${CMAKE_CXX_COMPILER}" PATH) + IF(NOT _CMAKE_USER_CXX_COMPILER_PATH) + FIND_PROGRAM(CMAKE_CXX_COMPILER_WITH_PATH NAMES ${CMAKE_CXX_COMPILER}) + MARK_AS_ADVANCED(CMAKE_CXX_COMPILER_WITH_PATH) + SET(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER_WITH_PATH} CACHE FILEPATH "CXX compiler" FORCE) + ENDIF(NOT _CMAKE_USER_CXX_COMPILER_PATH) ENDIF(NOT CMAKE_CXX_COMPILER) MARK_AS_ADVANCED(CMAKE_CXX_COMPILER) -GET_FILENAME_COMPONENT(COMPILER_LOCATION "${CMAKE_CXX_COMPILER}" PATH) +IF (NOT _CMAKE_TOOLCHAIN_LOCATION) + GET_FILENAME_COMPONENT(_CMAKE_TOOLCHAIN_LOCATION "${CMAKE_CXX_COMPILER}" PATH) +ENDIF (NOT _CMAKE_TOOLCHAIN_LOCATION) + +# if we have a g++ cross compiler, they have usually some prefix, like +# e.g. powerpc-linux-g++, arm-elf-g++ or i586-mingw32msvc-g++ +# the other tools of the toolchain usually have the same prefix +IF (NOT _CMAKE_TOOLCHAIN_PREFIX) + GET_FILENAME_COMPONENT(COMPILER_BASENAME "${CMAKE_CXX_COMPILER}" NAME_WE) + IF (COMPILER_BASENAME MATCHES "^(.+-)[gc]\\+\\+") + STRING(REGEX REPLACE "^(.+-)[gc]\\+\\+" "\\1" _CMAKE_TOOLCHAIN_PREFIX "${COMPILER_BASENAME}") + ENDIF (COMPILER_BASENAME MATCHES "^(.+-)[gc]\\+\\+") +ENDIF (NOT _CMAKE_TOOLCHAIN_PREFIX) + +# 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_CXX_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_CXX_OUTPUT_EXTENSION) + IF(UNIX) + SET(CMAKE_CXX_OUTPUT_EXTENSION .o) + ELSE(UNIX) + SET(CMAKE_CXX_OUTPUT_EXTENSION .obj) + ENDIF(UNIX) +ENDIF(NOT CMAKE_CXX_OUTPUT_EXTENSION) -FIND_PROGRAM(CMAKE_AR NAMES ar PATHS ${COMPILER_LOCATION}) -MARK_AS_ADVANCED(CMAKE_AR) - -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) # This block was used before the compiler was identified by building a # source file. Unless g++ crashes when building a small C++ @@ -101,6 +146,8 @@ IF(NOT CMAKE_CXX_COMPILER_ID_RUN) ENDIF("${CMAKE_CXX_PLATFORM_ID}" MATCHES "MinGW") ENDIF(NOT CMAKE_CXX_COMPILER_ID_RUN) +INCLUDE(CMakeFindBinUtils) + # configure all variables set in this file CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCXXCompiler.cmake IMMEDIATE) |