Commit Graph

87 Commits

Author SHA1 Message Date
Marc Chevrier
7b552b9a64 Linker: Save GNU push-/pop-state detection with compiler inspection results
Previously we saved it in the cache, which:

* Persists even if a new version of CMake changes how the check works.
* Does not propagate to `try_compile` checks.
2025-03-20 11:00:02 -04:00
Tyler
7c38e6bb52 Add CMAKE_<LANG>_STANDARD_LATEST variables
Add a variable to indicate the latest standard known to be supported for
each language:

* `CMAKE_C_STANDARD_LATEST`
* `CMAKE_CXX_STANDARD_LATEST`
* `CMAKE_CUDA_STANDARD_LATEST`
* `CMAKE_HIP_STANDARD_LATEST`
* `CMAKE_OBJC_STANDARD_LATEST`
* `CMAKE_OBJCXX_STANDARD_LATEST`

These variables, more generally referred to as
`CMAKE_<LANG>_STANDARD_LATEST`, are assigned an integer value which
represents the minimum between the latest version of the associated
language standard supported by the current compiler and the latest
version supported by CMake.

Add documentation for these variables in a new page called
`CMAKE_<LANG>_STANDARD_LATEST` was added under the "Variables for
Languages" section of the `cmake-variables(7)` page.

Update each compiler-specific CMake script under
`${CMAKE_ROOT}\Modules\Compiler` to manually define the relevant
`CMAKE_<LANG>_STANDARD_LATEST` variable as necessary. This will
require updating and maintaining as newer compiler versions become
recognized by CMake.

Closes: #25717
2024-04-30 11:05:03 -04:00
Ben Boeckel
678717f3e4 cxxmodules: provide a detection variable for import std 2024-04-18 09:53:21 -04:00
Ben Boeckel
f80c60df02 CMakeDetermineCompilerSupport: construct C++ modules targets
Compilers may implement this by implementing a `_cmake_cxx_import_std`
function which takes the standard version as an argument (e.g., `23`)
and creating a target named `CMake::CXX${std}` that represents how
`import std;` should be represented within CMake.
2024-04-12 09:32:29 -04:00
Raul Tambre
f21dbf8f26 C++26: Fix C++/CUDA/HIP compile feature support
In commit f808d8afb9 (CMake: Support upcoming C++26 language level,
2022-08-19, v3.25.0-rc1~218^2) we forgot some necessary scaffolding.

Fixes: #25819
2024-04-09 11:38:59 +03:00
Brad King
c29bc18b10 Merge topic 'cxxmodules-clang-resource-dir'
a3ada1a241 Clang: detect -resource-dir for clang-scan-deps

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !9274
2024-02-22 08:24:00 -05:00
Ben Boeckel
a3ada1a241 Clang: detect -resource-dir for clang-scan-deps
When cross-compiling, `clang-scan-deps` needs help to find the correct
location of core headers such as `stddef.h`. Always determine this path
and pass it when available.

Fixes: #25590
2024-02-21 08:51:42 -05:00
Michael Hirsch
ec2ad53d18
Modules: refactor compiler find to use modern foreach 2023-11-18 19:08:00 -05:00
Marc Chevrier
c26c6ac488 Link Step: compute effective linker used by the compiler
Extract the effective linker during the computation of implicit artifacts
delivered by the compiler to the linker.
Define various variables describing the linker:
* CMAKE_<LANG>_COMPILER_LINKER
* CMAKE_<LANG>_COMPILER_LINKER_VERSION
* CMAKE_<LANG>_COMPILER_LINKER_ID
* CMAKE_<LANG>_COMPILER_LINKER_FRONTEND_VARIANT

This is complementary to feature introduced by commit 96a953b1ed
(Add options to specify linker tool, 2023-09-27).

Fixes: #17596, #18209, #25344
2023-10-24 08:34:50 -04:00
Marc Chevrier
96a953b1ed Add options to specify linker tool
Offer the capability, through variable `CMAKE_LINKER_TYPE`, as well as
the target property `LINKER_TYPE` to specify which linker must be used.

