Options
The source code for this example can be found in examples/options
SoCMake allow to use options, a script can easily be adapted to fit in a different environnement or to test different tools or features depending on your needs. This allows to make generic and configurable script if you would like to share your work with others.
Let's try to create an example with several options, to demonstrate how to use them.
CMakeLists.txt
We can for example create a file like the following CMakeLists.txt to try the different possibilities:
## Options are used for variables and conditional configuration of the project
## To change an option pass it during configuration with `cmake -DSIM_TYPE=SYNTH ../`
## To print help message for options run `make help_options`
## To see options in gui run `cmake-gui ../`
cmake_minimum_required(VERSION 3.27)
project(options_example NONE)
include("../../SoCMakeConfig.cmake")
option_enum("SIM_TYPE" "Type of simulation to run" "SYNTH;GENERIC" "GENERIC")
option_boolean("SIM_TRACE" "Enable tracing vcd file" OFF)
option_string("SIM_TRACE_PATH" "Output of VCD file in case SIM_TRACE is on" "trace.vcd")
option_integer("SIM_NUM_TESTS" "Number of tests in regression" 1)
option_file("SIM_LOG_FILE" "File path of the output log file" "/tmp/sim_log.txt")
option_directory("SIM_OUTDIR" "Directory path to the simulation artifacts" "/tmp/sim/")
if(SIM_TYPE STREQUAL SYNTH)
# Add Synthesis only files
# ip_sources(${IP} SYSTEMVERILOG <SYNTH_FILES>)
elseif(SIM_TYPE STREQUAL GENERIC)
# Add Generic only files
# ip_sources(${IP} SYSTEMVERILOG <SIM_FILES>)
endif()
help()
Not all the options are taken in account in the files, it's to show how to implement them and the different types available
SoCMake API add 6 new functions for options, that can be of the following type Boolean, Integer, Enum, String, File and Directory.
They are generally composed of the following arguments :
- VARIABLE name of the variable
- DESCRIPTION short description for the variable
- DEFAULT default value of the variable
If using option_enum(), an other argument, a list of strings is needed, between the description and the default value to give the possible values.
SoCMake performs a check to verify that the value passed is an allowed value for Enum, Boolean, Integer types.
Instructions
To run the example we need to create a build directory as always:
mkdir build
cd build
Then when generating the Makefile, we can choose to precise our options, like it's generally done with cmake scripts:
cmake -DSIM_TYPE=GENERIC -DSIM_TRACE=ON ../
the help() function, if used, will create a target called help_options.txt after the configuration. It can be useful if you want to look at the different option and their values without looking in the CMakeLists.txt file
Use cmake-gui or ccmake to modify the configuration options in a visual way.