CMakeCInformation.cmake 8.1 KB

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