The implementation of this capability is specified by variables specific
to the language and linker type: `CMAKE_<LANG>_USING_LINKER_<TYPE>`.
Some definitions are provided as part of `CMake`.

For example, to select the `LLVM` linker rather than the standard one,
the type `LLD` should be specified through the variable `CMAKE_LINKER_TYPE`.
And, on `Apple`, `Linux` and some environments on `Windows`, the variable
`CMAKE_<LANG>_USING_LINKER_LLD` has value `-fuse-ld=lld`. And for `Windows`
environments  based on `MSVC`, where the linker is used directly, the tool
`lld-link.exe` will be used rather than `link.exe`.

Fixes: #19174, #24254, #24990
2023-10-13 11:52:35 +02:00
Marc Chevrier
0626b62cf2 Link Step: ensure the correct linker is used for depfile configuration
This is related to MR !8443.
2023-05-28 11:28:08 +02:00
Marc Chevrier
375e6fdbbe Link step: use linker dependency linker file
Based on work done by @ben.boeckel (!8051)

Fixes: #22217
2023-05-03 17:08:07 +02:00
Brad King
45d1925efc Treat '.ccm', '.cxxm', and '.c++m' files as C++ sources
These extensions are used by convention for C++ module interface units
with Clang.

For now, do not add any tests using these extensions.
Very few compilers recognize them as C++ sources.
Tests can be added later as part of C++ modules support.
2023-03-09 14:36:01 -05:00
Marc Chevrier
ede33f30cf Apple: Handle generation and comsuption of text-based stubs (.tbd files)
Fixes: #24123
2023-03-01 12:23:28 +01:00
Raul Tambre
fc3a1cbdd8 CompilerID: Compiler extensions default detection 2021-09-28 21:24:53 +03:00
Brad King
a136b6ec98 MINGW: Define variable only when targeting Windows platforms
The `MINGW` variable indicates that the compiler targets MinGW, a GNU
ABI on Windows.  Since commit aff3147917 (Modernize GNU compiler info on
Windows, 2009-12-02, v2.8.2~636), we load the `Platform/Windows-GNU`
module for compilers targetin MinGW, so set the variable there instead.
This is equivalent to `Platform/Windows-MSVC` setting the `MSVC`
variable.  Also remove `if(MINGW)` checks from the module, which have
not been necessary since the enclosed logic was moved to that module.

The undocumented `CMAKE_COMPILER_IS_MINGW` internal variable is now
unused, so remove it too.

Fixes: #22647
2021-09-17 12:17:35 -04:00
Brad King
0b7ae84a96 Cygwin: Remove redundant definitions of CYGWIN and UNIX variables
These are set by modules loaded for `CMAKE_SYSTEM_NAME`.  We do not
need to set them again if the compiler defines `__CYGWIN__`.

Also remove the now-unused undocumented `CMAKE_COMPILER_IS_CYGWIN`
internal variable.
2021-09-16 09:55:26 -04:00
Andrew Gilewsky
7c4c4f1406 Treat '.ixx' and '.cppm' files as C++ sources
These extensions are used by convention for C++ modules and interface
units with MSVC.
2021-03-22 11:58:44 -04:00
Ben Boeckel
b0fc2993e1 Treat the '.mpp' file extension as C++ code
This is the extension required in build2 for C++ module support.
2021-01-05 09:29:18 -05:00
Raul Tambre
9f3c70a333 CUDA, CXX, OBJCXX: C++23 support with Clang 12
Clang 12 landed initial support for C++23 language mode flag -std={c|gnu}++2b
in commit 6627a3c2873fdf7ccba1a1573371079be48b36e8.
2020-12-08 18:43:59 +02:00
Brad King
f511a1c009 CMakeDetermineCompilerABI: Detect byte order as part of check
We already detect `sizeof(void*)`.  Detect the byte order as part of the
same check.

