Closed cnwzhu closed 11 months ago
Yes. By just looking at what you shared here, it seems it cannot find the hc32l19x.h
header file included by the preincluded UserConfig.h
. This means that the --preinclude
seems to be working correctly. Perhaps what is missing is to check where the hc32l19x.h
header file comes from. This header is not supplied by IAR.
But, Actually hc32l19x.h is in Source/CMSIS
Thanks for providing further details. Now this is strange. Your project should be working with CMake the way you intend to. Look at this: it works for me on a very similar scenario in which I tried to replicate your project structure (and requirements) when using the IAR C/C++ Compiler for Arm V9.40.2...
XXX/CMakeLists.txt
:
cmake_minimum_required(VERSION 3.20)
project(XXX LANGUAGES C)
add_executable(XXX)
target_sources(XXX PRIVATE main.c)
target_include_directories(XXX PRIVATE Source/CMSIS Source/UserCode)
target_compile_options(XXX PRIVATE --no_wrap_diagnostics --cpu=Cortex-M0+ --preinclude ${PROJECT_SOURCE_DIR}/Source/UserCode/UserConfig.h)
* `XXX/Source/UserCode/UserConfig.h`:
```c
#include "hc32l19x.h"
XXX/Source/CMSIS/hc32l19x.h
:
#define MACRO 1
XXX/main.c
:
#include "UserConfig.h"
int main() { return MACRO; }
* Configure
felipe-iar@iar ~/XXX $ cmake -Bbuild -GNinja --toolchain iar-toolchain.cmake -- The C compiler identification is IAR ARM 9.40.2 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /opt/iarsystems/bxarm/arm/bin/iccarm - skipped -- Detecting C compile features -- Detecting C compile features - done -- Configuring done (2.2s) -- Generating done (0.0s) -- Build files have been written to: /home/felipe-iar/XXX/build
* Build
felipe-iar@iar ~/XXX $ cmake --build build --verbose Change Dir: '/home/felipe-iar/XXX/build'
Run Build Command(s): /usr/bin/ninja -v [1/2] /opt/iarsystems/bxarm/arm/bin/iccarm --silent /home/felipe-iar/XXX/main.c -I/home/felipe-iar/XXX/Source/CMSIS -I/home/felipe-iar/XXX/Source/UserCode -e --no_wrap_diagnostics --cpu=Cortex-M0+ --preinclude /home/felipe-iar/XXX/Source/UserCode/UserConfig.h --dependencies=ns CMakeFiles/XXX.dir/main.o.d -o CMakeFiles/XXX.dir/main.o [2/2] : && /opt/iarsystems/bxarm-9.40.2/arm/bin/ilinkarm CMakeFiles/XXX.dir/main.o --silent -o XXX.elf && :
A word of caution though about for specifying --preinclude
. The flag works for C
and CXX
but if the target uses ASM
sources, it is a different flag for the IAR Assembler (-P
). Example:
project(XXX LANGUAGES C ASM)
# etc...
target_compile_options(XXX PRIVATE
--cpu=Cortex-M0+
$<$<COMPILE_LANGUAGE:C,CXX>:--preinclude>
$<$<COMPILE_LANGUAGE:ASM>:-P> ${PROJECT_SOURCE_DIR}/Source/UserCode/UserConfig.h)
The Genex above will use the appropriate flag depending on each source file to be built, based on the language, specified by their extension.
Thank you for your reply. I got through by executing the following command
cmake -Bcmake-build-debug -GNinja --toolchain iar-toolchain.cmake
But the other command still gives an error
cmake --build .\cmake-build-debug\ --verbose
The error is
__WEAK
^
"C:\PROGRA~1\IARSYS~1\EMBEDD~1.2\arm\inc\c\assert.h",52 Error[Pe077]: this
declaration has no storage class or type specifier
__ATTRIBUTES void __iar_EmptyStepPoint(void);
^
"C:\PROGRA~1\IARSYS~1\EMBEDD~1.2\arm\inc\c\assert.h",53 Error[Pe065]: expected
a ";"
AdcMskTrigPC15 = 1u<<31,
^
"C:\Users\wang-\Desktop\App_Plc\Source\McuDrivers\inc\adc.h",237 Warning[Pe068]:
integer conversion resulted in a change of sign
AdcMskTrigPC15 = 1u<<31,
^
"C:\Users\wang-\Desktop\App_Plc\Source\McuDrivers\inc\adc.h",237 Warning[Pe066]:
enumeration value is out of "int" range
Hard to tell without going into the project’s details. It might require the compiler's extended keywords support enabled, it might be something else requiring a deeper investigation. In either way, this issue tracker is specific for the cmake-tutorial tutorial and, in fact, it is not a general support forum. For technical support use https://www.iar.com/knowledge/support/request-technical-support/
When I use --preinclude cmake reports an error. The header file I preinclude has dependencies on other header files that can't be found.
my cmake config
` include_directories( ${TOOLKIT}/lib Source/FreeRTOS/include Source/FreeRTOS/portable/IAR/ARM_CM0 Source/McuDrivers/inc Source/RfDrivers Source/CMSIS Source/UserCode )
target_compile_options(XXX PRIVATE $<$:--dlib_config normal>
--cpu Cortex-M0+
--preinclude "${PROJECT_SOURCE_DIR}/Source/UserCode/UserConfig.h"
)
` cmake output
` -- The ASM compiler identification is unknown -- Found assembler: C:/Program Files/IAR Systems/Embedded Workbench 9.2/arm/bin/iccarm.exe -- Warning: Did not find file Compiler/-ASM -- Configuring done (1.1s) -- Generating done (0.0s) -- Build files have been written to: C:/Users/wang-/Desktop/App_Plc/cmake-build-debug
Cannot get compiler information: Failed to run compiler:
include "hc32l19x.h"