[CMake] Adding new language.
Michael Hertling
mhertling at online.de
Mon Mar 14 12:16:41 EDT 2011
On 03/14/2011 03:15 PM, arrowdodger wrote:
> Hello. I'm using CMake as build system for a C/CXX project and i've faced
> the following problem: I need to compile some sources as bytecode for VM.
> This is achieved by using different linker (with different flags) and,
> probably, different compiler. At the moment, the only solution i see is to
> create two new CMake "languages" - BC_C and BC_CXX by setting
> CMAKE_BC_C_{COMPILER,LINK_EXECUTABLE}. Then, i want to set LANGUAGE and
> COMPILE_FLAGS properties on files, which i want to be compiled as bytecode
> and finally define LINKER_LANGUAGE property on target.
> Still, i need the way, to "inherit" all compiler flags and probably linker
> from CXX language, and i don't know how to do it.
>
> Also, if you know how to to implement such thing in better way, please share
> your thoughts.
>
> Thanks in advance.
Besides the introduction of new languages BC_C and BC_CXX - which is a
quite fundamental approach - I can imagine the following alternatives:
1) If there are only a few affected files, you might get along with
custom targets/commands, so at least, you can rely on CMake's
dependency tracking capabilities.
2) If you collect the affected files in a separate directory - which is
probably recommendable anyway - you might set CMAKE_C_COMPILE_OBJECT,
CMAKE_C_CREATE_SHARED_LIBRARY, CMAKE_C_LINK_EXECUTABLE etc. as well
as their CXX counterparts in that directory to whatever suits your
needs, and you can refer to the special placeholders <DEFINES>,
<FLAGS> etc. from within the abovementioned rule variables.
3) You might impose the RULE_LAUNCH_COMPILE/LINK properties on the
affected targets/directories. In this way, you can intercept the
compiling/linking phase at the very last moment in order to, e.g.,
replace the regular compiler/linker with the bytecode one. So, you
can use the entire CMake capabilities w.r.t. tracking dependencies,
setting up flags etc. while having the necessary modifications done
just before compiling/linking takes place. The downside is that the
RULE_LAUNCH properties are limited to the Makefile generators. See
[1,2,3] for examples.
'hope that helps.
Regards,
Michael
[1] http://www.mail-archive.com/cmake@cmake.org/msg35215.html
[2] http://www.mail-archive.com/cmake@cmake.org/msg34375.html
[3] http://www.mail-archive.com/cmake@cmake.org/msg34148.html
More information about the CMake
mailing list