Issue: #21392
2020-11-04 10:08:13 -05:00
Robert Maynard
8cc384f629 Compilers: Add paths from -print-sysroot to system prefix path 2020-04-14 13:48:28 -04:00
Cristian Adam
806e01d638 Objective-C: Do not treat Objective-C files as C++ files
When both C and C++ langauges are enabled, the Objective-C files
should be treated as C files and not as C++ files.
2019-10-11 14:01:48 +02:00
Steve Wilson
9e66397c28 Languages: Add support for Objective-C++
Add entries in Modules and Modules/Platform to support
Objective-C++ compiler determination and identification.
Add Modules to check Objective-C++ compiler flags, source
compilations, program checks, etc...

Use OBJCXX as the designator of the language, eg:

project(foo OBJCXX)

Add various tests for Objective-C++ language features.  Add
tests to preserve C++ handling of .M and .mm files when
Objective-C++ is not a configured language.

Co-authored-by: Cristian Adam <cristian.adam@gmail.com>
2019-09-28 15:56:53 +02:00
Steve Wilson
80f120a85f Languages: Add support for Objective-C
Add entries in Modules and Modules/Platform to support
Objective-C compiler determination and identification.
Add Modules to check Objective-C compiler flags, source
compilations, program checks, etc...

Use OBJC as the designator of the language, eg:

project(foo OBJC)

Add various tests for Objective-C language features.  Add
tests to preserve C++ handling of .m and .mm files when
OBJC is not a configured language.

Co-Authored-By: Cristian Adam <cristian.adam@gmail.com>
2019-09-28 15:56:46 +02:00
Zsolt Parragi
53fbe23f3f clang: introduce CMAKE_<lang>_COMPILER_FRONTEND_VARIANT
This variable is set to GNU on Windows when clang.exe ar clang++.exe is
used, and set to MSVC for clang-cl.exe.

CMAKE_<lang>_SIMULATE_ID is set to MSVC in both cases, as clang defaults
to -fms-compatibility for all command lines on windows.
2019-05-17 19:11:34 +02:00
Chuck Cranor
5990ecb741 Compute implicit include directories from compiler output
- CMakeParseImplicitIncludeInfo.cmake: new parser that extracts the
   compiler's include path from verbose output.  If the parser cannot
   parse the output, we fall back to the old behavior.  On osx we skip
   over framework directories (handled elsewhere).

 - CMakeDetermineCompilerABI.cmake:
     - use verbose flag in try_compile for ${src}
     - use new cmake_parse_implicit_include_info() to attempt extract
       implicit include directory path and if successful set
        CMAKE_${LANG}_IMPLICIT_INCLUDE_DIRECTORIES

 - CMakeCCompiler.cmake.in and CMakeCXXCompiler.cmake.in - preserve
   CMAKE_${LANG}_IMPLICIT_INCLUDE_DIRECTORIES value between runs in
   the same way CMAKE_${LANG}_IMPLICIT_LINK_DIRECTORIES is preserved

 - Tests/RunCMake/ParseImplicitIncludeInfo: tests for parse
   based on the older Tests/CMakeTests/ImplicitLinkInfoTest.cmake.in.
   The test runs a set of verbose compiler outputs collected from
   various machines through the parser and checks the results.  New
   compiler files can be added by dropping input/output files in the
   ParseImplicitIncludeInfo/data subdirectory and then adding the new set
   of files to the ${targets} list in ParseImplicitIncludeInfo.cmake.
   There is a helper CMakeLists.txt in ParseImplicitIncludeInfo/data
   that can help with the generation of test input files.
   NOTE: the standard cmake pre-commit hook rejects verbose compiler
   output with trailing spaces... you have to manually edit them out.
   This shouldn't impact the test.

Note that both the parser and the test code can use CMAKE_${LANG}_COMPILER_*
variables such as ${CMAKE_CXX_COMPILER_ID} to decide how to parse
verbose compiler output.  For the test code, this requires us to
save the variables values in the test input files.

Fixes: #16291
2019-01-21 11:14:08 -05:00
Mateusz Zych
bd9bfc6449 MSVC: Respect CMAKE_RC_COMPILER and CMAKE_MT in vs_link_{dll,exe}
CMake commands vs_link_dll and vs_link_exe, performing linking on MSVC,
are responsible for calling resource compiler and manifest tool.

