try_compile adds extra compiler flag for IAR compiler
I'm trying to use CMake to compile for STM8 architecture using IAR compiler. My configuration is VS2017 (with CMake project support), Ninja generator and CMake 3.11. I know that CMake now support only ARM and AVR architectures but I made some changes in .cmake files to add STM8. First, I added new ARCHITECTURE_ID to CMakePlatformId.h.in
#elif defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)
# if defined(__ICCARM__)
# define ARCHITECTURE_ID "ARM"
# elif defined(__ICCAVR__)
# define ARCHITECTURE_ID "AVR"
# elif defined(__ICCSTM8__)
# define ARCHITECTURE_ID "STM8"
And process it at end of IAR-C.cmake
elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "STM8")
set(CMAKE_C_COMPILE_OBJECT "<CMAKE_C_COMPILER> ${CMAKE_IAR_C_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
endif()
and IAR-CXX.cmake
elseif("${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "STM8")
set(CMAKE_IAR_CXX_FLAG --eec++)
set(CMAKE_CXX_EXTENSION_COMPILE_OPTION -e)
set(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> ${CMAKE_IAR_CXX_FLAG} --silent <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>")
endif()
I know that defining only CMAKE_CXX_COMPILE_OBJECT is not enough, but it is only test still. Also I'm define CMAKE_SYSTEM_NAME, CMAKE_CXX_COMPILER and CMAKE_C_COMPILER in command line
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe -G "Ninja" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\alan\CMakeBuilds\b8acd0a5-87a5-863e-9056-110296654189\install\stm8s" -DCMAKE_SYSTEM_NAME="Generic" -DCMAKE_CXX_COMPILER="C:/IAR/stm8/bin/iccstm8.exe" -DCMAKE_C_COMPILER="C:/IAR/stm8/bin/iccstm8.exe" --debug-trycompile --trace-expand -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe" "C:\Users\alan\source\repos\test"
Now the compiler and architecture identification are successfull. I can see in output file that CMake found the compiler and set approppriate defines. But the testing compiler stage ends with error. For unknown reason CMake adds "-c " flag to rules.ninja file. But IAR compiler does not support this flag.
CMake Error at C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.11/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"C:/IAR/stm8/bin/iccstm8.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/alan/CMakeBuilds/b8acd0a5-87a5-863e-9056-110296654189/build/stm8s/CMakeFiles/CMakeTmp
Run Build Command:"C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe" "cmTC_ac784"
[1/2] Building C object CMakeFiles\cmTC_ac784.dir\testCCompiler.c.obj
FAILED: CMakeFiles/cmTC_ac784.dir/testCCompiler.c.obj
C:\IAR\stm8\bin\iccstm8.exe -o CMakeFiles\cmTC_ac784.dir\testCCompiler.c.obj -c testCCompiler.c
IAR C/C++ Compiler V3.10.1.201 for STM8
Copyright 2010-2017 IAR Systems AB.
Standalone license - IAR Embedded Workbench for STMicroelectronics STM8, 8K KickStart Edition 3.10
Command line error: Unexpected command line arguments:
-c
ninja: build stopped: subcommand failed.
I checked all output produced with --trace-expand
flag several times and did not find anywhere this -c
flag. I even looked to CMake sources, but this is beyond my head. Where is this flag defined and how can I turn it off?