# Question about add\_custom\_command

**URL:** <https://discourse.cmake.org/t/question-about-add-custom-command/2489>\
**Category:** Code\
**Created:** [January 6, 2021, 11:01pm UTC](https://discourse.cmake.org/t/question-about-add-custom-command/2489 "2021-01-06T23:01:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ceanwang](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ceanwang/32/1075_2.png) [@ceanwang](https://discourse.cmake.org/u/ceanwang)\
**Post date:** [January 6, 2021, 11:01pm UTC](https://discourse.cmake.org/t/question-about-add-custom-command/2489/1 "2021-01-06T23:01:12Z")

</div>

Hi,

I am building with cmake + gnu c/c++ (MINGW) under Windows 10. I use add\_custom\_command to let a program (the name is ‘fluid’) to compiler some other resource files. Like this:  
add\_custom\_command(  
OUTPUT “${basename}.cxx” “${basename}.h”  
COMMAND fluid -c ${CMAKE\_CURRENT\_SOURCE\_DIR}/${src}  
DEPENDS ${src}  
MAIN\_DEPENDENCY ${src}  
)  
The program is built by that project.  
add\_subdirectory(fluid)  
set(FLTK\_FLUID\_EXECUTABLE fluid)  
set(FLUID fluid) # export

From here [add\_custom\_command — CMake 3.19.2 Documentation](https://cmake.org/cmake/help/latest/command/add_custom_command.html)

It says: " If `COMMAND` specifies an executable target name (created by the [`add_executable()`](https://cmake.org/cmake/help/latest/command/add_executable.html#command:add_executable) command), it will automatically be replaced by the location of the executable created at build time if either of the following is true:"

The problem I have is that the program is replaces in an relative path, something like this: …/myfolde/fluid.exe, but this can’t be executed in a DOS terminal.

My question is how can I let it in absolute path way?

Regards,

Cean

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [January 7, 2021, 5:17pm UTC](https://discourse.cmake.org/t/question-about-add-custom-command/2489/2 "2021-01-07T17:17:42Z")

</div>

You can use `$<TARGET_FILE:fluid>` which should get the full path. Though I’d expect the slashes to be output in the right way anyways…

@brad.king

---

<div class="post-metadata">

**Author:** ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)\
**Post date:** [January 7, 2021, 5:36pm UTC](https://discourse.cmake.org/t/question-about-add-custom-command/2489/3 "2021-01-07T17:36:55Z")

</div>

The use of `/` or `\` in the generated build system depends on what generator is being used. It corresponds to whatever direction is preferred by the corresponding `make` tool and its shell.

@ceanwang what generator are you using?

---

<div class="post-metadata">

**Author:** ![ceanwang](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ceanwang/32/1075_2.png) [@ceanwang](https://discourse.cmake.org/u/ceanwang)\
**Post date:** [January 7, 2021, 10:59pm UTC](https://discourse.cmake.org/t/question-about-add-custom-command/2489/4 "2021-01-07T22:59:31Z")

</div>

I am using “Unix Makefiles”, but under Windows 10 to compile with gnu c/c++. Maybe this is the problem.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [January 8, 2021, 12:32am UTC](https://discourse.cmake.org/t/question-about-add-custom-command/2489/5 "2021-01-08T00:32:51Z")

</div>

That probably is the problem. That should work under a Cygwin environment (with a Cygwin build of CMake), but the `NMake Makefiles` may also work better? The `Ninja` generator is probably your best bet though.

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [January 8, 2021, 11:05am UTC](https://discourse.cmake.org/t/question-about-add-custom-command/2489/6 "2021-01-08T11:05:50Z")

</div>

If you want to stick with Makefiles, you should use MinGW Makefiles generator.

---

<div class="post-metadata">

**Author:** ![ceanwang](https://discourse.cmake.org/user_avatar/discourse.cmake.org/ceanwang/32/1075_2.png) [@ceanwang](https://discourse.cmake.org/u/ceanwang)\
**Post date:** [January 9, 2021, 12:47am UTC](https://discourse.cmake.org/t/question-about-add-custom-command/2489/7 "2021-01-09T00:47:00Z")

</div>

Use MinGW Makefiles solved the problem.

Its writes out is .\myfolde\fluid.exe and this form could be run under DOS terminal.

Thanks all for the help.