Before this commit, both of these tools were called directly, with the
expectation that they are available in the `PATH`. This has been fixed
by respecting CMake variables `CMAKE_RC_COMPILER` and `CMAKE_MT`
defining paths to these tools.

Fixes: #17804
2018-10-29 13:40:47 -04:00
Brad King
bc5bcad45e Xcode: Detect architecture(s) using ARCHS instead of CURRENT_ARCH
Xcode 10 no longer populates `CURRENT_ARCH` with the current
architecture in shell scripts and instead uses `undefined_arch`.
Instead we must use `ARCHS`.  It lists all architectures separated by
spaces.

Fixes: #18085
2018-06-18 13:44:43 -04:00
Brad King
7fe580a362 Features: Add infrastructure for C++ 20 language standard
Issue: #17849
2018-03-27 07:40:54 -04:00
Brad King
b96ca728f1 Add infrastructure to detect secondary compiler version information
Create a `CMAKE_<LANG>_COMPILER_VERSION_INTERNAL` variable to hold
a secondary/internal compiler version number detected at the same
time as the primary compiler version.  This will be useful for some
compilers where we need such a number to determine correct usage.

Inspired-by: Stefan Andersson <tfosm@hotmail.com>
Suggested-by: Norbert Lange <norbert.lange@andritz.com>
Issue: #17264
2017-10-03 08:11:27 -04:00
Norbert Lange
0b1a2876c8 Add a CMAKE_<LANG>_COMPILER_ARCHITECTURE_ID variable
Compilers such as MSVC and IAR may have variants that target different
architectures.  We have been using a `MSVC_<LANG>_ARCHITECTURE_ID`
variable to hold this information for MSVC.  Add an alternative with a
more general name (later we can port MSVC to it too).

