During cross-compiling the toolchain file may use CMakeForceCompiler to
force a compiler setting. When using the Xcode generator try to convert
it to a full path by searching the PATH as is done for the Makefile
generators.
For clang, this allows passing -target <triple> to the compiler, and
for qcc, -V<arch> using toolchain files containing something like
set(triple arm-linux-gnueabihf)
set(CMAKE_C_COMPILER "/usr/bin/clang")
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
set(CMAKE_CXX_COMPILER_TARGET ${triple})
or
set(arch gcc_ntoarmv7le)
set(CMAKE_C_COMPILER /opt/qnx650/host/linux/x86/usr/bin/qcc)
set(CMAKE_C_COMPILER_TARGET ${arch})
set(CMAKE_CXX_COMPILER /opt/qnx650/host/linux/x86/usr/bin/QCC)
set(CMAKE_CXX_COMPILER_TARGET ${arch})
Both clang and qcc are inherently cross compiler( driver)s.
When cross-compiling with clang, use the CMAKE_${lang}_COMPILER_TARGET
as the _CMAKE_TOOLCHAIN_PREFIX to find the appropriate binutils.
When cross-compiling with QNX qcc, use the CMAKE_${lang}_COMPILER_TARGET
to set the appropriate _CMAKE_TOOLCHAIN_PREFIX.
Since commit 7d47c693 (Drop compatibility with CMake < 2.4, 2013-10-08)
we no longer need to use the configure_file IMMEDIATE option to support
compatibility modes less than 2.0.
3e04946 Require CMAKE_<LANG>_COMPILER to be found as a full path
6007f7c CMakeDetermineCompilerId: Always use compiler detected from IDE
332771c CMakeDetermine*Compiler: Remove temporary cache entry
One way to use clang as a cross-compiler is to create
a symlink named <target>-clang, which is equivalent to
running
clang -target <target>
Extract the toolchain prefix to find the binutils executables.
When the user or toolchain file sets CMAKE_<LANG>_COMPILER to a name
without a path we use find_program with CMAKE_<LANG>_COMPILER_WITH_PATH
to search for the tool. Remove the temporary cache entry afterward to
avoid exposing it to projects. It is not set by other logic paths so no
one should be using it.
e5fee8a Store ABI detection results in compiler information files
3df81b4 Move CMAKE_<LANG>_COMPILER_WORKS to compiler information files
7195aca Make platform information files specific to the CMake version
403ead6 Document CMAKE_<LANG>_COMPILER_(ID|VERSION) values
8be51f6 Test variables CMAKE_(C|CXX|Fortran)_COMPILER(|_ID|_VERSION)
ec22a9b Cleanly enable a language in multiple subdirectories
66cb335 VS: Detect the compiler id and tool location
89595d6 VS10: Define CMAKE_VS_PLATFORM_TOOLSET variable
965a69d Xcode: Detect the compiler id and tool location
9a9e1ee CMakeDetermineCompilerId: Prepare to detect IDE compiler id
b8b5c83 Re-order C/C++/Fortran compiler determination logic
At the top of a build tree we configure inside the CMakeFiles directory
files such as "CMakeSystem.cmake" and "CMake<lang>Compiler.cmake" to
save information detected about the system and compilers in use. The
method of detection and the exact results store varies across CMake
versions as things improve. This leads to problems when loading files
configured by a different version of CMake. Previously we ignored such
existing files only if the major.minor part of the CMake version
component changed, and depended on the CMakeCache.txt to tell us the
last version of CMake that wrote the files. This led to problems if the
user deletes the CMakeCache.txt or we add required information to the
files in a patch-level release of CMake (still a "feature point" release
by modern CMake versioning convention).
Ensure that we always have version-consistent platform information files
by storing them in a subdirectory named with the CMake version. Every
version of CMake will do its own system and compiler identification
checks even when a build tree has already been configured by another
version of CMake. Stored results will not clobber those from other
versions of CMake which may be run again on the same tree in the future.
Loaded results will match what the system and language modules expect.
Rename the undocumented variable CMAKE_PLATFORM_ROOT_BIN to
CMAKE_PLATFORM_INFO_DIR to clarify its purpose. The new variable points
at the version-specific directory while the old variable did not.
Configure a hand-generated Visual Studio project to build the compiler id
source file since we cannot run the compiler command-line tool directly.
Add a post-build command to print out the full path to the compiler tool.
Parse the full path to the compiler tool from the build output.
Configure a hand-generated Xcode project to build the compiler id source
file since we cannot run the compiler command-line tool directly. Add a
post-build shell script phase to print out the compiler toolset build
setting. Run xcodebuild to compile the identification binary. Parse
the full path to the compiler tool from the xcodebuild output.
Re-organize CMakeDetermine(C|CXX|Fortran)Compiler.cmake to search for
the compiler command-line tool only under generators for which it makes
sense. For the Visual Studio generators we do not expect to find the
compiler tool from the environment, nor would we use the result anyway.
Furthermore, set CMAKE_${lang}_COMPILER_ID_TEST_FLAGS only when it has a
chance to be used. Extract _CMAKE_TOOLCHAIN_LOCATION from the compiler
path after running the compiler id step so in the future that step can
help find the path to the compiler.
Ancient versions of CMake required else(), endif(), and similar block
termination commands to have arguments matching the command starting the
block. This is no longer the preferred style.
Run the following shell code:
for c in else endif endforeach endfunction endmacro endwhile; do
echo 's/\b'"$c"'\(\s*\)(.\+)/'"$c"'\1()/'
done >convert.sed &&
git ls-files -z -- bootstrap '*.cmake' '*.cmake.in' '*CMakeLists.txt' |
egrep -z -v '^(Utilities/cm|Source/kwsys/)' |
egrep -z -v 'Tests/CMakeTests/While-Endwhile-' |
xargs -0 sed -i -f convert.sed &&
rm convert.sed
Teach CMake to prefer the system default compiler automatically when no
compiler is specified. By default use "cc" for C, "CC" for C++, and
"f95" for Fortran. Load a new Platform/<os>-<lang>.cmake module to
allow each platform to specify for each language its system compiler
name(s) and/or exclude certain names.
Create Platform/(CYGWIN|Darwin|Linux|Windows)-CXX.cmake modules to
specify "c++" as the system C++ compiler name for these platforms. On
systems that use case-insensitive filesystems exclude C++ compiler names
that are distinguished from C compiler names only by case.
This will change the default compiler selection for existing build
scripts that do not specify a compiler when run on machines with
separate system and GNU compilers both installed in the PATH. We do not
make this change in default behavior lightly. However:
(1) If a given build really needs specific compilers one should specify
them explicitly e.g. by setting CC, CXX, and FC in the environment.
(2) The motivating case is to prefer the system Clang on newer OS X
systems over the older GNU compilers typically also installed. On
such systems the names "cc" and "c++" link to Clang. This is the
first platform known to CMake on which "c++" is not a GNU compiler.
The old behavior selected "gcc" for C and "c++" C++ and therefore
chooses GNU for C and Clang for C++ by default. The new behavior
selects GNU or Clang consistently for both languages on older or
newer OS X systems, respectively.
(3) Other than the motivating OS X case the conditions under which the
behavior changes do not tend to exist in default OS installations.
They typically occur only on non-GNU systems with manually-installed
GNU compilers.
(4) The consequences of the new behavior are not dire. At worst the
project fails to compile with the system compiler when it previously
worked with the non-system GNU compiler. Such failure is easy to
work around (see #1).
In short this change creates a more sensible default behavior everywhere
and fixes poor default behavior on a widely-used platform at the cost of
a modest change in behavior in less-common conditions.
The compiler candidate list selection and search code for C, C++, ASM,
and Fortran languages was duplicated across four modules. To look for
compilers adjacent to already-enabled languages the C and CXX modules
each used _CMAKE_USER_(C|CXX)_COMPILER_PATH and the ASM module used
_CMAKE_TOOLCHAIN_LOCATION. Since commit 4debb7ac (Bias Fortran compiler
search with C/C++ compilers, 2009-09-09) CMake prefers Fortran compilers
matching the vendor and directory of an enabled C or C++ compiler.
Factor out the common functionality among the four languages into a new
CMakeDetermineCompiler module. Generalize the Fortran implementation so
that all languages may each use the vendor and directory of the other
languages that have already been enabled. For now do not list any
vendor-specific names for C, C++, or ASM so that only the directory
preference is used for these languages (existing behavior).
Look for "clang" or "clang++" compiler executables so Clang will be used
when it is the only compiler available. Prefer them last to avoid
changing compiler default preferences for existing scripts.
Currently the VS generators do not support Intel C/C++ .icproj files and
the MS tools do not include a Fortran compiler. Therefore we can always
set the C and CXX compiler IDs to "MSVC" and the Fortran ID to "Intel".
This fixes a regression in support for the Intel Fortran compiler under
the VS plugin introduced by commit cd43636c (Modernize Intel compiler
info on Windows, 2010-12-16). The commit moved the compiler information
into platform files that only load when the proper compiler id is set.
It worked for the NMake Makefiles generator but not for the VS IDE
generator because it did not set the compiler id.
This adds copyright/license notification blocks CMake's non-find
modules. Most of the modules had no notices at all. Some had notices
referring to the BSD license already. This commit normalizes existing
notices and adds missing notices.
- Write a single source file into the compiler id directory
- This avoid requiring the compiler to behave correctly with
respect to include rules and the current working directory
- Helps to identify cross-compiling toolchains with unusual
default behavior
CMAKE_SYSTEM_AND_C_COMPILER_INFO_FILE, CMAKE_SYSTEM_AND_CXX_COMPILER_INFO_FILE,
CMAKE_SYSTEM_AND_C_COMPILER_AND_PROCESSOR_INFO_FILE and CMAKE_SYSTEM_AND_CXX_COMPILER_AND_PROCESSOR_INFO_FILE
Instead of presetting these variables to arbitrary filenames, users should
set up CMAKE_SYSTEM_NAME and the compilers correctly and also create a
Platform/ directory so these files will all follow the official cmake style,
which should make it easier to understand and debug project which have their
own platform/toolchain support files.
-remove support for a suffix to MS crosscompilers, since this is not (yet)
supported by cmake and might confuse users
Alex
CMakeDetermineSystem.cmake, since CMAKE_SYSTEM_NAME might already be preset
when using cmake for cross compiling
use type STRING instead of FILEPATH since otherwise a strange filename was
generated
Alex
second part copies the values from the cmake variables into internal maps.
So this can now be done after the compiler-specific information has been
loaded, which can now overwrite more settings.
Alex
-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