[CMake] cmake picks a compiler

David Cole DLRdave at aol.com
Tue Mar 3 15:33:55 EST 2015


CMake picks the compiler when you enable the C++ language, which is
either: the first project command encountered, or an explicit call to
the enable_language command. Or, in rare cases, it could be an
implicitly added project command in the top level CMakeLists.txt file
for those files without either project or enable_language anywhere in
the file...

If you want to put instruction before the automatic picking happens,
just put your instructions before the project command.

HTH,
David C.


On Tue, Mar 3, 2015 at 3:23 PM, Dave Yost <Dave at yost.com> wrote:
> Hi.
>
> In our CMakeLists.txt file we want to force the user to pick a c++ compiler
> explicitly, something like this:
>
> if (NOT DEFINED CMAKE_CXX_COMPILER)
>   set(CMAKE_CXX_COMPILER $ENV{CXX})
>   if (NOT DEFINED CMAKE_CXX_COMPILER)
>     message(FATAL_ERROR "
>  You must choose your compiler, in one of two ways:
>    cmake -DCMAKE_CXX_COMPILER=/path/to/compiler++
>    CXX=/path/to/compiler++ cmake")
>   endif()
> endif()
> message("CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
>
>
> Problem is, CMAKE_CXX_COMPILER is already set because cmake looked around
> and picked a compiler (which causes a lot of messages to be output before
> cmake executes the above statements).
>
> Z% CMAKE_CXX_COMPILER=/usr/bin/clang++ cmake ..
> -- The CXX compiler identification is GNU 4.9.2
> -- Checking whether CXX compiler has -isysroot
> -- Checking whether CXX compiler has -isysroot - yes
> -- Checking whether CXX compiler supports OSX deployment target flag
> -- Checking whether CXX compiler supports OSX deployment target flag - yes
> -- Check for working CXX compiler: /opt/local/bin/c++
> -- Check for working CXX compiler: /opt/local/bin/c++ -- works
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- Detecting CXX compile features
> -- Detecting CXX compile features - done
> CMAKE_CXX_COMPILER: /opt/local/bin/c++
>
>
> I need a command I can put in my CMakeLists.txt file to disable the cmake
> feature that automatically locates a c++ compiler.
>
> Thanks
>
> --
>
> 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:
> http://public.kitware.com/mailman/listinfo/cmake


More information about the CMake mailing list