[CMake] How to specify $1 for compiler?

Michael Hertling mhertling at online.de
Thu Feb 3 19:31:49 EST 2011


On 02/03/2011 08:30 PM, Jed Brown wrote:
> I need to build a compilation command of the form
> 
>   win32fe f90 -with -options -and source.f -o path/to/source.f.o
> 
> but setting CMAKE_Fortran_COMILER=/path/to/win32fe and
> CMAKE_Fortran_FLAGS="f90 -with -options" does not work because CMake places
> other options in between:
> 
>   win32fe -o path/to/source.f.o -with -options source.f
> 
> which does not work because win32fe needs the compiler to come first.  Note
> that the C compiler seems to place the "-o" options later so
> CMAKE_C_COMPILER=/path/to/win32fo CMAKE_C_FLAGS="cl -with -options" is
> working.
> 
> Is this difference in options placement intentional? Is there a robust way
> to make something be $1 in the command line?

With a Makefile generator, you might use a RULE_LAUNCH_COMPILE property:

SET_TARGET_PROPERTIES(<target> PROPERTIES RULE_LAUNCH_COMPILE "win32fe")

This prepends "win32fe" to the Makefile's command lines which compile
the target's object files. Additionally, the special placeholders in
CMAKE_<LANG>_COMPILE_OBJECT et al. are expanded in those launchers,
so a RULE_LAUNCH_COMPILE property like, e.g.,

myscript <CMAKE_C_COMPILER> -o <OBJECT> -c <SOURCE> <DEFINES> <FLAGS> --

would invoke "myscript" with the defines and the flags moved behind
the source and the object file. The "--" is intended to delimit the
launcher from the actual command line, so "myscript" can take the
parameters up to that mark and ignore the remaining ones in order
to construct an arbitrary command line to execute; see [1,2] for
further examples.

As a last resort, you might manipulate CMAKE_<LANG>_COMPILE_OBJECT.
IIRC, these variables are directory-specific, so you can possibly

SET(CMAKE_Fortran_COMPILE_OBJECT
    "win32fe <CMAKE_Fortran_COMPILER> ..."
)

or

SET(CMAKE_Fortran_COMPILE_OBJECT
    "win32fe ${CMAKE_Fortran_COMPILE_OBJECT}"
)

to define suitable Fortran compilation commands for a directory.

'hope that helps.

Regards,

Michael

[1] http://www.mail-archive.com/cmake@cmake.org/msg29622.html
[2] http://www.mail-archive.com/cmake@cmake.org/msg34148.html


More information about the CMake mailing list