1# Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2# file Copyright.txt or https://cmake.org/licensing for details.
3
4
5# This file sets the basic flags for the Objective-C language in CMake.
6# It also loads the available platform file for the system-compiler
7# if it exists.
8# It also loads a system - compiler - processor (or target hardware)
9# specific file, which is mainly useful for crosscompiling and embedded systems.
10
11include(CMakeLanguageInformation)
12
13# some compilers use different extensions (e.g. sdcc uses .rel)
14# so set the extension here first so it can be overridden by the compiler specific file
15set(CMAKE_OBJC_OUTPUT_EXTENSION .o)
16
17if(NOT CMAKE_INCLUDE_FLAG_OBJC)
18  set(CMAKE_INCLUDE_FLAG_OBJC ${CMAKE_INCLUDE_FLAG_C})
19endif()
20
21set(_INCLUDED_FILE 0)
22
23# Load compiler-specific information.
24if(CMAKE_OBJC_COMPILER_ID)
25  include(Compiler/${CMAKE_OBJC_COMPILER_ID}-OBJC OPTIONAL)
26endif()
27
28set(CMAKE_BASE_NAME)
29get_filename_component(CMAKE_BASE_NAME "${CMAKE_OBJC_COMPILER}" NAME_WE)
30if(CMAKE_COMPILER_IS_GNUOBJC)
31  set(CMAKE_BASE_NAME gcc)
32endif()
33
34
35# load a hardware specific file, mostly useful for embedded compilers
36if(CMAKE_SYSTEM_PROCESSOR)
37  if(CMAKE_OBJC_COMPILER_ID)
38    include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_OBJC_COMPILER_ID}-OBJC-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
39  endif()
40  if (NOT _INCLUDED_FILE)
41    include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_BASE_NAME}-${CMAKE_SYSTEM_PROCESSOR} OPTIONAL)
42  endif ()
43endif()
44
45
46# load the system- and compiler specific files
47if(CMAKE_OBJC_COMPILER_ID)
48  include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_OBJC_COMPILER_ID}-OBJC
49    OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
50endif()
51if (NOT _INCLUDED_FILE)
52  include(Platform/${CMAKE_EFFECTIVE_SYSTEM_NAME}-${CMAKE_BASE_NAME}
53    OPTIONAL RESULT_VARIABLE _INCLUDED_FILE)
54endif ()
55
56# load any compiler-wrapper specific information
57if (CMAKE_OBJC_COMPILER_WRAPPER)
58  __cmake_include_compiler_wrapper(OBJC)
59endif ()
60
61# We specify the compiler information in the system file for some
62# platforms, but this language may not have been enabled when the file
63# was first included.  Include it again to get the language info.
64# Remove this when all compiler info is removed from system files.
65if (NOT _INCLUDED_FILE)
66  include(Platform/${CMAKE_SYSTEM_NAME} OPTIONAL)
67endif ()
68
69if(CMAKE_OBJC_SIZEOF_DATA_PTR)
70  foreach(f ${CMAKE_OBJC_ABI_FILES})
71    include(${f})
72  endforeach()
73  unset(CMAKE_OBJC_ABI_FILES)
74endif()
75
76# This should be included before the _INIT variables are
77# used to initialize the cache.  Since the rule variables
78# have if blocks on them, users can still define them here.
79# But, it should still be after the platform file so changes can
80# be made to those values.
81
82if(CMAKE_USER_MAKE_RULES_OVERRIDE)
83  # Save the full path of the file so try_compile can use it.
84  include(${CMAKE_USER_MAKE_RULES_OVERRIDE} RESULT_VARIABLE _override)
85  set(CMAKE_USER_MAKE_RULES_OVERRIDE "${_override}")
86endif()
87
88if(CMAKE_USER_MAKE_RULES_OVERRIDE_OBJC)
89  # Save the full path of the file so try_compile can use it.
90  include(${CMAKE_USER_MAKE_RULES_OVERRIDE_OBJC} RESULT_VARIABLE _override)
91  set(CMAKE_USER_MAKE_RULES_OVERRIDE_OBJC "${_override}")
92endif()
93
94if(CMAKE_EXECUTABLE_FORMAT STREQUAL "ELF")
95  if(NOT DEFINED CMAKE_OBJC_LINK_WHAT_YOU_USE_FLAG)
96    set(CMAKE_OBJC_LINK_WHAT_YOU_USE_FLAG "LINKER:--no-as-needed")
97  endif()
98  if(NOT DEFINED CMAKE_LINK_WHAT_YOU_USE_CHECK)
99    set(CMAKE_LINK_WHAT_YOU_USE_CHECK ldd -u -r)
100  endif()
101endif()
102
103
104# for most systems a module is the same as a shared library
105# so unless the variable CMAKE_MODULE_EXISTS is set just
106# copy the values from the LIBRARY variables
107if(NOT CMAKE_MODULE_EXISTS)
108  set(CMAKE_SHARED_MODULE_OBJC_FLAGS ${CMAKE_SHARED_LIBRARY_OBJC_FLAGS})
109  set(CMAKE_SHARED_MODULE_CREATE_OBJC_FLAGS ${CMAKE_SHARED_LIBRARY_CREATE_OBJC_FLAGS})
110endif()
111
112set(CMAKE_OBJC_FLAGS_INIT "$ENV{OBJCFLAGS} ${CMAKE_OBJC_FLAGS_INIT}")
113
114cmake_initialize_per_config_variable(CMAKE_OBJC_FLAGS "Flags used by the Objective-C compiler")
115
116if(CMAKE_OBJC_STANDARD_LIBRARIES_INIT)
117  set(CMAKE_OBJC_STANDARD_LIBRARIES "${CMAKE_OBJC_STANDARD_LIBRARIES_INIT}"
118    CACHE STRING "Libraries linked by default with all Objective-C applications.")
119  mark_as_advanced(CMAKE_OBJC_STANDARD_LIBRARIES)
120endif()
121
122if(NOT CMAKE_OBJC_COMPILER_LAUNCHER AND DEFINED ENV{CMAKE_OBJC_COMPILER_LAUNCHER})
123  set(CMAKE_OBJC_COMPILER_LAUNCHER "$ENV{CMAKE_OBJC_COMPILER_LAUNCHER}"
124    CACHE STRING "Compiler launcher for OBJC.")
125endif()
126
127if(NOT CMAKE_OBJC_LINKER_LAUNCHER AND DEFINED ENV{CMAKE_OBJC_LINKER_LAUNCHER})
128  set(CMAKE_OBJC_LINKER_LAUNCHER "$ENV{CMAKE_OBJC_LINKER_LAUNCHER}"
129    CACHE STRING "Linker launcher for OBJC.")
130endif()
131
132include(CMakeCommonLanguageInclude)
133
134# now define the following rule variables
135
136# CMAKE_OBJC_CREATE_SHARED_LIBRARY
137# CMAKE_OBJC_CREATE_SHARED_MODULE
138# CMAKE_OBJC_COMPILE_OBJECT
139# CMAKE_OBJC_LINK_EXECUTABLE
140
141# variables supplied by the generator at use time
142# <TARGET>
143# <TARGET_BASE> the target without the suffix
144# <OBJECTS>
145# <OBJECT>
146# <LINK_LIBRARIES>
147# <FLAGS>
148# <LINK_FLAGS>
149
150# Objective-C compiler information
151# <CMAKE_OBJC_COMPILER>
152# <CMAKE_SHARED_LIBRARY_CREATE_OBJC_FLAGS>
153# <CMAKE_SHARED_MODULE_CREATE_OBJC_FLAGS>
154# <CMAKE_OBJC_LINK_FLAGS>
155
156# Static library tools
157# <CMAKE_AR>
158# <CMAKE_RANLIB>
159
160
161# create an Objective-C shared library
162if(NOT CMAKE_OBJC_CREATE_SHARED_LIBRARY)
163  set(CMAKE_OBJC_CREATE_SHARED_LIBRARY
164      "<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>")
165endif()
166
167# create an Objective-C shared module just copy the shared library rule
168if(NOT CMAKE_OBJC_CREATE_SHARED_MODULE)
169  set(CMAKE_OBJC_CREATE_SHARED_MODULE ${CMAKE_OBJC_CREATE_SHARED_LIBRARY})
170endif()
171
172# Create an static archive incrementally for large object file counts.
173# If CMAKE_OBJC_CREATE_STATIC_LIBRARY is set it will override these.
174if(NOT DEFINED CMAKE_OBJC_ARCHIVE_CREATE)
175  set(CMAKE_OBJC_ARCHIVE_CREATE "<CMAKE_AR> qc <TARGET> <LINK_FLAGS> <OBJECTS>")
176endif()
177if(NOT DEFINED CMAKE_OBJC_ARCHIVE_APPEND)
178  set(CMAKE_OBJC_ARCHIVE_APPEND "<CMAKE_AR> q <TARGET> <LINK_FLAGS> <OBJECTS>")
179endif()
180if(NOT DEFINED CMAKE_OBJC_ARCHIVE_FINISH)
181  set(CMAKE_OBJC_ARCHIVE_FINISH "<CMAKE_RANLIB> <TARGET>")
182endif()
183
184# compile an Objective-C file into an object file
185if(NOT CMAKE_OBJC_COMPILE_OBJECT)
186  set(CMAKE_OBJC_COMPILE_OBJECT
187    "<CMAKE_OBJC_COMPILER> <DEFINES> <INCLUDES> -x objective-c <FLAGS> -o <OBJECT> -c <SOURCE>")
188endif()
189
190if(NOT CMAKE_OBJC_LINK_EXECUTABLE)
191  set(CMAKE_OBJC_LINK_EXECUTABLE
192    "<CMAKE_OBJC_COMPILER> <FLAGS> <CMAKE_OBJC_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
193endif()
194
195if(NOT CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG)
196  set(CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG ${CMAKE_SHARED_LIBRARY_RUNTIME_OBJC_FLAG})
197endif()
198
199if(NOT CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG_SEP)
200  set(CMAKE_EXECUTABLE_RUNTIME_OBJC_FLAG_SEP ${CMAKE_SHARED_LIBRARY_RUNTIME_OBJC_FLAG_SEP})
201endif()
202
203if(NOT CMAKE_EXECUTABLE_RPATH_LINK_OBJC_FLAG)
204  set(CMAKE_EXECUTABLE_RPATH_LINK_OBJC_FLAG ${CMAKE_SHARED_LIBRARY_RPATH_LINK_OBJC_FLAG})
205endif()
206
207set(CMAKE_OBJC_INFORMATION_LOADED 1)
208