CMakeCInformation.cmake 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #=============================================================================
  2. # Copyright 2004-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 file sets the basic flags for the C language in CMake.
  14. # It also loads the available platform file for the system-compiler
  15. # if it exists.
  16. # It also loads a system - compiler - processor (or target hardware)
  17. # specific file, which is mainly useful for crosscompiling and embedded systems.
  18. # some compilers use different extensions (e.g. sdcc uses .rel)
  19. # so set the extension here first so it can be overridden by the compiler specific file
  20. IF(UNIX)
  21. SET(CMAKE_C_OUTPUT_EXTENSION .o)
  22. ELSE(UNIX)
  23. SET(CMAKE_C_OUTPUT_EXTENSION .obj)
  24. ENDIF(UNIX)
  25. # Load compiler-specific information.
  26. IF(CMAKE_C_COMPILER_ID)
  27. INCLUDE(Compiler/${CMAKE_C_COMPILER_ID}-C OPTIONAL)
  28. ENDIF(CMAKE_C_COMPILER_ID)
  29. SET(CMAKE_BASE_NAME)
  30. GET_FILENAME_COMPONENT(CMAKE_BASE_NAME ${CMAKE_C_COMPILER} NAME_WE)
  31. IF(CMAKE_COMPILER_IS_GNUCC)
  32. SET(CMAKE_BASE_NAME gcc)
  33. ENDIF(CMAKE_COMPILER_IS_GNUCC)
  34. # load a hardware specific file, mostly useful for embedded compilers
  35. IF(CMAKE_SYSTEM_PROCESSOR)
  36. IF(CMAKE_C_COMPILER_ID)
  37. INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_C_COMPILER_ID}-C-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
  38. ENDIF(CMAKE_C_COMPILER_ID)
  39. IF (NOT _INCLUDED_FILE)
  40. INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
  41. ENDIF (NOT _INCLUDED_FILE)
  42. ENDIF(CMAKE_SYSTEM_PROCESSOR)
  43. # load the system- and compiler specific files
  44. IF(CMAKE_C_COMPILER_ID)
  45. INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_C_COMPILER_ID}-C
  46. OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
  47. ENDIF(CMAKE_C_COMPILER_ID)
  48. IF (NOT _INCLUDED_FILE)
  49. INCLUDE(Platform/${CMAKE_SYSTEM_NAME}-${CMAKE_BASE_NAME}
  50. OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
  51. ENDIF (NOT _INCLUDED_FILE)
  52. # We specify the compiler information in the system file for some
  53. # platforms, but this language may not have been enabled when the file
  54. # was first included. Include it again to get the language info.
  55. # Remove this when all compiler info is removed from system files.
  56. IF (NOT _INCLUDED_FILE)
  57. INCLUDE(Platform/${CMAKE_SYSTEM_NAME} OPTIONAL)
  58. ENDIF (NOT _INCLUDED_FILE)
  59. # This should be included before the _INIT variables are
  60. # used to initialize the cache. Since the rule variables
  61. # have if blocks on them, users can still define them here.
  62. # But, it should still be after the platform file so changes can
  63. # be made to those values.
  64. IF(CMAKE_USER_MAKE_RULES_OVERRIDE)
  65. INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE})
  66. ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE)
  67. IF(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
  68. INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE_C})
  69. ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
  70. # for most systems a module is the same as a shared library
  71. # so unless the variable CMAKE_MODULE_EXISTS is set just
  72. # copy the values from the LIBRARY variables
  73. IF(NOT CMAKE_MODULE_EXISTS)
  74. SET(CMAKE_SHARED_MODULE_C_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
  75. SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
  76. ENDIF(NOT CMAKE_MODULE_EXISTS)
  77. SET(CMAKE_C_FLAGS_INIT "$ENV{CFLAGS} ${CMAKE_C_FLAGS_INIT}")
  78. # avoid just having a space as the initial value for the cache
  79. IF(CMAKE_C_FLAGS_INIT STREQUAL " ")
  80. SET(CMAKE_C_FLAGS_INIT)
  81. ENDIF(CMAKE_C_FLAGS_INIT STREQUAL " ")
  82. SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_INIT}" CACHE STRING
  83. "Flags used by the compiler during all build types.")
  84. IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
  85. # default build type is none
  86. IF(NOT CMAKE_NO_BUILD_TYPE)
  87. SET (CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE_INIT} CACHE STRING
  88. "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
  89. ENDIF(NOT CMAKE_NO_BUILD_TYPE)
  90. SET (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT}" CACHE STRING
  91. "Flags used by the compiler during debug builds.")
  92. SET (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL_INIT}" CACHE STRING
  93. "Flags used by the compiler during release minsize builds.")
  94. SET (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT}" CACHE STRING
  95. "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).")
  96. SET (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
  97. "Flags used by the compiler during Release with Debug Info builds.")
  98. ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
  99. IF(CMAKE_C_STANDARD_LIBRARIES_INIT)
  100. SET(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES_INIT}"
  101. CACHE STRING "Libraries linked by defalut with all C applications.")
  102. MARK_AS_ADVANCED(CMAKE_C_STANDARD_LIBRARIES)
  103. ENDIF(CMAKE_C_STANDARD_LIBRARIES_INIT)
  104. INCLUDE(CMakeCommonLanguageInclude)
  105. # now define the following rule variables
  106. # CMAKE_C_CREATE_SHARED_LIBRARY
  107. # CMAKE_C_CREATE_SHARED_MODULE
  108. # CMAKE_C_COMPILE_OBJECT
  109. # CMAKE_C_LINK_EXECUTABLE
  110. # variables supplied by the generator at use time
  111. # <TARGET>
  112. # <TARGET_BASE> the target without the suffix
  113. # <OBJECTS>
  114. # <OBJECT>
  115. # <LINK_LIBRARIES>
  116. # <FLAGS>
  117. # <LINK_FLAGS>
  118. # C compiler information
  119. # <CMAKE_C_COMPILER>
  120. # <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS>
  121. # <CMAKE_SHARED_MODULE_CREATE_C_FLAGS>
  122. # <CMAKE_C_LINK_FLAGS>
  123. # Static library tools
  124. # <CMAKE_AR>
  125. # <CMAKE_RANLIB>
  126. # create a C shared library
  127. IF(NOT CMAKE_C_CREATE_SHARED_LIBRARY)
  128. SET(CMAKE_C_CREATE_SHARED_LIBRARY
  129. "<CMAKE_C_COMPILER> <CMAKE_SHARED_LIBRARY_C_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS> <CMAKE_SHARED_LIBRARY_SONAME_C_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
  130. ENDIF(NOT CMAKE_C_CREATE_SHARED_LIBRARY)
  131. # create a C shared module just copy the shared library rule
  132. IF(NOT CMAKE_C_CREATE_SHARED_MODULE)
  133. SET(CMAKE_C_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_LIBRARY})
  134. ENDIF(NOT CMAKE_C_CREATE_SHARED_MODULE)
  135. # Create a static archive incrementally for large object file counts.
  136. # If CMAKE_C_CREATE_STATIC_LIBRARY is set it will override these.
  137. SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS>")
  138. SET(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> r <TARGET> <LINK_FLAGS> <OBJECTS>")
  139. SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
  140. # compile a C file into an object file
  141. IF(NOT CMAKE_C_COMPILE_OBJECT)
  142. SET(CMAKE_C_COMPILE_OBJECT
  143. "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
  144. ENDIF(NOT CMAKE_C_COMPILE_OBJECT)
  145. IF(NOT CMAKE_C_LINK_EXECUTABLE)
  146. SET(CMAKE_C_LINK_EXECUTABLE
  147. "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
  148. ENDIF(NOT CMAKE_C_LINK_EXECUTABLE)
  149. IF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG)
  150. SET(CMAKE_EXECUTABLE_RUNTIME_C_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
  151. ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG)
  152. IF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP)
  153. SET(CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
  154. ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP)
  155. IF(NOT CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG)
  156. SET(CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
  157. ENDIF(NOT CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG)
  158. MARK_AS_ADVANCED(
  159. CMAKE_C_FLAGS
  160. CMAKE_C_FLAGS_DEBUG
  161. CMAKE_C_FLAGS_MINSIZEREL
  162. CMAKE_C_FLAGS_RELEASE
  163. CMAKE_C_FLAGS_RELWITHDEBINFO
  164. )
  165. SET(CMAKE_C_INFORMATION_LOADED 1)