A mechanism in CMake allowing users to define build steps other than compiling libraries and linking executables, supporting a more generalized concept of a build. Involves the add_custom_command and add_custom_target commands.
Questions tagged [cmake-custom-command]
104 questions
5
votes
2 answers
CMake: how to use if condition in add_custom_command(...)
I want to use Linux if condition in CMakeLists.txt by add_custom_command(...) for i need run these if condition and do some judgement in makefile. Like this:
cmake_minimum_required(VERSION 2.8)
add_custom_target(temp_target…

Chao Zhang
- 190
- 2
- 15
5
votes
1 answer
cmake add_custom_command not working
I am trying to run gperf from a cmake file.
I created a very minimal CMakeLists.txt below.
When I run it by
$ cmake .
$ make
It does not create the example.hpp file
What could be problem with the below CMakeLists.txt?
cmake_minimum_required(…

Sri Kant
- 169
- 1
- 12
5
votes
0 answers
CMake/CPack: add_custom_command TARGET package POST_BUILD
Having the same problem as here described, I want to execute a shell script as a POST_BUILD command of TARGET "package". Target platform is Debian/Ubuntu.
I add following to the end of my CMakeLists:
add_custom_command(
TARGET package
…

Polybos
- 51
- 3
5
votes
2 answers
add_custom_command -- update dependency list over rebuilds
See last status update
Initial conditions
code generator that generates set of c++ sources taking one input file as parameter
input file may include other input files
already solved task of getting list of output files, parsing input codegen files…

Konstantin
- 51
- 5
3
votes
0 answers
How to correctly quote CMAKE Join Generator expressions
Consider a target with compile options and include files:
target_compile_options(Tutorial PRIVATE /DC=1)
target_compile_options(Tutorial PRIVATE /DD=2)
target_include_directories(Tutorial PRIVATE "include…

Brad
- 3,190
- 1
- 22
- 36
3
votes
1 answer
Dealing with lots and lots of escaped characters in add_custom_command
I have a file that contains a bunch of data. I want to turn it into a C++ string literal, because I need to compile this data into the binary - I cannot read it from disk.
One way of doing this is to just generate a C++ source file that declares a…

Barry
- 286,269
- 29
- 621
- 977
3
votes
2 answers
CMake post-build output command with print
I'm using CLion 1.2 to build an embedded C project for an STM32 target. Cross compilation using GNU ARM tools works well, however, I would like to run arm-none-eabi-size after the executable file has been built, and have the output of that command…

WoodyWoodsta
- 160
- 2
- 15
3
votes
1 answer
When is cmakes add_custom_command POST_BUILD being triggered?
Lets consider that I have registered a custom command for a target:
add_custom_command(TARGET ${target_name} POST_BUILD
COMMAND cmake -E copy_if_different ${file_path} ${dest_file}
COMMENT "exporting…

tssch
- 734
- 8
- 25
3
votes
1 answer
cmake: add_custom_command only invoked first time
I'm running into a problem with add_custom_command for a custom target (created using add_custom_target).
My general idea is to incorporate a static code analysis tool into the cmake tool-chain. My solution is based on the one described here:…

Max
- 97
- 2
- 7
2
votes
2 answers
cmake add_custom_command is aways out of date
I have the problem that add_custom_command is always out of date and therefore runs on every build. the custom command runs a tool that is a target of the same project to generate a file that is used by another target:
add_executable(GeneratorTool…

Jochen
- 754
- 7
- 21
2
votes
0 answers
Xcode 13.4.1 error: Requested but did not find extension point with identifier Xcode.IDEKit.
We are building an application that would be cross-platform and hence using CMake as the build system: Getting the below error when code signing is allowed using XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "Yes"
Command CodeSign failed with a nonzero exit…

Karan Dixit
- 37
- 2
2
votes
1 answer
Expand variable name containing a generator expression in cmake
In the build process, I set directories where I gather the build output of different sub-projects. The directories are set as :
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_LIST_DIR}/../build/bin/debug" )
set(…

Joma
- 2,334
- 2
- 20
- 25
2
votes
0 answers
CMake: how to handle add_custom_command sub-builds when building with Ninja
I'm using CMake to build a C++ project (on Linux). The project consists of numerous sub-projects, each of which may invoke a function to create a useful link_date.c source file, which contains the timestamp when the link took place. I use this as a…

davidA
- 12,528
- 9
- 64
- 96
2
votes
1 answer
Source doesn't exist yet for target depending on custom target using source generated by add_custom_command
I am trying to port a meson project to CMake. I have the following subdirectories in my main CMake file:
add_subdirectory(protos)
add_subdirectory(qtlayershell)
add_subdirectory(demo)
and the following in protos/CMakeLists.txt:
set(PROTOCOLS
…
user10146018
2
votes
2 answers
CMake: Regenerate source file if target gets rebuilt
I am trying to embed the build date into a source file, so that every time a specific target gets built, the embedded date is refreshed, without regenerating every time the overall project built.
I.e. I have a header file builddate.h that is…

villintehaspam
- 8,540
- 6
- 45
- 76