[CMake] Specifying different compilers for subsets of a project
Marcel Loose
loose at astron.nl
Wed Oct 15 04:54:48 EDT 2014
Hi George,
You could (ab)use the "assembler plugin" system for that. Define your
own CMake-ASM-BGQ*.cmake files and use the assembler to compile the
sources.
Here's how I did this a couple of years ago for the BG/P.
In the CMakeLists.txt file for the files that need to be compiled with
the BG/P compiler I have:
## ---------------------------------------------------------------------------
## Enable BGP specific assembler.
## Use the BGP assembler also for linking C/C++ programs.
## ---------------------------------------------------------------------------
enable_language(ASM-BGP)
set(CMAKE_C_LINK_EXECUTABLE ${CMAKE_ASM-BGP_LINK_EXECUTABLE})
set(CMAKE_CXX_LINK_EXECUTABLE ${CMAKE_ASM-BGP_LINK_EXECUTABLE})
CMakeASM-BGPInformation.cmake:
set(ASM_DIALECT "-BGP")
set(CMAKE_ASM${ASM_DIALECT}_SOURCE_FILE_EXTENSIONS S)
set(CMAKE_ASM${ASM_DIALECT}_COMPILE_OBJECT "<CMAKE_ASM${ASM_DIALECT}_COMPILER> <DEFINES> <FLAGS> -c -o <OBJECT> <SOURCE>")
set(CMAKE_ASM${ASM_DIALECT}_LINK_EXECUTABLE "<CMAKE_ASM${ASM_DIALECT}_COMPILER> <FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
include(CMakeASMInformation)
set(ASM_DIALECT)
CMakeDetermineASM-BGPCompiler.cmake:
set(ASM_DIALECT "-BGP")
set(CMAKE_ASM${ASM_DIALECT}_COMPILER_INIT ${CMAKE_ASM_COMPILER})
include(CMakeDetermineASMCompiler)
set(ASM_DIALECT)
CMakeTestASM-BGPCompiler.cmake:
set(ASM_DIALECT "-BGP")
include(CMakeTestASMCompiler)
set(ASM_DIALECT)
Hope this helps.
Regards,
Marcel Loose.
On 15/10/14 04:23, George Zagaris wrote:
> Dear all,
>
> I am working on a project where on certain platforms, namely, on a
> BG/Q or Cray, we have to cross-compile the code, but still, there are
> parts of the code that should only be compiled for the front end,
> login nodes.
>
> Typically, we have a toolchain file, which among other things sets:
> - CMAKE_CXX_COMPILER
> - CMAKE_C_COMPILER
> - CMAKE_FORTRAN_COMPILER
>
> to the respective cross-compilers available on the target platform.
>
> This compiles everything for the back-end.
>
> The obvious way to compile front-end tools is to create another
> directory, e.g., "front-end-build" and run cmake therein to
> re-configure and build with a front-end compiler.
>
> However, since only a relatively small subset of the files needs to be
> compiled for the front-end, it is desirable to do this within the same
> build, which leads to my question:
>
> Is it possible to tell CMake to build certain files with a different
> compiler? I know there is a way to set file properties to control the
> compiler flags of certain files. Is there a "blessed" approach to
> control the compiler for certain files and/or directories (and avoid
> things like set(CMAKE_CXX_COMPILER...) within a CMakeLists file)?
>
> Thank you very much for all your help.
>
> Best,
> George
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141015/17afa42d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: loose.vcf
Type: text/x-vcard
Size: 292 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake/attachments/20141015/17afa42d/attachment.vcf>
More information about the CMake
mailing list