CMakeOBJCInformation.cmake 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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_OBJC_OUTPUT_EXTENSION .o)
  12. if(NOT CMAKE_INCLUDE_FLAG_OBJC)
  13. set(CMAKE_INCLUDE_FLAG_OBJC ${CMAKE_INCLUDE_FLAG_C})
  14. endif()
  15. set(_INCLUDED_FILE 0)
  16. # Load compiler-specific information.
  17. if(CMAKE_OBJC_COMPILER_ID)
  18. include(Compiler/${CMAKE_OBJC_COMPILER_ID}-OBJC OPTIONAL)
  19. endif()
  20. set(CMAKE_BASE_NAME)
  21. get_filename_component(CMAKE_BASE_NAME "${CMAKE_OBJC_COMPILER}" NAME_WE)
  22. if(CMAKE_COMPILER_IS_GNUOBJC)
  23. set(CMAKE_BASE_NAME gcc)
  24. endif()
  25. # load a hardware specific file, mostly useful for embedded compilers
  26. if(CMAKE_SYSTEM_PROCESSOR)
  27. if(CMAKE_OBJC_COMPILER_ID)
  28. include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_OBJC_COMPILER_ID}-OBJC-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
  29. endif()
  30. if (NOT _INCLUDED_FILE)
  31. include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_BASE_NAME}-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
  32. endif ()
  33. endif()
  34. # load the system- and compiler specific files
  35. if(CMAKE_OBJC_COMPILER_ID)
  36. include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_OBJC_COMPILER_ID}-OBJC
  37. OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
  38. endif()
  39. if (NOT _INCLUDED_FILE)
  40. include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_BASE_NAME}
  41. OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
  42. endif ()
  43. # load any compiler-wrapper specific information
  44. if (CMAKE_OBJC_COMPILER_WRAPPER)
  45. __cmake_include_compiler_wrapper(OBJC)
  46. endif ()
  47. # We specify the compiler information in the system file for some
  48. # platforms, but this language may not have been enabled when the file
  49. # was first included. Include it again to get the language info.
  50. # Remove this when all compiler info is removed from system files.
  51. if (NOT _INCLUDED_FILE)
  52. include(Platform/${CMAKE_SYSTEM_NAME} OPTIONAL)
  53. endif ()
  54. if(CMAKE_OBJC_SIZEOF_DATA_PTR)
  55. foreach(f ${CMAKE_OBJC_ABI_FILES})
  56. include(${f})
  57. endforeach()
  58. unset(CMAKE_OBJC_ABI_FILES)
  59. endif()
  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. # Save the full path of the file so try_compile can use it.
  67. include(${CMAKE_USER_MAKE_RULES_OVERRIDE} RESULT_VARIABLE _override)
  68. set(CMAKE_USER_MAKE_RULES_OVERRIDE "${_override}")
  69. endif()
  70. if(CMAKE_USER_MAKE_RULES_OVERRIDE_OBJC)
  71. # Save the full path of the file so try_compile can use it.
  72. include(${CMAKE_USER_MAKE_RULES_OVERRIDE_OBJC} RESULT_VARIABLE _override)
  73. set(CMAKE_USER_MAKE_RULES_OVERRIDE_OBJC "${_override}")
  74. endif()
  75. if(CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF")
  76. if(NOT DEFINED CMAKE_OBJC_LINK_WHAT_YOU_USE_FLAG)
  77. set(CMAKE_OBJC_LINK_WHAT_YOU_USE_FLAG "LINKER:--no-as-needed")
  78. endif()
  79. if(NOT DEFINED CMAKE_LINK_WHAT_YOU_USE_CHECK)
  80. set(CMAKE_LINK_WHAT_YOU_USE_CHECK ldd -u -r)
  81. endif()
  82. endif()
  83. # for most systems a module is the same as a shared library
  84. # so unless the variable CMAKE_MODULE_EXISTS is set just
  85. # copy the values from the LIBRARY variables
  86. if(NOT CMAKE_MODULE_EXISTS)
  87. set(CMAKE_SHARED_MODULE_OBJC_FLAGS ${CMAKE_SHARED_LIBRARY_OBJC_FLAGS})
  88. set(CMAKE_SHARED_MODULE_CREATE_OBJC_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_OBJC_FLAGS})
  89. endif()
  90. set(CMAKE_OBJC_FLAGS_INIT "$ENV{OBJCFLAGS} ${CMAKE_OBJC_FLAGS_INIT}")
  91. cmake_initialize_per_config_variable(CMAKE_OBJC_FLAGS "Flags used by the Objective-C compiler")
  92. if(CMAKE_OBJC_STANDARD_LIBRARIES_INIT)
  93. set(CMAKE_OBJC_STANDARD_LIBRARIES "${CMAKE_OBJC_STANDARD_LIBRARIES_INIT}"
  94. CACHE STRING "Libraries linked by default with all Objective-C applications.")
  95. mark_as_advanced(CMAKE_OBJC_STANDARD_LIBRARIES)
  96. endif()
  97. if(NOT CMAKE_OBJC_COMPILER_LAUNCHER AND DEFINED ENV{CMAKE_OBJC_COMPILER_LAUNCHER})
  98. set(CMAKE_OBJC_COMPILER_LAUNCHER "$ENV{CMAKE_OBJC_COMPILER_LAUNCHER}"
  99. CACHE STRING "Compiler launcher for OBJC.")
  100. endif()
  101. if(NOT CMAKE_OBJC_LINKER_LAUNCHER AND DEFINED ENV{CMAKE_OBJC_LINKER_LAUNCHER})
  102. set(CMAKE_OBJC_LINKER_LAUNCHER "$ENV{CMAKE_OBJC_LINKER_LAUNCHER}"
  103. CACHE STRING "Linker launcher for OBJC.")
  104. endif()
  105. include(CMakeCommonLanguageInclude)
  106. # now define the following rule variables
  107. # CMAKE_OBJC_CREATE_SHARED_LIBRARY
  108. # CMAKE_OBJC_CREATE_SHARED_MODULE
  109. # CMAKE_OBJC_COMPILE_OBJECT
  110. # CMAKE_OBJC_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. # Objective-C compiler information
  120. # <CMAKE_OBJC_COMPILER>
  121. # <CMAKE_SHARED_LIBRARY_CREATE_OBJC_FLAGS>
  122. # <CMAKE_SHARED_MODULE_CREATE_OBJC_FLAGS>
  123. # <CMAKE_OBJC_LINK_FLAGS>
  124. # Static library tools
  125. # <CMAKE_AR>
  126. # <CMAKE_RANLIB>
  127. # create an Objective-C shared library
  128. if(NOT CMAKE_OBJC_CREATE_SHARED_LIBRARY)
  129. set(CMAKE_OBJC_CREATE_SHARED_LIBRARY
  130. "<CMAKE_OBJC_COMPILER> <CMAKE_SHARED_LIBRARY_OBJC_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_OBJC_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>")
  131. endif()
  132. # create an Objective-C shared module just copy the shared library rule
  133. if(NOT CMAKE_OBJC_CREATE_SHARED_MODULE)
  134. set(CMAKE_OBJC_CREATE_SHARED_MODULE ${CMAKE_OBJC_CREATE_SHARED_LIBRARY})
  135. endif()
  136. # Create an static archive incrementally for large object file counts.
  137. # If CMAKE_OBJC_CREATE_STATIC_LIBRARY is set it will override these.
  138. if(NOT DEFINED CMAKE_OBJC_ARCHIVE_CREATE)
  139. set(CMAKE_OBJC_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
  140. endif()
  141. if(NOT DEFINED CMAKE_OBJC_ARCHIVE_APPEND)
  142. set(CMAKE_OBJC_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
  143. endif()
  144. if(NOT DEFINED CMAKE_OBJC_ARCHIVE_FINISH)
  145. set(CMAKE_OBJC_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
  146. endif()
  147. # compile an Objective-C file into an object file
  148. if(NOT CMAKE_OBJC_COMPILE_OBJECT)
  149. set(CMAKE_OBJC_COMPILE_OBJECT
  150. "<CMAKE_OBJC_COMPILER> <DEFINES> <INCLUDES> -x objective-c <FLAGS> -o <OBJECT> -c <SOURCE>")
  151. endif()
  152. if(NOT CMAKE_OBJC_LINK_EXECUTABLE)
  153. set(CMAKE_OBJC_LINK_EXECUTABLE
  154. "<CMAKE_OBJC_COMPILER> <FLAGS> <CMAKE_OBJC_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
  155. endif()
  156. if(NOT CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG)
  157. set(CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_OBJC_FLAG})
  158. endif()
  159. if(NOT CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG_SEP)
  160. set(CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_OBJC_FLAG_SEP})
  161. endif()
  162. if(NOT CMAKE_EXECUTABLE_RPATH_LINK_OBJC_FLAG)
  163. set(CMAKE_EXECUTABLE_RPATH_LINK_OBJC_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_OBJC_FLAG})
  164. endif()
  165. set(CMAKE_OBJC_INFORMATION_LOADED 1)