Specifying both native and cross compiler at the same time

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Specifying both native and cross compiler at the same time

Mojca Miklavec
Hi,

I would like a build setup for a project to work correctly for both native and cross compilation, however one part requires native compilation and execution of the binary to generate some data tables as part of the build process (the temporary native binary is then discarded / not installed).

What I seem to be unable to figure out is how to specify the compiler(s) and flags separately for the native and cross compiler. I want them to be specified by the user or package manager rather than the author of cmake files.

One particular problem is when cross-compiling on mac with mingw (gcc) while using clang as the native compiler (the two compilers have incompatible flags).

How can I specify two sets of compilers and flags at configure time? (The same question puzzles me in autoconf world as well. Please don't say that the native compiler should be found automatically as I really need to specify which one to use, ancient systems don't have support for C++11 with the default compiler etc.)

Thank you very much,
    Mojca


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake
Reply | Threaded
Open this post in threaded view
|

Re: Specifying both native and cross compiler at the same time

Lassi Niemistö

Hello,

 

I spent a lot of time figuring out how to support multiple compilers in parallel. Here is how I did it:

 

·        Write a toolchain file for each of your compiler setups. Specify any toolchain specific compiler flags there. See https://cmake.org/cmake/help/v3.14/manual/cmake-toolchains.7.html

·        Write one top-level CMakeLists which

o   Calls cmake for your actual CMakeLists with execute_process and each time specify different –DCMAKE_TOOLCHAIN_FILE and different build directory

o   Implement a mechanism how the actual cmake tree can publish target names to top-level. I wrote them to a file in the root of build directory. Of course you can also hardcode the target names on top-level but a dynamic mechanism makes it less cluttered.

o   In the top-level cmake, after generating the architecture specific trees, read the published targets and add a custom target for each of the published targets from the architecture specific trees. Each custom target just calls make in the respective architecture specific build directory.

 

The other point, using the compiled binary as part of the compilation is not necessarily very good idea (sounds like chicken-egg to me). Could you instead compile the native binary separately and put it as a “released version” somewhere and use the last released version in your compilation phase.

 

The “cmake way” would be to regenerate cmake each time you want to switch between the architectures. But if cmake generation and build is heavy, this is a major usability issue. Hence the above hack solution.

 

-Lassi

 

From: CMake <[hidden email]> On Behalf Of Mojca Miklavec
Sent: tiistai 19. maaliskuuta 2019 10.16
To: [hidden email]
Subject: [CMake] Specifying both native and cross compiler at the same time

 

Hi,

 

I would like a build setup for a project to work correctly for both native and cross compilation, however one part requires native compilation and execution of the binary to generate some data tables as part of the build process (the temporary native binary is then discarded / not installed).

 

What I seem to be unable to figure out is how to specify the compiler(s) and flags separately for the native and cross compiler. I want them to be specified by the user or package manager rather than the author of cmake files.

 

One particular problem is when cross-compiling on mac with mingw (gcc) while using clang as the native compiler (the two compilers have incompatible flags).

 

How can I specify two sets of compilers and flags at configure time? (The same question puzzles me in autoconf world as well. Please don't say that the native compiler should be found automatically as I really need to specify which one to use, ancient systems don't have support for C++11 with the default compiler etc.)

 

Thank you very much,

    Mojca

 


--

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
https://cmake.org/mailman/listinfo/cmake