CMakeOBJCXXInformation.cmake 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. # This file sets the basic flags for the Objective-C++ language in CMake.
  4. # It also loads the available platform file for the system-compiler
  5. # if it exists.
  6. # It also loads a system - compiler - processor (or target hardware)
  7. # specific file, which is mainly useful for crosscompiling and embedded systems.
  8. include(CMakeLanguageInformation)
  9. # some compilers use different extensions (e.g. sdcc uses .rel)
  10. # so set the extension here first so it can be overridden by the compiler specific file
  11. set(CMAKE_OBJCXX_OUTPUT_EXTENSION .o)
  12. set(_INCLUDED_FILE 0)
  13. # Load compiler-specific information.
  14. if(CMAKE_OBJCXX_COMPILER_ID)
  15. include(Compiler/${CMAKE_OBJCXX_COMPILER_ID}-OBJCXX OPTIONAL)
  16. endif()
  17. set(CMAKE_BASE_NAME)
  18. get_filename_component(CMAKE_BASE_NAME "${CMAKE_OBJCXX_COMPILER}" NAME_WE)
  19. # since the gnu compiler has several names force g++
  20. if(CMAKE_COMPILER_IS_GNUOBJCXX)
  21. set(CMAKE_BASE_NAME g++)
  22. endif()
  23. # load a hardware specific file, mostly useful for embedded compilers
  24. if(CMAKE_SYSTEM_PROCESSOR)
  25. if(CMAKE_OBJCXX_COMPILER_ID)
  26. include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_OBJCXX_COMPILER_ID}-OBJCXX-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
  27. endif()
  28. if (NOT _INCLUDED_FILE)
  29. include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_BASE_NAME}-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
  30. endif ()
  31. endif()
  32. # load the system- and compiler specific files
  33. if(CMAKE_OBJCXX_COMPILER_ID)
  34. include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_OBJCXX_COMPILER_ID}-OBJCXX OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
  35. endif()
  36. if (NOT _INCLUDED_FILE)
  37. include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_BASE_NAME} OPTIONAL
  38. RESULT_VARIABLE _INCLUDED_FILE)
  39. endif ()
  40. # load any compiler-wrapper specific information
  41. if (CMAKE_OBJCXX_COMPILER_WRAPPER)
  42. __cmake_include_compiler_wrapper(OBJCXX)
  43. endif ()
  44. # We specify the compiler information in the system file for some
  45. # platforms, but this language may not have been enabled when the file
  46. # was first included. Include it again to get the language info.
  47. # Remove this when all compiler info is removed from system files.
  48. if (NOT _INCLUDED_FILE)
  49. include(Platform/${CMAKE_SYSTEM_NAME} OPTIONAL)
  50. endif ()
  51. if(CMAKE_OBJCXX_SIZEOF_DATA_PTR)
  52. foreach(f ${CMAKE_OBJCXX_ABI_FILES})
  53. include(${f})
  54. endforeach()
  55. unset(CMAKE_OBJCXX_ABI_FILES)
  56. endif()
  57. # This should be included before the _INIT variables are
  58. # used to initialize the cache. Since the rule variables
  59. # have if blocks on them, users can still define them here.
  60. # But, it should still be after the platform file so changes can
  61. # be made to those values.
  62. if(CMAKE_USER_MAKE_RULES_OVERRIDE)
  63. # Save the full path of the file so try_compile can use it.
  64. include(${CMAKE_USER_MAKE_RULES_OVERRIDE} RESULT_VARIABLE _override)
  65. set(CMAKE_USER_MAKE_RULES_OVERRIDE "${_override}")
  66. endif()
  67. if(CMAKE_USER_MAKE_RULES_OVERRIDE_OBJCXX)
  68. # Save the full path of the file so try_compile can use it.
  69. include(${CMAKE_USER_MAKE_RULES_OVERRIDE_OBJCXX} RESULT_VARIABLE _override)
  70. set(CMAKE_USER_MAKE_RULES_OVERRIDE_OBJCXX "${_override}")
  71. endif()
  72. # Create a set of shared library variable specific to Objective-C++
  73. # For 90% of the systems, these are the same flags as the Objective-C versions
  74. # so if these are not set just copy the flags from the Objective-C version
  75. if(NOT CMAKE_SHARED_LIBRARY_CREATE_OBJCXX_FLAGS)
  76. set(CMAKE_SHARED_LIBRARY_CREATE_OBJCXX_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_OBJC_FLAGS})
  77. endif()
  78. if(NOT CMAKE_OBJCXX_COMPILE_OPTIONS_PIC)
  79. set(CMAKE_OBJCXX_COMPILE_OPTIONS_PIC ${CMAKE_OBJC_COMPILE_OPTIONS_PIC})
  80. endif()
  81. if(NOT CMAKE_OBJCXX_COMPILE_OPTIONS_PIE)
  82. set(CMAKE_OBJCXX_COMPILE_OPTIONS_PIE ${CMAKE_OBJC_COMPILE_OPTIONS_PIE})
  83. endif()
  84. if(NOT CMAKE_OBJCXX_LINK_OPTIONS_PIE)
  85. set(CMAKE_OBJCXX_LINK_OPTIONS_PIE ${CMAKE_OBJC_LINK_OPTIONS_PIE})
  86. endif()
  87. if(NOT CMAKE_OBJCXX_LINK_OPTIONS_NO_PIE)
  88. set(CMAKE_OBJCXX_LINK_OPTIONS_NO_PIE ${CMAKE_OBJC_LINK_OPTIONS_NO_PIE})
  89. endif()
  90. if(NOT CMAKE_OBJCXX_COMPILE_OPTIONS_DLL)
  91. set(CMAKE_OBJCXX_COMPILE_OPTIONS_DLL ${CMAKE_OBJC_COMPILE_OPTIONS_DLL})
  92. endif()
  93. if(NOT CMAKE_SHARED_LIBRARY_OBJCXX_FLAGS)
  94. set(CMAKE_SHARED_LIBRARY_OBJCXX_FLAGS ${CMAKE_SHARED_LIBRARY_OBJC_FLAGS})
  95. endif()
  96. if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_OBJCXX_FLAGS)
  97. set(CMAKE_SHARED_LIBRARY_LINK_OBJCXX_FLAGS ${CMAKE_SHARED_LIBRARY_LINK_OBJC_FLAGS})
  98. endif()
  99. if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_OBJCXX_FLAG)
  100. set(CMAKE_SHARED_LIBRARY_RUNTIME_OBJCXX_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_OBJC_FLAG})
  101. endif()
  102. if(NOT CMAKE_SHARED_LIBRARY_RUNTIME_OBJCXX_FLAG_SEP)
  103. set(CMAKE_SHARED_LIBRARY_RUNTIME_OBJCXX_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_OBJC_FLAG_SEP})
  104. endif()
  105. if(NOT CMAKE_SHARED_LIBRARY_RPATH_LINK_OBJCXX_FLAG)
  106. set(CMAKE_SHARED_LIBRARY_RPATH_LINK_OBJCXX_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_OBJC_FLAG})
  107. endif()
  108. if(NOT DEFINED CMAKE_EXE_EXPORTS_OBJCXX_FLAG)
  109. set(CMAKE_EXE_EXPORTS_OBJCXX_FLAG ${CMAKE_EXE_EXPORTS_OBJC_FLAG})
  110. endif()
  111. if(NOT DEFINED CMAKE_SHARED_LIBRARY_SONAME_OBJCXX_FLAG)
  112. set(CMAKE_SHARED_LIBRARY_SONAME_OBJCXX_FLAG ${CMAKE_SHARED_LIBRARY_SONAME_OBJC_FLAG})
  113. endif()
  114. if(NOT CMAKE_EXECUTABLE_RUNTIME_OBJCXX_FLAG)
  115. set(CMAKE_EXECUTABLE_RUNTIME_OBJCXX_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_OBJCXX_FLAG})
  116. endif()
  117. if(NOT CMAKE_EXECUTABLE_RUNTIME_OBJCXX_FLAG_SEP)
  118. set(CMAKE_EXECUTABLE_RUNTIME_OBJCXX_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_OBJCXX_FLAG_SEP})
  119. endif()
  120. if(NOT CMAKE_EXECUTABLE_RPATH_LINK_OBJCXX_FLAG)
  121. set(CMAKE_EXECUTABLE_RPATH_LINK_OBJCXX_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_OBJCXX_FLAG})
  122. endif()
  123. if(NOT DEFINED CMAKE_SHARED_LIBRARY_LINK_OBJCXX_WITH_RUNTIME_PATH)
  124. set(CMAKE_SHARED_LIBRARY_LINK_OBJCXX_WITH_RUNTIME_PATH ${CMAKE_SHARED_LIBRARY_LINK_OBJC_WITH_RUNTIME_PATH})
  125. endif()
  126. if(NOT CMAKE_INCLUDE_FLAG_OBJCXX)
  127. set(CMAKE_INCLUDE_FLAG_OBJCXX ${CMAKE_INCLUDE_FLAG_C})
  128. endif()
  129. # for most systems a module is the same as a shared library
  130. # so unless the variable CMAKE_MODULE_EXISTS is set just
  131. # copy the values from the LIBRARY variables
  132. if(NOT CMAKE_MODULE_EXISTS)
  133. set(CMAKE_SHARED_MODULE_OBJCXX_FLAGS ${CMAKE_SHARED_LIBRARY_OBJCXX_FLAGS})
  134. set(CMAKE_SHARED_MODULE_CREATE_OBJCXX_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_OBJCXX_FLAGS})
  135. endif()
  136. # repeat for modules
  137. if(NOT CMAKE_SHARED_MODULE_CREATE_OBJCXX_FLAGS)
  138. set(CMAKE_SHARED_MODULE_CREATE_OBJCXX_FLAGS ${CMAKE_SHARED_MODULE_CREATE_OBJC_FLAGS})
  139. endif()
  140. if(NOT CMAKE_SHARED_MODULE_OBJCXX_FLAGS)
  141. set(CMAKE_SHARED_MODULE_OBJCXX_FLAGS ${CMAKE_SHARED_MODULE_OBJC_FLAGS})
  142. endif()
  143. # Initialize OBJCXX link type selection flags from OBJC versions.
  144. foreach(type SHARED_LIBRARY SHARED_MODULE EXE)
  145. if(NOT CMAKE_${type}_LINK_STATIC_OBJCXX_FLAGS)
  146. set(CMAKE_${type}_LINK_STATIC_OBJCXX_FLAGS
  147. ${CMAKE_${type}_LINK_STATIC_OBJC_FLAGS})
  148. endif()
  149. if(NOT CMAKE_${type}_LINK_DYNAMIC_OBJCXX_FLAGS)
  150. set(CMAKE_${type}_LINK_DYNAMIC_OBJCXX_FLAGS
  151. ${CMAKE_${type}_LINK_DYNAMIC_OBJC_FLAGS})
  152. endif()
  153. endforeach()
  154. # add the flags to the cache based
  155. # on the initial values computed in the platform/*.cmake files
  156. # use _INIT variables so that this only happens the first time
  157. # and you can set these flags in the cmake cache
  158. set(CMAKE_OBJCXX_FLAGS_INIT "$ENV{OBJCXXFLAGS} ${CMAKE_OBJCXX_FLAGS_INIT}")
  159. cmake_initialize_per_config_variable(CMAKE_OBJCXX_FLAGS "Flags used by the Objective-C++ compiler")
  160. if(CMAKE_OBJCXX_STANDARD_LIBRARIES_INIT)
  161. set(CMAKE_OBJCXX_STANDARD_LIBRARIES "${CMAKE_OBJCXX_STANDARD_LIBRARIES_INIT}"
  162. CACHE STRING "Libraries linked by default with all Objective-C++ applications.")
  163. mark_as_advanced(CMAKE_OBJCXX_STANDARD_LIBRARIES)
  164. endif()
  165. include(CMakeCommonLanguageInclude)
  166. # now define the following rules:
  167. # CMAKE_OBJCXX_CREATE_SHARED_LIBRARY
  168. # CMAKE_OBJCXX_CREATE_SHARED_MODULE
  169. # CMAKE_OBJCXX_COMPILE_OBJECT
  170. # CMAKE_OBJCXX_LINK_EXECUTABLE
  171. # variables supplied by the generator at use time
  172. # <TARGET>
  173. # <TARGET_BASE> the target without the suffix
  174. # <OBJECTS>
  175. # <OBJECT>
  176. # <LINK_LIBRARIES>
  177. # <FLAGS>
  178. # <LINK_FLAGS>
  179. # Objective-C++ compiler information
  180. # <CMAKE_OBJCXX_COMPILER>
  181. # <CMAKE_SHARED_LIBRARY_CREATE_OBJCXX_FLAGS>
  182. # <CMAKE_OBJCXX_SHARED_MODULE_CREATE_FLAGS>
  183. # <CMAKE_OBJCXX_LINK_FLAGS>
  184. # Static library tools
  185. # <CMAKE_AR>
  186. # <CMAKE_RANLIB>
  187. # create a shared Objective-C++ library
  188. if(NOT CMAKE_OBJCXX_CREATE_SHARED_LIBRARY)
  189. set(CMAKE_OBJCXX_CREATE_SHARED_LIBRARY
  190. "<CMAKE_OBJCXX_COMPILER> <CMAKE_SHARED_LIBRARY_OBJCXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_OBJCXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
  191. endif()
  192. # create an Objective-C++ shared module copy the shared library rule by default
  193. if(NOT CMAKE_OBJCXX_CREATE_SHARED_MODULE)
  194. set(CMAKE_OBJCXX_CREATE_SHARED_MODULE ${CMAKE_OBJCXX_CREATE_SHARED_LIBRARY})
  195. endif()
  196. # Create a static archive incrementally for large object file counts.
  197. # If CMAKE_OBJCXX_CREATE_STATIC_LIBRARY is set it will override these.
  198. if(NOT DEFINED CMAKE_OBJCXX_ARCHIVE_CREATE)
  199. set(CMAKE_OBJCXX_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
  200. endif()
  201. if(NOT DEFINED CMAKE_OBJCXX_ARCHIVE_APPEND)
  202. set(CMAKE_OBJCXX_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
  203. endif()
  204. if(NOT DEFINED CMAKE_OBJCXX_ARCHIVE_FINISH)
  205. set(CMAKE_OBJCXX_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
  206. endif()
  207. # compile an Objective-C++ file into an object file
  208. if(NOT CMAKE_OBJCXX_COMPILE_OBJECT)
  209. set(CMAKE_OBJCXX_COMPILE_OBJECT
  210. "<CMAKE_OBJCXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -x objective-c++ -o <OBJECT> -c <SOURCE>")
  211. endif()
  212. if(NOT CMAKE_OBJCXX_LINK_EXECUTABLE)
  213. set(CMAKE_OBJCXX_LINK_EXECUTABLE
  214. "<CMAKE_OBJCXX_COMPILER> <FLAGS> <CMAKE_OBJCXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
  215. endif()
  216. mark_as_advanced(
  217. CMAKE_VERBOSE_MAKEFILE
  218. )
  219. set(CMAKE_OBJCXX_INFORMATION_LOADED 1)