I work on a big Cortex-M project with arm-none-eabi-gcc, cmake and ninja-build.
The current build process is a bash script which consists of 4 parts:
Execute pre-cmake-build bash instruction (also here, some files are generated EVERY TIME like git_version_info.h etc)
Execute cmake β¦
Execute ninja
Execute post-cmake-build bash instructions
Now what i want to achieve is moving part 1 and part 4 into a pre and post build bash script, and remove the other one, so i can make it work with CLion.
Im terribly failing to find a command for cmake that lets me execute a bash script:
A.) every time a build, even if there is no change in coding
B.) that actually PRE_BUILD executes.
add_custom_command does not work, as PRE_BUILD is equal to PRE_LINK, therefore the build fails since header files are missing.
Can someone help me write this cmakelists file so the bash script will actually execute BEFORE cmake generates files and ninja executes the compilation?
You can make a command run βalwaysβ by listing an output that never gets created. Something like this:
add_custom_command(
OUTPUT
"${CMAKE_CURRENT_BINARY_DIR}/version.h"
"${CMAKE_CURRENT_BINARY_DIR}/version.h.noexist"
COMMAND
mkversion)
# "Attach" a single target to this command. Directly depending on
# version.h from multiple targets is not supported in Visual Studio.
add_custom_target(version.h
DEPENDS
"${CMAKE_CURRENT_BINARY_DIR}/version.h")
# For each direct consumer of the header.
add_library(foo foo.c)
add_dependencies(foo version.h)
You wanted it to run unconditionally. That makes that happen. Compared to a plain custom target? Itβs probably similar, but itβs easier to make chains of commands with add_custom_command, so I just do that then βcapβ it off with a user-facing custom target.