CMakeDetermineCXXCompiler.cmake 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # determine the compiler to use for C++ programs
  2. # NOTE, a generator may set CMAKE_CXX_COMPILER before
  3. # loading this file to force a compiler.
  4. # use environment variable CXX first if defined by user, next use
  5. # the cmake variable CMAKE_GENERATOR_CXX which can be defined by a generator
  6. # as a default compiler
  7. IF(NOT CMAKE_CXX_COMPILER)
  8. # if the user has specified CC via the environment, then use that without checking
  9. IF($ENV{CXX} MATCHES ".+")
  10. GET_FILENAME_COMPONENT(CMAKE_CXX_COMPILER_INIT $ENV{CXX} PROGRAM PROGRAM_ARGS CMAKE_CXX_FLAGS_ENV_INIT)
  11. IF(EXISTS ${CMAKE_CXX_COMPILER_INIT})
  12. ELSE(EXISTS ${CMAKE_CXX_COMPILER_INIT})
  13. MESSAGE(SEND_ERROR "Could not find compiler set in environment variable CXX:\n$ENV{CXX}.")
  14. ENDIF(EXISTS ${CMAKE_CXX_COMPILER_INIT})
  15. ELSE($ENV{CXX} MATCHES ".+")
  16. # if not in the envionment then search for the compiler in the path
  17. SET(CMAKE_CXX_COMPILER_LIST ${CMAKE_GENERATOR_CXX} c++ g++ CC aCC cl bcc )
  18. FIND_PROGRAM(CMAKE_CXX_COMPILER_FULLPATH NAMES ${CMAKE_CXX_COMPILER_LIST})
  19. GET_FILENAME_COMPONENT(CMAKE_CXX_COMPILER_INIT
  20. ${CMAKE_CXX_COMPILER_FULLPATH} NAME)
  21. ENDIF($ENV{CXX} MATCHES ".+")
  22. SET(CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER_INIT}
  23. CACHE STRING "C++ compiler")
  24. ENDIF(NOT CMAKE_CXX_COMPILER)
  25. MARK_AS_ADVANCED(CMAKE_CXX_COMPILER)
  26. # set this to notfound right after so that it is searched for each time this
  27. # file is included
  28. SET(CMAKE_CXX_COMPILER_FULLPATH NOTFOUND CACHE INTERNAL "full path to cxx compiler" FORCE)
  29. # test to see if the cxx compiler is gnu
  30. EXEC_PROGRAM(${CMAKE_CXX_COMPILER} ARGS -E ${CMAKE_ROOT}/Modules/CMakeTestGNU.c OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT RETURN_VALUE CMAKE_COMPILER_RETURN)
  31. IF(NOT CMAKE_COMPILER_RETURN)
  32. IF(${CMAKE_COMPILER_OUTPUT} MATCHES ".*THIS_IS_GNU.*" )
  33. SET(CMAKE_COMPILER_IS_GNUCXX 1)
  34. ENDIF(${CMAKE_COMPILER_OUTPUT} MATCHES ".*THIS_IS_GNU.*" )
  35. ENDIF(NOT CMAKE_COMPILER_RETURN)
  36. # configure all variables set in this file
  37. CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in
  38. ${PROJECT_BINARY_DIR}/CMakeCXXCompiler.cmake IMMEDIATE)
  39. MARK_AS_ADVANCED(CMAKE_CXX_COMPILER_FULLPATH)