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
0
votes
1 answer
How to build and deploy an external library with CMake
I would like to use and deploy an external library in my program.
My project's structure is as follow (simplified):
ProjectDir
|_ _build
|_ CMakeLists.txt
|_ Src
| |_ CMakeLists.txt
| |_ .h and .cpp files
|_ ThirdParty
…

user19334409
- 17
- 3
0
votes
0 answers
Getting environment variable during runtime from file in cmake
On the disk I have a file VERSION with in it the version number this is used in CMakeLists.txt means of
include(version)
where the version.cmake has as content:
file (STRINGS "${TOP}/VERSION" VERSION)
set(ENV{VERSION} "${VERSION}")
The so created…

albert
- 8,285
- 3
- 19
- 32
0
votes
1 answer
Force custom command to always run without first deleting the output
I have a setup where I use a custom command to check the current hash of a git repository so that other commands can clone it if it has updated
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/module_VERSION.txt
COMMAND…

Jon Burr
- 97
- 7
0
votes
0 answers
Build generated source files after specific custom target build to create objects
I have a multiple source files getting generated using custom command and custom target in the cmake_binary_dir. These source files are not getting build as they are generated during buildtime. I don't want to use execute_process to create the…

deb
- 15
- 7
0
votes
1 answer
Alternatives for CMake commands
I am new to CMake and was going through the CMake documentations and tutorials. I was able to understand that the target_include_directories command is just the -I option for the compiler (gcc for me). I tried doing it adding the directories…

Pisers
- 103
- 5
0
votes
0 answers
How to make CMake custom target trigger only for some dependencies?
I have a CMake custom target that depends on an input file and a program, like this:
add_custom_command(
OUTPUT generate
COMMAND install generate
)
add_custom_command(
OUTPUT header.h
DEPENDS generate header.txt
COMMAND generate…

sycc90
- 83
- 6
0
votes
0 answers
How to create a dependency for a FILES install in cmake
I have a custom target & custom command in my CMakeLists.txt to build a .jar of the wrapper for the c library which is the main focus of the project. I am using install(FILES ...) (because even if I specify ARCHIVE with install(TARGETS ...) cmake…

msc
- 1,549
- 2
- 12
- 19
0
votes
1 answer
How can I build a fatbin file using CMake?
I want to build a fatbin file from my .cu source file, using CMake.
I've tried this:
add_library(dummy_lib OBJECT my_src.cu)
set_property(TARGET dummy_lib PROPERTY CUDA_PTX_COMPILATION ON)
add_custom_command(
TARGET dummy_lib POST_BUILD
COMMAND…

einpoklum
- 118,144
- 57
- 340
- 684
0
votes
1 answer
How do I get a generator-expression file's basename?
Here's a custom command we find in the CMake documentation:
add_custom_command(
TARGET foo POST_BUILD
COMMAND someHasher -i "$"
-o "$.hash"
VERBATIM)
suppose that, instead of adding…

einpoklum
- 118,144
- 57
- 340
- 684
0
votes
1 answer
cmake add_custom_command pre_build
I am writing cmake example for the first time.
Here is a part of CMakeFiles.txt:
add_custom_command(
OUTPUT ${CODEGEN_SRC}
PRE_BUILD
COMMAND ${CODEGEN_CMD} ${SERVICE_XML} --generate-cpp- code=/home/hello/include/gen/testGenCode
COMMENT…

JungWoo
- 15
- 1
- 4
0
votes
1 answer
Find a CMake file-generating add_custom_command example in which DEPENDS option is necessary
I want a simple example to illustrate the DEPENDS option of file generating add_custom_command(OUTPUT ...), that is, if we comment the DEPENDS part, the example will give different output or totally crash.
In the following example (there are files…

Neymar87
- 145
- 1
- 7
0
votes
0 answers
Run Windows batch script in POST_BUILD command even when generating on Linux machine
I'm using Visual Studio 2019 combined with CMake to cross compile my project on both PC environment (generating .sln file) and remote Linux machine (Generating Makefile file). I'm switching between the environments using Visual Studio's Cross…

Alon Adler
- 3,984
- 4
- 32
- 44
0
votes
1 answer
add_custom_command: Remove redirected output on failure
Consider the following custom command (latest CMake + ninja):
add_custom_command(
OUTPUT
${OUTPUT}
COMMAND
${Python3_EXECUTABLE} script.py ${INPUT} > ${OUTPUT}
DEPENDS
${INPUT}
…

Amir Gonnen
- 3,525
- 4
- 32
- 61
0
votes
0 answers
Error in condition check inside add_custom_command of CMAKE
I am trying to write unit test cases using CMAKE ctest .
I want to do unit test on my custom add and inverse function.
The difference between add and inverse test cases
add is using two inputs where as inverse is using single input
Address of the…

jailaxmi k
- 89
- 3
- 11
0
votes
0 answers
CMake command in add_custom_command failing to run
As part of the configuration step of my CMake-based program, I download a program into a subfolder of CMAKE_BINARY_DIR, which is then invoked as part of an add_custom_command() to generate some source files at build time.
However, when running make…

Paul Belanger
- 2,354
- 14
- 23