GNU.cmake 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #=============================================================================
  2. # Copyright 2002-2009 Kitware, Inc.
  3. #
  4. # Distributed under the OSI-approved BSD License (the "License");
  5. # see accompanying file Copyright.txt for details.
  6. #
  7. # This software is distributed WITHOUT ANY WARRANTY; without even the
  8. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. # See the License for more information.
  10. #=============================================================================
  11. # (To distribute this file outside of CMake, substitute the full
  12. # License text for the above reference.)
  13. # This module is shared by multiple languages; use include blocker.
  14. if(__COMPILER_GNU)
  15. return()
  16. endif()
  17. set(__COMPILER_GNU 1)
  18. macro(__compiler_gnu lang)
  19. # Feature flags.
  20. set(CMAKE_${lang}_VERBOSE_FLAG "-v")
  21. set(CMAKE_${lang}_COMPILE_OPTIONS_PIC "-fPIC")
  22. if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 3.4)
  23. set(CMAKE_${lang}_COMPILE_OPTIONS_PIE "-fPIE")
  24. endif()
  25. if(NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4.2)
  26. set(CMAKE_${lang}_COMPILE_OPTIONS_VISIBILITY "-fvisibility=")
  27. endif()
  28. set(CMAKE_SHARED_LIBRARY_${lang}_FLAGS "-fPIC")
  29. set(CMAKE_SHARED_LIBRARY_CREATE_${lang}_FLAGS "-shared")
  30. set(CMAKE_${lang}_COMPILE_OPTIONS_SYSROOT "--sysroot=")
  31. # Older versions of gcc (< 4.5) contain a bug causing them to report a missing
  32. # header file as a warning if depfiles are enabled, causing check_header_file
  33. # tests to always succeed. Work around this by disabling dependency tracking
  34. # in try_compile mode.
  35. get_property(_IN_TC GLOBAL PROPERTY IN_TRY_COMPILE)
  36. if(NOT _IN_TC OR CMAKE_FORCE_DEPFILES)
  37. # distcc does not transform -o to -MT when invoking the preprocessor
  38. # internally, as it ought to. Work around this bug by setting -MT here
  39. # even though it isn't strictly necessary.
  40. set(CMAKE_DEPFILE_FLAGS_${lang} "-MD -MT <OBJECT> -MF <DEPFILE>")
  41. endif()
  42. # Initial configuration flags.
  43. set(CMAKE_${lang}_FLAGS_INIT "")
  44. set(CMAKE_${lang}_FLAGS_DEBUG_INIT "-g")
  45. set(CMAKE_${lang}_FLAGS_MINSIZEREL_INIT "-Os -DNDEBUG")
  46. set(CMAKE_${lang}_FLAGS_RELEASE_INIT "-O3 -DNDEBUG")
  47. set(CMAKE_${lang}_FLAGS_RELWITHDEBINFO_INIT "-O2 -g -DNDEBUG")
  48. set(CMAKE_${lang}_CREATE_PREPROCESSED_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -E <SOURCE> > <PREPROCESSED_SOURCE>")
  49. set(CMAKE_${lang}_CREATE_ASSEMBLY_SOURCE "<CMAKE_${lang}_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -S <SOURCE> -o <ASSEMBLY_SOURCE>")
  50. if(NOT APPLE OR NOT CMAKE_${lang}_COMPILER_VERSION VERSION_LESS 4) # work around #4462
  51. set(CMAKE_INCLUDE_SYSTEM_FLAG_${lang} "-isystem ")
  52. endif()
  53. endmacro()