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
76
votes
3 answers
CMake add_custom_command not being run
I'm trying to use add_custom_command to generate a file during the build. The command never seemed to be run, so I made this test file.
cmake_minimum_required( VERSION 2.6 )
add_custom_command(
OUTPUT hello.txt
COMMAND touch hello.txt
DEPENDS…

Jonathan Sternberg
- 6,421
- 7
- 39
- 58
27
votes
3 answers
add_custom_command is not generating a target
Perhaps this is impossible and I'm misreading the cmake 3.2 documentation, but I though creating a custom command would create a custom "target" in the Makefile so that I could build the target by invoking the name of the output file. The CMake docs…

Mark Lakata
- 19,989
- 5
- 106
- 123
25
votes
1 answer
How to call a CMake function from add_custom_target/command?
Is it possible to call a CMake function out of an add_custom_target or add_custom_command?
I know I could move the CMake function to a Python (or whatever) script and call it from add_custom_target/command but I would like to avoid having tons of…

Martin
- 968
- 3
- 10
- 19
19
votes
2 answers
cmake add_custom_command
I'm struggling with add_custom_command. Let me explain the problem in detail.
I've these set of cxx files and hxx files. I run a perl script on each of them to generate a certain kind of translation file. The command looks like
perl trans.pl…

Surya
- 1,139
- 1
- 11
- 30
12
votes
2 answers
How to get include directories from a target for use in add_custom_target?
I'm modeling dependencies with target_link_libraries, as is done in this blog post.
target_link_libraries(Foo
LibraryA
LibraryB
)
This is working great, but for various reasons I need to use add_custom_target to preprocess to a file through…

Stradigos
- 814
- 1
- 13
- 29
11
votes
3 answers
CMake: execute a macro/function as the command of add_custom_command
I'm using an external library which provides a CMake function for automatic code generation, to be used in my CMakeLists. The problem is that whenever I modify a CMakeLists then the function is run again, triggering the recompilation of the newly…

Nicola Mori
- 777
- 1
- 5
- 19
8
votes
1 answer
How to add multiple comments in add_custom_command of CMake?
This question is just out of curiosity as I noticed that only the last comment block was being printed.
add_custom_command(
TARGET target_a
POST_BUILD
COMMAND command_A_to_do_something
COMMENT "Comment A"
COMMAND command_B_to_do_something_else
…

sunam
- 181
- 3
- 8
8
votes
2 answers
Cmake: add_custom_command argument based on variable content
I'd like to have a Cmake function to copy some binaries to a specific location. Fo this I have the following function definition :
function ( collect_binaries TARGET_NAME DEST_DIR )
set ( targetsToCopy ${ARGN} )
set ( copy_cmd "COMMAND…

Dmitry
- 1,912
- 2
- 18
- 29
8
votes
1 answer
CMake: add dependency to add_custom_command dynamically
I have a CMake project with many subprojects.
Each of them can use a function I provide to generate a small text file with some certain information (by calling add_custom_command).
At the final step I'd like to combine all those files into one big…

Michał Walenciak
- 4,257
- 4
- 33
- 61
7
votes
2 answers
How do I run a python script every time in a CMake build?
Currently I have a need to run a Python script every time in CMake which generates a .qrc file. I can't use Qt Designer and I have to use CMake.
set(CMAKE_AUTORCC ON) is being used and fails whenever a resource is added or a name is changed, thus…

Anthony
- 71
- 1
- 1
- 5
7
votes
1 answer
CMake: How to add a custom command that is only executed for one configuration?
I want to add a cmake custom command that is only executed when the custom target is build in the Debug configuration while using the Visual Studio multi-config generator. Is there a clean way to do this?
In order to implement this, I first tried…

Knitschi
- 2,822
- 3
- 32
- 51
6
votes
1 answer
Can I manually use CMake's cpp file dependency-scanner in my cmake code?
I am trying to add a custom target with CMake that executes one command for each given .cpp file. The command should only be re-executed when the source file itself or one of the included source files changes. AFAIK to achieve this I need a list of…

Knitschi
- 2,822
- 3
- 32
- 51
6
votes
1 answer
CMake: add_custom_command with PRE_BUILD does not work
In the following CMakeLists.txt file, although I have set an add_custom_command command with PRE_BUILD option, the custom command is not always executed before making the main executable:
cmake_minimum_required(VERSION…

B Faley
- 17,120
- 43
- 133
- 223
5
votes
0 answers
How to Run a Basic `add_custom_command` in CMake
I'm just trying to get a basic CMake example up and running that can run some basic command line commands. I've been researching this for a while and I haven't had any luck. Am I completely using this wrong? Any and all input would be greatly…

Alexander Finney
- 51
- 1
- 4
5
votes
2 answers
CMake add_custom_command with target_link_libraries
For a number of reasons I have to manually generate a static library through a custom command.
However, it seems that the custom command is only executed when a target specifically requests its output files.
If I try to link the generated static…

Svalorzen
- 5,353
- 3
- 30
- 54