CMakeOBJCInformation.cmake 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. include(CMakeCommonLanguageInclude)
  90. # now define the following rule variables
  91. # CMAKE_OBJC_CREATE_SHARED_LIBRARY
  92. # CMAKE_OBJC_CREATE_SHARED_MODULE
  93. # CMAKE_OBJC_COMPILE_OBJECT
  94. # CMAKE_OBJC_LINK_EXECUTABLE
  95. # variables supplied by the generator at use time
  96. # <TARGET>
  97. # <TARGET_BASE> the target without the suffix
  98. # <OBJECTS>
  99. # <OBJECT>
  100. # <LINK_LIBRARIES>
  101. # <FLAGS>
  102. # <LINK_FLAGS>
  103. # Objective-C compiler information
  104. # <CMAKE_OBJC_COMPILER>
  105. # <CMAKE_SHARED_LIBRARY_CREATE_OBJC_FLAGS>
  106. # <CMAKE_SHARED_MODULE_CREATE_OBJC_FLAGS>
  107. # <CMAKE_OBJC_LINK_FLAGS>
  108. # Static library tools
  109. # <CMAKE_AR>
  110. # <CMAKE_RANLIB>
  111. # create an Objective-C shared library
  112. if(NOT CMAKE_OBJC_CREATE_SHARED_LIBRARY)
  113. set(CMAKE_OBJC_CREATE_SHARED_LIBRARY
  114. "<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>")
  115. endif()
  116. # create an Objective-C shared module just copy the shared library rule
  117. if(NOT CMAKE_OBJC_CREATE_SHARED_MODULE)
  118. set(CMAKE_OBJC_CREATE_SHARED_MODULE ${CMAKE_OBJC_CREATE_SHARED_LIBRARY})
  119. endif()
  120. # Create an static archive incrementally for large object file counts.
  121. # If CMAKE_OBJC_CREATE_STATIC_LIBRARY is set it will override these.
  122. if(NOT DEFINED CMAKE_OBJC_ARCHIVE_CREATE)
  123. set(CMAKE_OBJC_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
  124. endif()
  125. if(NOT DEFINED CMAKE_OBJC_ARCHIVE_APPEND)
  126. set(CMAKE_OBJC_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
  127. endif()
  128. if(NOT DEFINED CMAKE_OBJC_ARCHIVE_FINISH)
  129. set(CMAKE_OBJC_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
  130. endif()
  131. # compile an Objective-C file into an object file
  132. if(NOT CMAKE_OBJC_COMPILE_OBJECT)
  133. set(CMAKE_OBJC_COMPILE_OBJECT
  134. "<CMAKE_OBJC_COMPILER> <DEFINES> <INCLUDES> <FLAGS> -x objective-c -o <OBJECT> -c <SOURCE>")
  135. endif()
  136. if(NOT CMAKE_OBJC_LINK_EXECUTABLE)
  137. set(CMAKE_OBJC_LINK_EXECUTABLE
  138. "<CMAKE_OBJC_COMPILER> <FLAGS> <CMAKE_OBJC_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
  139. endif()
  140. if(NOT CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG)
  141. set(CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_OBJC_FLAG})
  142. endif()
  143. if(NOT CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG_SEP)
  144. set(CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_OBJC_FLAG_SEP})
  145. endif()
  146. if(NOT CMAKE_EXECUTABLE_RPATH_LINK_OBJC_FLAG)
  147. set(CMAKE_EXECUTABLE_RPATH_LINK_OBJC_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_OBJC_FLAG})
  148. endif()
  149. set(CMAKE_OBJC_INFORMATION_LOADED 1)