Forcing the latest version of gcc with cmake

I am deploying a small application on several different systems (mac, linux, linux64) where it needs to be compiled. I would like to tell cmake the latest gcc available on a particular system. For example, Mac 10.6 has gcc 4.0 and gcc 4.2 (default). But some users also install gcc 4.4 through MacPorts (this is not the default). I would like cmake to use gcc44 in this case. On other Linux systems, the latest gcc is 4.4 or 4.5. What is a more reliable way to achieve this?

Thank,

H

+3
source share
2 answers

CMake CC CXX C ++. , clang, clang :

$ export CC=/usr/bin/clang
$ export CXX=/usr/bin/clang++
$ cmake ..
-- The C compiler identification is Clang
-- The CXX compiler identification is Clang
-- Check for working C compiler: /usr/bin/clang
-- Check for working C compiler: /usr/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++
-- Check for working CXX compiler: /usr/bin/clang++ -- works
...

, , script, cmake.

+8

CMakeLists.txt, :

  if($ENV{CXX})
    set(CMAKE_CXX_COMPILER $ENV{CXX} CACHE FILEPATH "CXX Compiler")
  endif()
  if($ENV{CC})
    set(CMAKE_CC_COMPILER $ENV{CC} CACHE FILEPATH "CC Compiler")
  endif()
0

Source: https://habr.com/ru/post/1790700/


All Articles