FlexSEA Wiki

A WEARABLE ROBOTICS TOOLKIT

User Tools

Site Tools


softwaredevtips

Software Hints and Tips

Directions for installing a Windows Development Environment.

Directions for installing a Ubuntu Development Environment.

Directions for installing a Raspberry PI Development Environment.

Adding a custom build step to CMAKE

This tells you how to add a custom build step to a CMAKE based project. If, foir example, you need to force a script to run before the project builds. There is a difference between how you do this for Windows and Linux. Below is the way the revision information is updated before the project is build

## Force generation of the revision header file BEFORE building targets
##  Create a psuedo-target to be created before the library
IF(WIN32)
add_custom_target(
    revisionTarget
    COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/update_revs.bat ${CMAKE_CURRENT_SOURCE_DIR}/include/git_rev_data.h
    COMMENT "Updating revision information"
)
ELSE()
add_custom_target(
   revisionTarget
   COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/update_revs.sh ${CMAKE_CURRENT_SOURCE_DIR}/git-revision.py ${CMAKE_CURRENT_SOURCE_DIR}/include/git_rev_data.h
   COMMENT "Updating revision information"
)

ENDIF()

The above code shows how to add a custom target to a CMakeLists.txt file. This describes how to build the target and adds a descriptive comment while 'make' is running. The next step is to force the project to execute the command before building the target. This is done using the command below.

add_dependencies(serialc revisionTarget)

Adding a custom build step to Eclipse projects

Open the project properties (right-click on the project and select Properties)

Navigate to C/C++ Build → Settings

Click on the Build steps tab and enter the command in the Pre-build steps command

Adding a custom build step to Qt Creator

There is a way to add a custom build step with the GUI. However, this is saved in the xyz.pro.user file. This file is for per-user customization and shouldn't be checked into the repository. There is a way to create a “default” pro-user file but that isn't really the best solution to this problem. If the project is up to date, it will not get the latest revision information and force the build based on that. A better solution is to use the following in the .pro file:

# Update revision information
PRE_TARGETDEPS += git_rev_data.h
QMAKE_EXTRA_TARGETS += revisionTarget
revisionTarget.target = git_rev_data.h
win32: revisionTarget.commands = cd $$PWD && python.exe $$PWD/git-revision.py -o $$PWD/inc/git_rev_data.h
else:  revisionTarget.commands = python $$PWD/git-revision.py -o $$PWD/inc/git_rev_data.h
revisionTarget.depends = FORCE

A couple of notes:

1) You MUST use the CD in the “.commands” line. If you do not, you will not change into the proper sub-module directory. This will prevent GIT from grabbing the latest revision information.

2) You MUST use && despite what you read on the internet. Several examples exist there but they use

 cd $$xyz; 

Notice the semi-colon. This will not work. You will get errors telling you the path is incorrect, etc.

softwaredevtips.txt · Last modified: 2019/03/08 15:17 by dtscbs