我注意到CMake安装了许多模块,例如IAR编译器:
https://github.com/Kitware/CMake/blob/master/Modules/Compiler/IAR.cmake
在之前的一个问题中,我问过如何加载这个特定的模块。答案只是补充:
set(CMAKE_C_COMPILER iccarm.exe)
在CMakeLists.txt
上。
不幸的是我注意到,这还不够,因为IAR.cmake
从未真正使用过。使用以下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}")
我得到了这个输出:
-- 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
未定义IARARM_CMAKE_LOADED
且CMAKE_C_COMPILE_OBJECT
未定义--silent
选项here
如何告诉CMake使用IAR模块?
答案 0 :(得分:1)
我慢慢开始意识到这些问题。
CMakeLists.txt
文件中定义编译器。你在命令行上添加它们作为参数,如cmake -DCMAKE_C_COMPILER=iccarm.exe ...
编译器检测通常发生在触摸CMakeLists.txt
文件之前添加下次用于调用CMake的版本和命令行。你也有一些选项,如--trace-expand
,可以让你知道发生了什么(不)。