[CMake] FIND_PROGRAM Question.
Brad King
brad.king at kitware.com
Wed Mar 30 08:17:17 EST 2005
Lars Pechan wrote:
> Hi there,
> I have a question about using the results of a FIND_PROGRAM on Windows.
>
> I have a couple of FIND_PROGRAMS going to locate cat and awk (available
> from the UnixUtils pkg).
>
> They work fine a return a Unix-style path, i.e.
> ${CAT} = G:/UnixUtils/usr/local/wbin/cat.exe and
> ${AWK} = G:/UnixUtils/usr/local/wbin/gawk.exe.
>
> I then use these in a custom command like so:
>
> ADD_CUSTOM_COMMAND(
> OUTPUT ${SOMEWHERE}/Somefile.txt
> COMMAND ${CAT}
> ARGS aFile | ${AWK} -f bFile > ${SOMEWHERE}/Somefile.txt
> DEPENDS aFile bFile
> )
>
> Now, CMake (CMakeCVS built 28/3/5) creates this Makefile:
>
> G:\UnixUtils\usr\local\wbin\cat.exe aFile |
> G:/UnixUtils/usr/local/wbin/gawk.exe -f bFile ...
>
> The problem is that CMake correctly generates a correct Windows path for
> the COMMAND argument but not so when another FIND_PROGRAM entity exists
> in the ARGS?
>
> Is there any simple way around this? Is it a bug? Wouldn't it make sense
> if whenever the result of FIND_PROGRAM is used it is modified for the
> target platform? (as is the case for ${CAT} above but not ${GAWK}.
This is not a problem with FIND_PROGRAM. CMake always uses forward
slashes internally and then converts to the appropriate output path when
it generates the Makefile. The problem is that it can only convert
slashes on the COMMAND part of a custom command. As far as it knows the
rest of the arguments are just strings because right now CMake's
language is untyped.
This is usually not a problem because forward slashes are supposed to be
valid on Windows when naming files. They are not valid when naming
executables to run which is why CMake converts the COMMAND portion.
Since you are using the pipe syntax then the path to awk should be
converted also but CMake has no idea it needs to do this. Converting
the language to have types could solve the problem but that is not in
the short term plans. Recognizing the pipe syntax and converting the
argument after the pipe is probably a better short term solution.
Please submit this as a feature request here:
http://www.cmake.org/Bug
Meanwhile I suggest you find another way to generate Somefile.txt. The
whole point of CMake is to not depend on a huge number of unix tools
like cat and awk. You might be able to get what you want by writing a
custom command like
COMMAND ${CMAKE_COMMAND}
ARGS -P ${CMAKE_CURRENT_BINARY_DIR}/myconvert.cmake
where myconvert.cmake is a CMake script that has been configured with
the proper input/output paths. The script can contain FILE and STRING
commands to read, process, and write Somefile.txt.
-Brad
More information about the CMake
mailing list