1
0

CMakeCInformation.cmake 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 distributed 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. # some systems include the compiler information in the system file
  53. # and if this is the enable_language command then it may not have been
  54. # included at this point, or needs to be included again so that the
  55. # language_INIT variables are set correctly
  56. IF (NOT _INCLUDED_FILE)
  57. INCLUDE(Platform/${CMAKE_SYSTEM_NAME}
  58. OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
  59. ENDIF (NOT _INCLUDED_FILE)
  60. # This should be included before the _INIT variables are
  61. # used to initialize the cache. Since the rule variables
  62. # have if blocks on them, users can still define them here.
  63. # But, it should still be after the platform file so changes can
  64. # be made to those values.
  65. IF(CMAKE_USER_MAKE_RULES_OVERRIDE)
  66. INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE})
  67. ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE)
  68. IF(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
  69. INCLUDE(${CMAKE_USER_MAKE_RULES_OVERRIDE_C})
  70. ENDIF(CMAKE_USER_MAKE_RULES_OVERRIDE_C)
  71. # for most systems a module is the same as a shared library
  72. # so unless the variable CMAKE_MODULE_EXISTS is set just
  73. # copy the values from the LIBRARY variables
  74. IF(NOT CMAKE_MODULE_EXISTS)
  75. SET(CMAKE_SHARED_MODULE_C_FLAGS ${CMAKE_SHARED_LIBRARY_C_FLAGS})
  76. SET(CMAKE_SHARED_MODULE_CREATE_C_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS})
  77. ENDIF(NOT CMAKE_MODULE_EXISTS)
  78. SET(CMAKE_C_FLAGS_INIT "$ENV{CFLAGS} ${CMAKE_C_FLAGS_INIT}")
  79. # avoid just having a space as the initial value for the cache
  80. IF(CMAKE_C_FLAGS_INIT STREQUAL " ")
  81. SET(CMAKE_C_FLAGS_INIT)
  82. ENDIF(CMAKE_C_FLAGS_INIT STREQUAL " ")
  83. SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS_INIT}" CACHE STRING
  84. "Flags used by the compiler during all build types.")
  85. IF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
  86. # default build type is none
  87. IF(NOT CMAKE_NO_BUILD_TYPE)
  88. SET (CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE_INIT} CACHE STRING
  89. "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.")
  90. ENDIF(NOT CMAKE_NO_BUILD_TYPE)
  91. SET (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG_INIT}" CACHE STRING
  92. "Flags used by the compiler during debug builds.")
  93. SET (CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL_INIT}" CACHE STRING
  94. "Flags used by the compiler during release minsize builds.")
  95. SET (CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE_INIT}" CACHE STRING
  96. "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files).")
  97. SET (CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO_INIT}" CACHE STRING
  98. "Flags used by the compiler during Release with Debug Info builds.")
  99. ENDIF(NOT CMAKE_NOT_USING_CONFIG_FLAGS)
  100. IF(CMAKE_C_STANDARD_LIBRARIES_INIT)
  101. SET(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES_INIT}"
  102. CACHE STRING "Libraries linked by defalut with all C applications.")
  103. MARK_AS_ADVANCED(CMAKE_C_STANDARD_LIBRARIES)
  104. ENDIF(CMAKE_C_STANDARD_LIBRARIES_INIT)
  105. INCLUDE(CMakeCommonLanguageInclude)
  106. # now define the following rule variables
  107. # CMAKE_C_CREATE_SHARED_LIBRARY
  108. # CMAKE_C_CREATE_SHARED_MODULE
  109. # CMAKE_C_COMPILE_OBJECT
  110. # CMAKE_C_LINK_EXECUTABLE
  111. # variables supplied by the generator at use time
  112. # <TARGET>
  113. # <TARGET_BASE> the target without the suffix
  114. # <OBJECTS>
  115. # <OBJECT>
  116. # <LINK_LIBRARIES>
  117. # <FLAGS>
  118. # <LINK_FLAGS>
  119. # C compiler information
  120. # <CMAKE_C_COMPILER>
  121. # <CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS>
  122. # <CMAKE_SHARED_MODULE_CREATE_C_FLAGS>
  123. # <CMAKE_C_LINK_FLAGS>
  124. # Static library tools
  125. # <CMAKE_AR>
  126. # <CMAKE_RANLIB>
  127. # create a C shared library
  128. IF(NOT CMAKE_C_CREATE_SHARED_LIBRARY)
  129. SET(CMAKE_C_CREATE_SHARED_LIBRARY
  130. "<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>")
  131. ENDIF(NOT CMAKE_C_CREATE_SHARED_LIBRARY)
  132. # create a C shared module just copy the shared library rule
  133. IF(NOT CMAKE_C_CREATE_SHARED_MODULE)
  134. SET(CMAKE_C_CREATE_SHARED_MODULE ${CMAKE_C_CREATE_SHARED_LIBRARY})
  135. ENDIF(NOT CMAKE_C_CREATE_SHARED_MODULE)
  136. # Create a static archive incrementally for large object file counts.
  137. # If CMAKE_C_CREATE_STATIC_LIBRARY is set it will override these.
  138. SET(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> cr <TARGET> <LINK_FLAGS> <OBJECTS>")
  139. SET(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> r <TARGET> <LINK_FLAGS> <OBJECTS>")
  140. SET(CMAKE_C_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
  141. # compile a C file into an object file
  142. IF(NOT CMAKE_C_COMPILE_OBJECT)
  143. SET(CMAKE_C_COMPILE_OBJECT
  144. "<CMAKE_C_COMPILER> <DEFINES> <FLAGS> -o <OBJECT> -c <SOURCE>")
  145. ENDIF(NOT CMAKE_C_COMPILE_OBJECT)
  146. IF(NOT CMAKE_C_LINK_EXECUTABLE)
  147. SET(CMAKE_C_LINK_EXECUTABLE
  148. "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
  149. ENDIF(NOT CMAKE_C_LINK_EXECUTABLE)
  150. IF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG)
  151. SET(CMAKE_EXECUTABLE_RUNTIME_C_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG})
  152. ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG)
  153. IF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP)
  154. SET(CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG_SEP})
  155. ENDIF(NOT CMAKE_EXECUTABLE_RUNTIME_C_FLAG_SEP)
  156. IF(NOT CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG)
  157. SET(CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_C_FLAG})
  158. ENDIF(NOT CMAKE_EXECUTABLE_RPATH_LINK_C_FLAG)
  159. MARK_AS_ADVANCED(
  160. CMAKE_C_FLAGS
  161. CMAKE_C_FLAGS_DEBUG
  162. CMAKE_C_FLAGS_MINSIZEREL
  163. CMAKE_C_FLAGS_RELEASE
  164. CMAKE_C_FLAGS_RELWITHDEBINFO
  165. )
  166. SET(CMAKE_C_INFORMATION_LOADED 1)