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
1
vote
1 answer
CMake rebuilts custom target despite no sources having changed
I'm using a custom target in a CMake file of mine, which looks like this:
add_custom_target(generated_bar
COMMAND ${CMAKE_COMMAND} -DOUT=bar -P generate-bar.cmake
BYPRODUCTS bar
COMMENT "Generating bar from foo"
SOURCES foo)
This…

einpoklum
- 118,144
- 57
- 340
- 684
1
vote
1 answer
CMake custom command to generate a non-config file
I've read:
cmake custom command to copy and rename
and I want to do something similar, but rather than copying a file, I want to generate a file. If that wasn't in a custom command, I would write:
file(WRITE "generated.c" "int main() { return 0;…

einpoklum
- 118,144
- 57
- 340
- 684
1
vote
1 answer
How can I use library in cmake-base project if sources and CMakeLists.txt file for this library I have to generate by external tool
I have to generate sources by external tool (I generate c++ classes from IDL-files for fastDDS messages), this tool also generate CMakeLists.txt file that allows me to compile generated files to .a file.
In my big superproject for one…

Егор Волков
- 55
- 5
1
vote
1 answer
recursive search in cmake post build
I want all the files with a particular extension in CMake in a directory. These extension files are generated post running the build.
I tried
file(GLOB_RECURSE GCOV_OBJECTS $ENV{OUTPUT_UT_DIR} *Test.cpp.o)
But this is getting executed before…

Jim Moriarty
- 141
- 1
- 5
- 12
1
vote
1 answer
cmake add_custom_command introduces false dependency unless add_custom_target also used
I'm using cmake to build some libraries, all of which generate some of their files.
I've created the generated files using add_custom_command(), but I've discovered something which seems like a false dependency. If a downstream library has a…

Rick
- 11
- 1
- 3
1
vote
1 answer
How to build and add a dependency library in CMake
For my project, I need to build and include another library, https://github.com/t-dillon/tdoku/, as my dependency.
Toku is also built using CMake, and there's a build script I can run by doing:
$ cd lib/toku
$ ./BUILD.sh
This puts the library file…

simonzack
- 19,729
- 13
- 73
- 118
1
vote
0 answers
CMake replaces part of absolute path to command with relative "../../" in add_custom_target
I'm trying to add a custom target to my cmake setup. It's needed as I want to execute particular tool with a set of arguments. The executable itself is prebuild and located in the repo which I want to build (so there is explicit .exe in repo, it's…

eciu
- 163
- 2
- 2
- 6
1
vote
1 answer
Creating a git commit id file in the project build folder using CMake
First, I define the COMMIT_ID variable:
execute_process(COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE COMMIT_ID )
If you specify the COMMIT_ID variable the project is not built:
…

Олег Привалов
- 171
- 2
- 14
1
vote
1 answer
CMake object files of executable in custom command
I have a custom command that is executed in the pre linking stage.
What I want to do is calculate a checksum of all parts that are going to be part of my executable. Then I want to link link this checksum as a global variable into my executable.
So…

sfs
- 21
- 4
1
vote
1 answer
Defining dependency between custom commands in different directories
I have a project in which the output of one custom command is used as the input to another, but in a different directory. So for example:
Directory lib/CMakeLists.txt contains:
add_custom_command(
OUTPUT libfoo.xx
COMMAND

Talin
- 1,397
- 2
- 15
- 30
1
vote
1 answer
cmake 3.15 adding JOB_POOL to add_custom_command SOMETIMES
For users that are using cmake 3.15 or later and are also using Ninja as a generator, I want to set the new JOB_POOL argument to some large add_custom_command() blocks. For other users, I want to keep my add_custom_command() the same (no…

Lance E.T. Compte
- 932
- 1
- 11
- 33
1
vote
1 answer
Does CMake's add_custom_command delete its first output sometimes?
In my CMake file I have a custom command which calls some external code generation. The generated files are stubs for the user to put his/her own code into. Thus, the code generation makes sure not to overwrite already existing files. My custom…

bjhend
- 1,538
- 11
- 25
1
vote
1 answer
edit .bat using cmake or cpack
I made an installer for my software using cmake and cpack.
in the cpack installer the user chose where to install the software.
let's say C:\Users\MySoftware
all my .exe and a python file go in it using the Destination option of cmake.
using cpack,…

p.deman
- 584
- 2
- 10
- 24
1
vote
1 answer
add_custom_command does not re-run on failure
In CMake, I would like to use add_custom_command(... POST_BUILD ...) with a COMMAND that might fail.
Observation
Running make will fail the first time, because the exit code of add_custom_command( ... COMMAND exit 1) is not 0. --> This is what I…

Unapiedra
- 15,037
- 12
- 64
- 93
1
vote
1 answer
add_custom_command depending on another add_custom_command
We have two add_custom_command clauses, where one depends on the other:
The first command compiles an .osl source file into an .oso object file using the oslc compiler:
set (oslc ${PROJECT_SOURCE_DIR}/sandbox/bin/oslc)
add_custom_command (
…

François Beaune
- 4,270
- 7
- 41
- 65