CMakeDetermineCCompiler.cmake 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # determine the compiler to use for C programs
  2. # NOTE, a generator may set CMAKE_C_COMPILER before
  3. # loading this file to force a compiler.
  4. # use environment variable CCC first if defined by user, next use
  5. # the cmake variable CMAKE_GENERATOR_CC which can be defined by a generator
  6. # as a default compiler
  7. IF(NOT CMAKE_C_COMPILER)
  8. FIND_PROGRAM(CMAKE_C_COMPILER_FULLPATH NAMES $ENV{CC} ${CMAKE_GENERATOR_CC} gcc cc cl bcc )
  9. GET_FILENAME_COMPONENT(CMAKE_C_COMPILER ${CMAKE_C_COMPILER_FULLPATH} NAME)
  10. # set this to notfound right after so that it is searched for each time this
  11. # file is included
  12. SET(CMAKE_C_COMPILER_FULLPATH NOTFOUND CACHE INTERNAL "full path to c compiler" FORCE)
  13. SET(CMAKE_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING "C++ compiler")
  14. ENDIF(NOT CMAKE_C_COMPILER)
  15. MARK_AS_ADVANCED(CMAKE_C_COMPILER)
  16. FIND_PROGRAM(CMAKE_AR NAMES ar PATHS /bin /usr/bin /usr/local/bin)
  17. FIND_PROGRAM(CMAKE_RANLIB NAMES ranlib PATHS /bin /usr/bin /usr/local/bin)
  18. IF(NOT CMAKE_RANLIB)
  19. SET(CMAKE_RANLIB : CACHE INTERNAL "noop for ranlib")
  20. ENDIF(NOT CMAKE_RANLIB)
  21. MARK_AS_ADVANCED(CMAKE_RANLIB)
  22. # test to see if the c compiler is gnu
  23. EXEC_PROGRAM(${CMAKE_C_COMPILER} ARGS -E ${CMAKE_ROOT}/Modules/CMakeTestGNU.c OUTPUT_VARIABLE CMAKE_COMPILER_OUTPUT RETURN_VALUE CMAKE_COMPILER_RETURN)
  24. IF(NOT CMAKE_COMPILER_RETURN)
  25. IF(${CMAKE_COMPILER_OUTPUT} MATCHES ".*THIS_IS_GNU.*" )
  26. SET(CMAKE_COMPILER_IS_GNUGCC 1)
  27. ENDIF(${CMAKE_COMPILER_OUTPUT} MATCHES ".*THIS_IS_GNU.*" )
  28. ENDIF(NOT CMAKE_COMPILER_RETURN)
  29. # configure variables set in this file for fast reload later on
  30. CONFIGURE_FILE(${CMAKE_ROOT}/Modules/CMakeCCompiler.cmake.in
  31. ${PROJECT_BINARY_DIR}/CMakeCCompiler.cmake IMMEDIATE)
  32. MARK_AS_ADVANCED(CMAKE_AR CMAKE_C_COMPILER_FULLPATH)