This additional information may be needed to generate proper invocations
of the compiler based on its architecture variant.
2017-06-29 13:25:57 -04:00
Brad King
820af5f797 Merge topic 'lang-specific-binutils'
73934188 Rename CMAKE_GCC_{AR,RANLIB} to CMAKE_LANG_COMPILER_{AR,RANLIB}

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !656
2017-04-05 10:15:40 -04:00
Ruslan Baratov
7393418844 Rename CMAKE_GCC_{AR,RANLIB} to CMAKE_LANG_COMPILER_{AR,RANLIB}
The variables recently added by commit b9d36826 (Add 'CMAKE_GCC_AR' and
'CMAKE_GCC_RANLIB' variables, 2017-03-08) are more appropriately managed
with language-specific names rather than toolchain-specific names.
2017-04-03 14:10:50 -04:00
Brad King
a122190509 Xcode: Detect CURRENT_ARCH for use by generator
During compiler identification, extract the Xcode `CURRENT_ARCH` value
and save it for later use by the Xcode generator in an internal compiler
information variable.  This will be useful to know the locations of
object files when only one architecture is built.
2017-03-31 11:26:08 -04:00
Ruslan Baratov
b9d36826c5 Add 'CMAKE_GCC_AR' and 'CMAKE_GCC_RANLIB' variables 2017-03-09 04:28:01 +08:00
Brad King
ae1a6815b6 Features: Add infrastructure for C++ 17 language standard
Issue: #16468
2016-12-02 11:22:46 -05:00
Brad King
735f168bf0 CMakeDetermine*Compiler: Add hook to save custom compiler information
Provide a way for Platform/<os>-Determine-<lang>.cmake modules to save
platform-specific information about the compiler in the configured
CMake<lang>Compiler.cmake modules.
2016-08-12 10:40:51 -04:00
Chuck Atkins
5eaac0c96a Compiler: Add infrastructure for detecting compiler wrappers 2015-12-07 11:09:06 -05:00
Brad King
9682de566e Revert "Disable shared library support when compiler links statically" (#15855)
In commit v3.4.0-rc1~18^2 (Disable shared library support when compiler
links statically, 2015-09-30) we tried to detect when the compiler is
not capable of linking shared libraries (possibly due to flags in use).
However, the approach is not robust against flags like `-nostdlib`.
Revert it for now pending another solution to the original problem.
2015-11-23 10:16:32 -05:00
Brad King
8b4873a1b0 Disable shared library support when compiler links statically
When a user or a compiler wrapper adds '-static' to the compiler flags
then it will always link static binaries.  Detect this from the compiler
id binary and disable TARGET_SUPPORTS_SHARED_LIBS.  This will prevent
projects from accidentally adding shared libraries when the toolchain
does not support them.  It also helps CMake avoid linking with flags
that require shared libraries to be supported.
2015-09-30 15:01:23 -04:00
Brad King
109a7a245a Ninja: Detect MSVC /showIncludes prefix with compiler flags (#15596)
Move detection over to the compiler id logic where we have already
constructed the list of compiler flags from ARG1 and CMAKE_<LANG>_FLAGS.
Pass the flags when we execute "cl" with "/showIncludes".  Also pass "/c"
because we only need to compile, not link.  Check the compiler process
exit code before trusting its output.
2015-09-18 10:02:53 -04:00
Brad King
828c05b9f5 Ninja: Refactor lookup of cmcldeps location
This executable comes with CMake so just compute its location in
cmSystemTools instead of storing it in compiler information modules.
2015-09-18 10:01:25 -04:00
Stephen Kelly
7235334a2f Project: Determine default language dialect for the compiler.
Use the __cplusplus and __STDC_VERSION__ macros to automatically
determine the default dialect for the compiler while determining its
id and version.
2015-09-18 10:00:21 -04:00
Stephen Kelly
dd043c3f21 Features: Add support for C++14 features.
Record the features implemented by GNU 4.9 and Clang 3.4.
2014-05-22 18:01:23 +02:00
Stephen Kelly
a36b957fc4 Features: Add cxx_template_template_parameters.
Extend the existing feature infrastructure as needed to support
both C++11 and C++98 features.
2014-04-16 15:16:23 +02:00
Stephen Kelly
faeddf64f2 project: Add infrastructure for recording CXX compiler features
Add a feature test using the compiler macros and the preprocessor to
determine available features.

Add a CMAKE_CXX_COMPILE_FEATURES variable which contains all features
known to the loaded compiler, and a CMAKE_CXX_KNOWN_FEATURES variable
containing all features known to CMake.  Add language standard specific
variables for internal use to determine the standard-specific compile
flags to use.

This will be extended to other languages in the future.  Follow-up
commits will add features which will be recorded by the feature test.
2014-04-07 16:48:44 +02:00
Tim Blechmann
95cdf13248 Treat .m files consistently as C across all generators
Objective C sources should be compiled with the C compiler, not C++.

The Xcode generator correctly classifies ".m" sources already.  The
cmSystemTools::GetFileFormat method was fixed by commit v2.8.0~1782 (fix
for 7045, use gcc for .m, 2008-08-19) but it is not used by any of the
generator since commit v2.4.0~2819 (major changes to support addition of
languages, 2004-09-22).

Fix the CMAKE_<LANG>_SOURCE_FILE_EXTENSIONS table entries so that
cmGlobalGenerator::GetLanguageFromExtension tells the Makefile, Ninja,
and VS IDE generators to compile ".m" sources as C.  This makes behavior
consistent on all generators.

Signed-off-by: Tim Blechmann <tim@klingt.org>
2014-03-20 09:40:41 -04:00
Peter Kümmel
eeb4aece1c Ninja: use deps = gcc/msvc feature
cmcldeps is now only used for .rc file processing
2013-10-24 19:48:18 +02:00
Brad King
51ab85c398 CMakeDetermineCompilerId: Add notion of "simulated" id/version
Some compilers try to simulate other compilers as a drop-in replacement
supporting all the same command-line options and predefined preprocessor
macros.  In such cases it will be useful to have CMake load the compiler
information files for the simulated compiler instead of duplicating the
information.  Teach CMakeDetermineCompilerId to extract the simulated
compiler id and version when the compiler id detection provides it.
2013-10-04 13:25:06 -04:00