Question about add_custom_command

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

It says: " If COMMAND specifies an executable target name (created by the 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

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

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?

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

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.

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

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.