CMake 101 (Part 1)

by Tsvi Mostovicz - Thu 19 March 2020
Tags #Scripting
Reading time: 1 minute, 41 seconds

Following the tutorials

Obviously, the first thing to do is to follow the existing tutorials. Unfortunately, most of them will show you how to compile some code into a single executable.

What I need is something that will run a specific custom command. I don't use the GCC toolchain. These tools are proprietary.

Some Google-fu later, I discover the following resources:

  • https://github.com/tymonx/logic - this guy seems to have done an incredible job
    might be a good place to look for some pointers although I wouldn't use it as is as I want to ease my way into this and keep most of the things as they were.
  • What do you know? There's a add_custom_command and add_custom_target

So my first try at a CMakefile.txt goes as follows:

cmake_minimum_required(VERSION 3.14)

# set the project name and version
project(my_project VERSION 8.0.0)

# find the path to the xrun command
find_program(XCELIUM_XRUN xrun
    PATH_SUFFIXES bin ${XCELIUM_PATH_SUFFIXES}
    DOC "Path to the xrun executable"
)

# add "compile" target which runs xrun -version
add_custom_command(OUTPUT xcelium.d
    COMMAND ${XCELIUM_XRUN} -version)

add_custom_target(compile ALL
    DEPENDS xcelium.d)

This works nicely. Not sure if xcelium.d is the correct output definition. But running:

$ cmake3 ..
$ make

Shows the following:

[100%] Generating xcelium.d
TOOL:   xrun    19.09-s001
[100%] Built target compile

Next step. Get the file list we currently use to pass it with a bunch of flags to xrun.

Comments