-
Notifications
You must be signed in to change notification settings - Fork 16
IAR Environment Variables in CMake
Felipe Torrezan edited this page Feb 28, 2024
·
4 revisions
The IAR Embedded Workbench IDE classic project format (*.ewp
) provides internal environment variables such as for "Project directory" ($PROJ_DIR$
) or for "Product directory" ($TOOLKIT_DIR$
). These are called "Argument Variables" and are not automatically propagated to CMake projects.
- IAR Argument Variables
get_filename_component()
CMAKE_<lang>_COMPILER
PROJECT_SOURCE_DIR
set()
unset()
It is possible to use CMake Variables to mimic any desired IAR Argument Variables in a CMake Project so that its environment becomes more familiar.
Notice that referencing IAR Argument Variables is syntactically different from referencing CMake Variables:
IAR Argument Variable | CMake Variable |
---|---|
$VARIABLE_NAME$ |
${VARIABLE_NAME} |
- In your
CMakeLists.txt
set the following snippet to extract the parent directory of the selected compiler:
# Set the TOOLKIT_DIR variable for the CMakeLists
get_filename_component(BIN_DIR $ENV{CC} DIRECTORY)
get_filename_component(TOOLKIT_DIR ${BIN_DIR} PATH)
unset(BIN_DIR)
- Then you can use the
${TOOLKIT_DIR}
variable to reference that directory in your CMake project. For example:
target_link_options(MyTarget PRIVATE --semihosting --config ${TOOLKIT_DIR}/config/generic.icf)
- In CMake,
PROJECT_SOURCE_DIR
can be used to emulatePROJ_DIR
:
set(PROJ_DIR ${PROJECT_SOURCE_DIR})
- Then you can simply use the
${PROJ_DIR}
variable to reference that directory in your CMake project. For example:
target_link_options(MyTarget PRIVATE --semihosting --config ${PROJ_DIR}/MyCustomLinkerConfiguration.icf)
This is the cmake-tutorial wiki. Back to Wiki Home
- Setting language-specific target options
- Selecting build types
- Using Ninja Multi-Config
- Filing a build log
- Multi-file compilation
- Invoking IAR binary utilities