try_compile uses wrong executable suffix when trying to find output file (v3.21.1)
After adding cxx_std_14
to a library by target_compile_features
, the configure phase fails with the following error.
[...]/IAR-BuildTools-Arm-8.50.4/bin/ilinkarm --silent CMakeFiles/cmTC_29181.dir/CMakeCCompilerABI.c.o --semihosting --vfe --text_out locale --no_exceptions --no_out_extension -o cmTC_29181.elf
Cannot copy output executable
''
to destination specified by COPY_FILE:
'[...]/build/CMakeFiles/3.21.1/CMakeDetermineCompilerABI_C.bin'
Unable to find the executable at any of:
[...]/build/CMakeFiles/CMakeTmp/cmTC_29181
[...]/build/CMakeFiles/CMakeTmp/Debug/cmTC_29181
[...]/build/CMakeFiles/CMakeTmp/Development/cmTC_29181
As you can see, it uses "-o XXX.elf" in the linker command, but when looking for the generated file it tries the paths without ".elf"
The state of my own investigation is that in Modules/Compiler/IAR.cmake
there is
macro(__compiler_iar_ilink lang)
set(CMAKE_EXECUTABLE_SUFFIX_${lang} ".elf")
but in Source/cmCoreTryCompile.cxx
there is
void cmCoreTryCompile::FindOutputFile(const std::string& targetName,
cmStateEnums::TargetType targetType)
{
[ ...SNIP... ]
if (targetType == cmStateEnums::EXECUTABLE) {
tmpOutputFile += targetName;
tmpOutputFile += this->Makefile->GetSafeDefinition("CMAKE_EXECUTABLE_SUFFIX");
The first is setting CMAKE_EXECUTABLE_SUFFIX_${lang}
but the latter is using CMAKE_EXECUTABLE_SUFFIX
.
In my opinion this is not working because different variables are used for finding and for linking. Shouldn't both use the same?
With this change in Modules/Compiler/IAR.cmake
is works for me
macro(__compiler_iar_ilink lang)
- set(CMAKE_EXECUTABLE_SUFFIX_${lang} ".elf")
+ set(CMAKE_EXECUTABLE_SUFFIX ".elf")
set(CMAKE_${lang}_OUTPUT_EXTENSION ".o")
if (${lang} STREQUAL "C" OR ${lang} STREQUAL "CXX")
set(CMAKE_${lang}_COMPILE_OBJECT "<CMAKE_${lang}_COMPILER> ${CMAKE_IAR_${lang}_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
I also tried setting CMAKE_EXECUTABLE_SUFFIX
in my custom toolchain file to work around this, but does not have any effect. The variable seems empty in cmCoreTryCompile.cxx
.
Am I doing something wrong or should both locations use the same variable?