Questions tagged [cmake-custom-command]

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.

104 questions
2
votes
1 answer

CMake add_custom_command replaces slash with backslash on windows

I'm trying to create a conan-package (hint: the names contain forward-slashes) as a postbuild operation with something like this: add_custom_command( TARGET ${PROJECT_NAME} POST_BUILD WORKING_DIRECTORY ${PROJECT_DIR} COMMAND conan…
zeroflag
  • 21
  • 2
2
votes
1 answer

CMake generating additional code around add_custom_command()'s command

Running into issues with a CMake POST_BUILD command. Whenever I try to build my CMake project (libFDSequencer) I error out with a pseudo-random error code (anything between 123 and 9009). I have narrowed down the root of the problem to the fact that…
2
votes
0 answers

cmake : add_custom_command : why it add "setlocal..."?

I use cmake to generate a VS 2017 solution. I use "add_custom_command" to add a post build event. The problem is that it add some quotes around my command code, and this make my script failing ! Do you know why ? And how to get rid of it ? Here is…
CDZ
  • 813
  • 1
  • 11
  • 27
2
votes
1 answer

In cmake, how can I always execute a process? (or capture stdout from add_custom_command)

I am using generated files in my cmake project. I have a script that generates source code from some input, and the same script can also validate the input, if given a different command line argument, like this: generate_code.py…
Drew
  • 12,578
  • 11
  • 58
  • 98
2
votes
1 answer

How to use add_custom_command to copy dlls using generator expressions?

I have to copy dll's in my solution at the compile time , so i am using add_custom_command for that as follows: function(dll_dependencies TEST_CASE ) foreach(depencency ${ARGN}) add_custom_command(TARGET ${TEST_CASE} POST_BUILD …
Learner
  • 453
  • 13
  • 29
2
votes
1 answer

CMake: Add a compilable file type

I am compiling code for an embedded system. The system is the Parallax Propeller for anyone curious, but you do not need to be familiar with it to answer my question. The custom version of GCC (propgcc) has a new input and output file type: a .cogc…
DavidZemon
  • 501
  • 5
  • 21
1
vote
2 answers

How can I write an int to a file as bytes in CMake?

Is there a native way in CMake to write an int to a file as bytes? E.g. file(SIZE generated_file.txt file_size) # file_size == 465435 file(WRITE output.txt "${file_size}" Where I would like ${file_size} written as a fixed number of bytes (E.g. 4)…
Matt Stokes
  • 4,618
  • 9
  • 33
  • 56
1
vote
0 answers

add_custom_command for a target is always executing

This is a simplification of another problem. But it boils down to the last add_custom_command (one which appends), which I want to only execute when the target T1 is build. However currently the problem is that every time I run make, the Appending…
Arjob Mukherjee
  • 387
  • 1
  • 10
1
vote
2 answers

cmake add_dependencies, add_custom_command and add_custom_target not working together

I have been trying to get the simple use case of getting cmake to to generate some files with a script and then build an executable out of those generated files. After spending hours reading the documentation and various stack overflow answers, it…
1
vote
1 answer

CMake link library from find_package with system lib in wrong order

my CMakeLists.txt is as follows find_pacakge(something) add_executable(exe main.cc) # libsomething depends on dlopen/dlsym... so I have to add dl here target_link_libraries(run PRIVATE something::something dl) results: g++ -o exe -ldl…
Bigcat
  • 100
  • 5
1
vote
2 answers

How to call a function at start and end of building a target in cmake

I'm looking for a way to execute shell code when starting and finishing the build of a target in cmake. The final goal is to send a message to a data tracking tool indicating when builds start and finish. So for example, if "make" build targets…
Spacemoose
  • 3,856
  • 1
  • 27
  • 48
1
vote
1 answer

How to run different add_custom_command for each specific target?

I work with Visual Studio and have different paths to work for different configurations (Debug, Release): if(WIN32 ) set(static_release ${my_lib}_release/SomeLibrary.lib) set(static_debug ${my_lib}_debug/SomeLibrary.lib) endif(WIN32) Then I…
1
vote
0 answers

Perform git patch and unpatch before and after cmake build

I have a project for which I want to apply a patch to a git repo before building the code, then unapply that patch after creating the executable. The reason being that I want the patch applied to the build but I want the repository that is patched…
Jeff L
  • 491
  • 5
  • 14
1
vote
1 answer

Do I always need a target in CMake?

I have a python script, which generates some files for me, and in my script, I have an argument --outputdir to specify the location of output files. I want to run this script to generate these files and install them later. I…
code3
  • 81
  • 1
  • 8
1
vote
1 answer

How to force a target to be rebuilt if a dependent script is updated?

I am written some custom scripts that are invoked in custom commands for CMake targets. I want the targets to be rebuilt if any of the scripts are updated (e.g. touch script.sh). I have tried several variations using the DEPENDS argument, but…
MarkB
  • 672
  • 2
  • 9