CMakeCInformation.cmake 7.7 KB

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