forked from qmathe/gnustep-libobjc2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
329 lines (277 loc) · 9.1 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
cmake_minimum_required(VERSION 2.8)
project(libobjc)
enable_language(ASM)
set(CMAKE_C_FLAGS_DEBUG "-g -O0 -fno-inline ${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_C_FLAGS_RELEASE "-O3 ${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ ${CMAKE_CXX_FLAGS}")
set(libobjc_VERSION 4.6)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fexceptions")
# Build configuration
add_definitions( -DGNUSTEP -D__OBJC_RUNTIME_INTERNAL__=1)
# Probably not needed anymore?
add_definitions( -D_XOPEN_SOURCE=700 -D__BSD_VISIBLE=1 -D_BSD_SOURCE=1)
set(libobjc_ASM_SRCS
block_trampolines.S
objc_msgSend.S)
set(libobjc_OBJC_SRCS
NSBlocks.m
Protocol2.m
arc.m
associate.m
blocks_runtime.m
properties.m)
set(libobjc_C_SRCS
abi_version.c
alias_table.c
block_to_imp.c
caps.c
category_loader.c
class_table.c
dtable.c
eh_personality.c
encoding2.c
gc_none.c
hash_table.c
hooks.c
ivar.c
legacy_malloc.c
loader.c
mutation.m
protocol.c
runtime.c
sarray2.c
selector_table.c
sendmsg2.c
statics_loader.c
toydispatch.c)
set(libobjc_HDRS
objc/Availability.h
objc/Object.h
objc/Protocol.h
objc/blocks_private.h
objc/blocks_runtime.h
objc/capabilities.h
objc/developer.h
objc/encoding.h
objc/hooks.h
objc/message.h
objc/objc-api.h
objc/objc-arc.h
objc/objc-auto.h
objc/objc.h
objc/runtime-deprecated.h
objc/runtime.h
objc/slot.h
)
set(libobjcxx_CXX_SRCS objcxx_eh.cc)
# For release builds, we disable spamming the terminal with warnings about
# selector type mismatches
if (CMAKE_BUILD_TYPE STREQUAL Release)
add_definitions(-DNO_SELECTOR_MISMATCH_WARNINGS)
else ()
add_definitions(-DGC_DEBUG)
endif ()
set(TYPE_DEPENDENT_DISPATCH TRUE CACHE BOOL
"Enable type-dependent dispatch")
if (TYPE_DEPENDENT_DISPATCH)
add_definitions(-DTYPE_DEPENDENT_DISPATCH)
endif ()
set(LOW_MEMORY FALSE CACHE BOOL
"Enable low-memory profile *HIGHLY EXPERIMENTAL*")
if (LOW_MEMORY)
add_definitions(-D__OBJC_LOW_MEMORY__)
endif ()
set(BOEHM_GC FALSE CACHE BOOL
"Enable garbage collection support (not recommended)")
if (BOEHM_GC)
include(FindPkgConfig)
pkg_check_modules(GC REQUIRED bdw-gc)
link_directories(${GC_LIBRARY_DIRS})
# If there's a threaded version, use it
find_library(LIBGC gc-threaded PATHS "${GC_LIBRARY_DIRS}")
if (LIBGC)
else ()
find_library(LIBGC gc PATHS GC_LIBRARY_DIRS)
endif ()
message(STATUS "Using Boehm GC library: ${LIBGC}")
include_directories(GC_INCLUDE_DIRS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${GC_CFLAGS}")
set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} -fobjc-gc")
set(objc_LINK_FLAGS "${objc_LINK_FLAGS} ${GC_CFLAGS}")
add_definitions(-DENABLE_GC)
endif ()
set(LEGACY_COMPAT FALSE CACHE BOOL
"Enable legacy compatibility features")
if (LEGACY_COMPAT)
list(APPEND libobjc_C_SRCS legacy_malloc.c)
else ()
add_definitions(-DNO_LEGACY)
endif ()
find_package(LLVM QUIET)
set(DEFAULT_ENABLE_LLVM ${LLVM_FOUND})
if (DEFAULT_ENABLE_LLVM)
exec_program(llvm-config
ARGS --version
OUTPUT_VARIABLE LLVM_VER)
if (LLVM_VER MATCHES ".*svnn")
set(DEFAULT_ENABLE_LLVM FALSE)
message(STATUS "svn version of LLVM found.")
message(STATUS "Disabling LLVM options unless explicitly enabled.")
elseif (LLVM_VER VERSION_GREATER 3.2)
set(DEFAULT_ENABLE_LLVM FALSE)
message(STATUS "Untested version of LLVM (${LLVM_VER}) found.")
message(STATUS "Disabling LLVM options unless explicitly enabled.")
endif()
endif()
set(LLVM_OPTS ${DEFAULT_ENABLE_LLVM} CACHE BOOL
"Build LLVM Objective-C optimisations")
if (LLVM_OPTS)
add_subdirectory(opts)
message(STATUS "Found LLVM, enabling LLVM optimisations")
endif ()
set(LIBOBJC_NAME "objc" CACHE STRING
"Name of the Objective-C runtime library (e.g. objc2 for libobjc2)")
set(INCLUDE_DIRECTORY "objc" CACHE STRING
"Subdirectory of the include path to install the headers.")
if (${CMAKE_C_COMPILER_ID} MATCHES Clang*)
set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} -Wno-deprecated-objc-isa-usage -Wno-objc-root-class")
if (${CMAKE_C_COMPILER_VERSION} VERSION_GREATER 3.1)
set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} -fobjc-runtime=gnustep-1.7")
endif ()
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i586")
endif ()
else (${CMAKE_C_COMPILER_ID} MATCHES Clang*)
MESSAGE("WARNING: It is strongly recommended that you compile with clang")
endif (${CMAKE_C_COMPILER_ID} MATCHES Clang*)
set(INSTALL_TARGETS objc)
set_source_files_properties(
${libobjc_OBJC_SRCS}
PROPERTIES LANGUAGE C
COMPILE_FLAGS "${CMAKE_OBJC_FLAGS}"
)
#
# C++ Runtime interaction
#
# Try to find libcxxrt.so. We can link to this to provide the C++ ABI layer,
# if it exists.
find_library(CXX_RUNTIME cxxrt)
# If it doesn't, then look for GNU libsupc++.so instead (either works, they're
# ABI compatible).
if (NOT CXX_RUNTIME)
find_library(CXX_RUNTIME supc++)
endif (NOT CXX_RUNTIME)
# If we have a C++ ABI library, then we can produce a single libobjc that works
# for Objective-C and Objective-C++. If not, then we need to provide a
# separate libobjcxx.
if (CXX_RUNTIME)
message(STATUS "Using ${CXX_RUNTIME} as the C++ runtime library")
set(libobjc_CXX_SRCS ${libobjcxx_CXX_SRCS})
# We don't want to link the STL implementation (e.g. libstdc++) if we have
# a separate C++ runtime.
set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
else (CXX_RUNTIME)
message(STATUS "No C++ runtime library found")
add_library(objcxx SHARED ${libobjcxx_CXX_SRCS})
set_target_properties(objcxx PROPERTIES
LINKER_LANGUAGE C
SOVERSION ${libobjc_VERSION}
)
set(CXX_RUNTIME "")
list(APPEND INSTALL_TARGETS objcxx)
endif (CXX_RUNTIME)
# Currently, we actually need pthreads, but we should use the platform's native
# threading implementation (we do for everything except thread-local storage)
set(CMAKE_THREAD_PREFER_PTHREAD)
include(FindThreads)
set(objc_LINK_FLAGS "${objc_LINK_FLAGS} ${CMAKE_THREAD_LIBS_INIT}")
add_library(objc SHARED ${libobjc_C_SRCS} ${libobjc_ASM_SRCS} ${libobjc_OBJC_SRCS} ${libobjc_CXX_SRCS})
set_target_properties(objc PROPERTIES
LINKER_LANGUAGE C
SOVERSION ${libobjc_VERSION}
OUTPUT_NAME ${LIBOBJC_NAME}
LINK_FLAGS "${objc_LINK_FLAGS}"
)
set(BUILD_STATIC_LIBOBJC false CACHE BOOL
"Build the static version of libobjc")
if (BUILD_STATIC_LIBOBJC)
add_library(objc-static STATIC ${libobjc_C_SRCS} ${libobjc_ASM_SRCS} ${libobjc_OBJC_SRCS} ${libobjc_CXX_SRCS})
set_target_properties(objc-static PROPERTIES
POSITION_INDEPENDENT_CODE true
OUTPUT_NAME ${LIBOBJC_NAME})
list(APPEND INSTALL_TARGETS objc-static)
endif ()
# Explicitly link the C++ runtime and libgc if we are compiling with gc support.
target_link_libraries(objc ${CXX_RUNTIME})
if (LIBGC)
target_link_libraries(objc ${LIBGC})
endif ()
# Link libdispatch if available (we'll miss symbols for toydispatch otherwise)
find_library(LIBDISPATCH dispatch)
if (LIBDISPATCH)
target_link_libraries(objc ${LIBDISPATCH})
endif ()
#
# Installation
#
find_program(GNUSTEP_CONFIG gnustep-config)
if (GNUSTEP_CONFIG)
EXEC_PROGRAM(gnustep-config
ARGS "--installation-domain-for=libobjc2"
OUTPUT_VARIABLE DEFAULT_INSTALL_TYPE)
endif ()
# If we have GNUstep environment variables, then default to installing in the
# GNUstep local environment.
if (DEFAULT_INSTALL_TYPE)
else ()
set(DEFAULT_INSTALL_TYPE "NONE")
endif ()
set(GNUSTEP_INSTALL_TYPE ${DEFAULT_INSTALL_TYPE} CACHE STRING
"GNUstep installation type. Options are NONE, SYSTEM, NETWORK or LOCAL.")
if (${GNUSTEP_INSTALL_TYPE} STREQUAL "NONE")
SET(LIB_INSTALL_PATH "lib" CACHE STRING
"Subdirectory of the root prefix where libraries are installed.")
SET(HEADER_INSTALL_PATH "include")
else ()
EXEC_PROGRAM(gnustep-config
ARGS "--variable=GNUSTEP_${GNUSTEP_INSTALL_TYPE}_LIBRARIES"
OUTPUT_VARIABLE LIB_INSTALL_PATH)
EXEC_PROGRAM(gnustep-config
ARGS "--variable=GNUSTEP_${GNUSTEP_INSTALL_TYPE}_HEADERS"
OUTPUT_VARIABLE HEADER_INSTALL_PATH)
endif ()
message(STATUS "GNUstep install type set to ${GNUSTEP_INSTALL_TYPE}")
install(TARGETS ${INSTALL_TARGETS}
LIBRARY DESTINATION ${LIB_INSTALL_PATH}
ARCHIVE DESTINATION ${LIB_INSTALL_PATH})
install(FILES ${libobjc_HDRS}
DESTINATION "${HEADER_INSTALL_PATH}/${INCLUDE_DIRECTORY}")
set(CPACK_GENERATOR TGZ CACHE STRING
"Installer types to generate. Sensible options include TGZ, RPM and DEB")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "GNUstep Objective-C Runtime")
set(CPACK_PACKAGE_VENDOR "The GNUstep Project")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "7")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_CONTACT "GNUstep Developer <[email protected]>")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}")
if (UNIX)
set(CPACK_STRIP_FILES true CACHE BOOL "Strip libraries when packaging")
endif ()
include (CPack)
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
set(TESTS TRUE CACHE BOOL
"Enable building the tests")
if (TESTS)
enable_testing()
add_subdirectory(Test)
endif (TESTS)