nowox
nowox

Reputation: 29106

How to use a different compiler with CMake (IAR)?

I've noticed that CMake is installed with numerous modules such as the IAR compiler:

https://github.com/Kitware/CMake/blob/master/Modules/Compiler/IAR.cmake

In a previous question I asked how to load this particular module. The answer was just to add:

set(CMAKE_C_COMPILER iccarm.exe) 

on my CMakeLists.txt.

Unfortunately I noticed, this is not enough because the IAR.cmake is never really used. With the following CMakeLists.txt:

cmake_minimum_required(VERSION 3.6)

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_C_COMPILER iccarm.exe)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

list(APPEND src src/main.c)

project("foo" C)

add_executable(foo ${src})

message(STATUS "IARARM_CMAKE_LOADED=${_IARARM_CMAKE_LOADED}")
message(STATUS "IAR CMAKE_C_COMPILE_OBJECT=${CMAKE_C_COMPILE_OBJECT}")

I get this output:

-- The C compiler identification is IAR
-- Check for working C compiler: C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm/bin/iccarm.exe
-- Check for working C compiler: C:/Program Files (x86)/IAR Systems/Embedded Workbench 8.0/arm/bin/iccarm.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- IARARM_CMAKE_LOADED=
-- IAR CMAKE_C_COMPILE_OBJECT=<CMAKE_C_COMPILER> <SOURCE> <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT>
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Ycr/Home/sandbox/cmake

Where IARARM_CMAKE_LOADED isn't defined and CMAKE_C_COMPILE_OBJECT doesn't have the --silent option defined here

How can I tell CMake to use the IAR Module?

Upvotes: 0

Views: 3263

Answers (1)

Norbert Lange
Norbert Lange

Reputation: 1192

I slowly begin to realize the issues.

  • you shall not define the compiler in the CMakeLists.txt file. you add them as argument on the commandline like cmake -DCMAKE_C_COMPILER=iccarm.exe ... Compiler detection usually happens before your CMakeLists.txt file gets touched
  • Are you sure you are using the nightly build, because the file you linked is not in the relased builds but will be included in CMake 3.10

Add the versions and the commandline used to invoke CMake next time. Also you have some options like --trace-expand that should give you an idea what (does not) happens.

Upvotes: 3

Related Questions