CMakeOBJCInformation.cmake 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. # for most systems a module is the same as a shared library
  76. # so unless the variable CMAKE_MODULE_EXISTS is set just
  77. # copy the values from the LIBRARY variables
  78. if(NOT CMAKE_MODULE_EXISTS)
  79. set(CMAKE_SHARED_MODULE_OBJC_FLAGS ${CMAKE_SHARED_LIBRARY_OBJC_FLAGS})
  80. set(CMAKE_SHARED_MODULE_CREATE_OBJC_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_OBJC_FLAGS})
  81. endif()
  82. set(CMAKE_OBJC_FLAGS_INIT "$ENV{OBJCFLAGS} ${CMAKE_OBJC_FLAGS_INIT}")
  83. cmake_initialize_per_config_variable(CMAKE_OBJC_FLAGS "Flags used by the Objective-C compiler")
  84. if(CMAKE_OBJC_STANDARD_LIBRARIES_INIT)
  85. set(CMAKE_OBJC_STANDARD_LIBRARIES "${CMAKE_OBJC_STANDARD_LIBRARIES_INIT}"
  86. CACHE STRING "Libraries linked by default with all Objective-C applications.")
  87. mark_as_advanced(CMAKE_OBJC_STANDARD_LIBRARIES)
  88. endif()
  89. if(NOT CMAKE_OBJC_COMPILER_LAUNCHER AND DEFINED ENV{CMAKE_OBJC_COMPILER_LAUNCHER})
  90. set(CMAKE_OBJC_COMPILER_LAUNCHER "$ENV{CMAKE_OBJC_COMPILER_LAUNCHER}"
  91. CACHE STRING "Compiler launcher for OBJC.")
  92. endif()
  93. include(CMakeCommonLanguageInclude)
  94. # now define the following rule variables
  95. # CMAKE_OBJC_CREATE_SHARED_LIBRARY
  96. # CMAKE_OBJC_CREATE_SHARED_MODULE
  97. # CMAKE_OBJC_COMPILE_OBJECT
  98. # CMAKE_OBJC_LINK_EXECUTABLE
  99. # variables supplied by the generator at use time
  100. # <TARGET>
  101. # <TARGET_BASE> the target without the suffix
  102. # <OBJECTS>
  103. # <OBJECT>
  104. # <LINK_LIBRARIES>
  105. # <FLAGS>
  106. # <LINK_FLAGS>
  107. # Objective-C compiler information
  108. # <CMAKE_OBJC_COMPILER>
  109. # <CMAKE_SHARED_LIBRARY_CREATE_OBJC_FLAGS>
  110. # <CMAKE_SHARED_MODULE_CREATE_OBJC_FLAGS>
  111. # <CMAKE_OBJC_LINK_FLAGS>
  112. # Static library tools
  113. # <CMAKE_AR>
  114. # <CMAKE_RANLIB>
  115. # create an Objective-C shared library
  116. if(NOT CMAKE_OBJC_CREATE_SHARED_LIBRARY)
  117. set(CMAKE_OBJC_CREATE_SHARED_LIBRARY
  118. "<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>")
  119. endif()
  120. # create an Objective-C shared module just copy the shared library rule
  121. if(NOT CMAKE_OBJC_CREATE_SHARED_MODULE)
  122. set(CMAKE_OBJC_CREATE_SHARED_MODULE ${CMAKE_OBJC_CREATE_SHARED_LIBRARY})
  123. endif()
  124. # Create an static archive incrementally for large object file counts.
  125. # If CMAKE_OBJC_CREATE_STATIC_LIBRARY is set it will override these.
  126. if(NOT DEFINED CMAKE_OBJC_ARCHIVE_CREATE)
  127. set(CMAKE_OBJC_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
  128. endif()
  129. if(NOT DEFINED CMAKE_OBJC_ARCHIVE_APPEND)
  130. set(CMAKE_OBJC_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
  131. endif()
  132. if(NOT DEFINED CMAKE_OBJC_ARCHIVE_FINISH)
  133. set(CMAKE_OBJC_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
  134. endif()
  135. # compile an Objective-C file into an object file
  136. if(NOT CMAKE_OBJC_COMPILE_OBJECT)
  137. set(CMAKE_OBJC_COMPILE_OBJECT
  138. "<CMAKE_OBJC_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -x objective-c -o <OBJECT> -c <SOURCE>")
  139. endif()
  140. if(NOT CMAKE_OBJC_LINK_EXECUTABLE)
  141. set(CMAKE_OBJC_LINK_EXECUTABLE
  142. "<CMAKE_OBJC_COMPILER> <FLAGS> <CMAKE_OBJC_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
  143. endif()
  144. if(NOT CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG)
  145. set(CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_OBJC_FLAG})
  146. endif()
  147. if(NOT CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG_SEP)
  148. set(CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_OBJC_FLAG_SEP})
  149. endif()
  150. if(NOT CMAKE_EXECUTABLE_RPATH_LINK_OBJC_FLAG)
  151. set(CMAKE_EXECUTABLE_RPATH_LINK_OBJC_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_OBJC_FLAG})
  152. endif()
  153. set(CMAKE_OBJC_INFORMATION_LOADED 1)