[CMake] One project, one platform, 2 compilers

David Cole david.cole at kitware.com
Thu Nov 17 13:49:11 EST 2011


To use two different compilers, you simply need two different build
trees. Same CMakeLists file, but different build trees.

You should not specify the compiler in your CMakeLists.txt files at
all, but rather set CC and CXX env vars to control the compiler when
first generating a build tree.

See the FAQ here for how to specify the compilers using CC and CXX:

  http://www.cmake.org/Wiki/CMake_FAQ#How_do_I_use_a_different_compiler.3F


HTH,
David


On Thu, Nov 17, 2011 at 11:18 AM, Paul Hansen
<paul.hansen.name at gmail.com> wrote:
> Hi
>
> I have a project that has to be compiled with two different compilers on the
> same computer.
>
> Can I do that from the same CMakeLists.txt file?
>
> Specifically I am wondering:
> - CMake finds a compiler and makes a test. A colleague has tried to change
> the compiler variables but CMake made the test and overwrote his settings
> (from the CMakeLists.txt file) in CMakeCache.txt
> - With target_link_directories I can point out specifically which libraries
> should be used with each executable. But what about header files?
> include_directories() is not specified for each executable. Is there anyway
> to control what is in the include path at different points in the
> CMakeLists.txt. I have tried to use set_directory_properties(PROPERTIES
> INCLUDE_DIRECTORIES "") to reset include path at one point. The deletion
> works but just not at that specific point on CMakeLists.txt.
> - If split up into compiler1.cmake and compiler2.cmake I still get the
> include_directories() problem since values are "inherited"
>
> Thank you very much indeed
> Paul
>
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>


More information about the CMake mailing list