diff options
author | Lingkai Dong <lingkai.dong@arm.com> | 2021-04-21 16:07:22 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2021-04-27 18:03:15 (GMT) |
commit | c4941b7e66cd3a0a9de5ed8189ef025fcd6f3122 (patch) | |
tree | c5158533c814362581c1423834fd2238d529e266 /Source | |
parent | 0078db3888e01343d26c1f695b250663bbcb7ac2 (diff) | |
download | CMake-c4941b7e66cd3a0a9de5ed8189ef025fcd6f3122.zip CMake-c4941b7e66cd3a0a9de5ed8189ef025fcd6f3122.tar.gz CMake-c4941b7e66cd3a0a9de5ed8189ef025fcd6f3122.tar.bz2 |
ARMClang: Do not automatically add cpu/arch compile or link options
The compile options `--march=<arch>` and `--mcpu=<cpu>` and the
link option `--cpu=<cpu>` are automatically added by CMake based
on `CMAKE_SYSTEM_PROCESSOR` or `CMAKE_SYSTEM_ARCH`. But this is not
sufficient, because armclang also supports enabling or disabling
features using `+<feature>`:
-mcpu=<name>[+[no]<feature>+...]
For example:
-mcpu=cortex-a57+nocrypto+nofp+nosimd+crc
(Reference: https://developer.arm.com/documentation/dui0774/k/Compiler-Command-line-Options/-mcpu?lang=en)
The problem is, even if a project adds a flag with features it needs,
CMake still adds flags, resulting in code that is compiled with wrong
CPU features and unable to run.
Add policy `CMP0123` to not automatically add compile or link options,
and let projects set them instead.
Co-Author: Brad King <brad.king@kitware.com>
Fixes: #21173
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmCoreTryCompile.cxx | 9 | ||||
-rw-r--r-- | Source/cmPolicies.h | 5 |
2 files changed, 13 insertions, 1 deletions
diff --git a/Source/cmCoreTryCompile.cxx b/Source/cmCoreTryCompile.cxx index cb84d1d..5399fd0 100644 --- a/Source/cmCoreTryCompile.cxx +++ b/Source/cmCoreTryCompile.cxx @@ -8,6 +8,7 @@ #include <sstream> #include <utility> +#include <cm/string_view> #include <cmext/string_view> #include "cmsys/Directory.hxx" @@ -217,6 +218,7 @@ std::string const kCMAKE_POSITION_INDEPENDENT_CODE = std::string const kCMAKE_SYSROOT = "CMAKE_SYSROOT"; std::string const kCMAKE_SYSROOT_COMPILE = "CMAKE_SYSROOT_COMPILE"; std::string const kCMAKE_SYSROOT_LINK = "CMAKE_SYSROOT_LINK"; +std::string const kCMAKE_ARMClang_CMP0123 = "CMAKE_ARMClang_CMP0123"; std::string const kCMAKE_TRY_COMPILE_OSX_ARCHITECTURES = "CMAKE_TRY_COMPILE_OSX_ARCHITECTURES"; std::string const kCMAKE_TRY_COMPILE_PLATFORM_VARIABLES = @@ -552,6 +554,13 @@ int cmCoreTryCompile::TryCompileCode(std::vector<std::string> const& argv, fprintf(fout, "cmake_policy(SET CMP0104 OLD)\n"); } + /* Set ARMClang cpu/arch policy to match outer project. */ + if (cmProp cmp0123 = + this->Makefile->GetDefinition(kCMAKE_ARMClang_CMP0123)) { + fprintf(fout, "cmake_policy(SET CMP0123 %s)\n", + *cmp0123 == "NEW"_s ? "NEW" : "OLD"); + } + std::string projectLangs; for (std::string const& li : testLangs) { projectLangs += " " + li; diff --git a/Source/cmPolicies.h b/Source/cmPolicies.h index d546b6e..0a5bb4b 100644 --- a/Source/cmPolicies.h +++ b/Source/cmPolicies.h @@ -366,7 +366,10 @@ class cmMakefile; SELECT( \ POLICY, CMP0122, \ "UseSWIG use standard library name conventions for csharp language.", 3, \ - 21, 0, cmPolicies::WARN) + 21, 0, cmPolicies::WARN) \ + SELECT(POLICY, CMP0123, \ + "ARMClang cpu/arch compile and link flags must be set explicitly.", \ + 3, 21, 0, cmPolicies::WARN) #define CM_SELECT_ID(F, A1, A2, A3, A4, A5, A6) F(A1) #define CM_FOR_EACH_POLICY_ID(POLICY) \ |