This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
252 lines (197 loc) · 7.83 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
cmake_minimum_required(VERSION 3.10)
include(macros.cmake)
include(ExternalProject)
include(CheckTypeSize)
if ((CMAKE_HOST_UNIX) AND (${CMAKE_HOST_SYSTEM_NAME} MATCHES "CYGWIN*"))
message(STATUS "Building on CYGWIN CMAKE: Adapting paths")
set(CYGWIN 1)
set(WIN 1)
# specify the cross compiler
set(CMAKE_TOOLCHAIN_PREFIX x86_64-w64-mingw32)
SET(CMAKE_C_COMPILER ${CMAKE_TOOLCHAIN_PREFIX}-gcc)
SET(CMAKE_CXX_COMPILER ${CMAKE_TOOLCHAIN_PREFIX}-g++)
SET(CMAKE_RC_COMPILER ${CMAKE_TOOLCHAIN_PREFIX}-windres)
SET(CMAKE_SYSTEM_PROCESSOR x86_64)
endif()
project(PThreadedFFI)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(OSX 1)
endif()
if(WIN)
include(win.cmake)
elseif(OSX)
include(osx.cmake)
else()
include(linux.cmake)
endif()
set(VERSION_MAJOR 1)
set(VERSION_MINOR 4)
set(VERSION_PATCH 0)
check_type_size("void*" SIZEOF_VOID_P)
get_commit_hash(GIT_COMMIT_HASH)
get_git_describe(GIT_DESCRIBE)
get_git_date(GIT_COMMIT_DATE)
set(EXECUTABLE_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/build/bin")
set(LIBRARY_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/build/bin")
#
# Creates a custom target to downloand VM headers
#
make_directory("build/vmIncludes")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/vmIncludes/include/pharovm/pharo.h"
COMMAND wget ${HEADER_URL}
COMMAND unzip PharoVM-*-include.zip
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build/vmIncludes"
COMMENT "Downloading Pharo VM Headers")
add_custom_target(vmIncludes
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/build/vmIncludes/include/pharovm/pharo.h"
COMMENT "Obtaining Pharo VM Headers")
#
# LibFFI
#
if(NOT SKIP_LIBFFI)
ExternalProject_Add(build_libFFI
PREFIX "${CMAKE_CURRENT_BINARY_DIR}/build/libffi"
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/build/libffi/src"
STAMP_DIR "${CMAKE_CURRENT_BINARY_DIR}/build/libffi/stamp"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/build/libffi/src"
UPDATE_COMMAND ""
GIT_REPOSITORY "https://github.com/libffi/libffi.git"
GIT_TAG "v3.3"
CONFIGURE_COMMAND "./autogen.sh" COMMAND ./configure "--target=${LIBFFI_TARGET}" "--disable-docs" "--prefix=${CMAKE_CURRENT_BINARY_DIR}/build/libffi/install" "CC=${CMAKE_C_COMPILER}" "CXX=${CMAKE_C_COMPILER}" ${LIBFFI_ADDITIONAL}
BUILD_COMMAND "${CMAKE_MAKE_PROGRAM}" ${LIBFFI_ADDITIONAL}
)
if(OSX)
add_custom_command(
OUTPUT ${LIBFFI_OUTPUT}
DEPENDS build_libFFI
COMMAND install_name_tool -id "@executable_path/Plugins/libffi.7.dylib" "${CMAKE_CURRENT_BINARY_DIR}/build/libffi/install/lib/libffi.7.dylib"
COMMAND install_name_tool -id "@executable_path/Plugins/libffi.dylib" "${CMAKE_CURRENT_BINARY_DIR}/build/libffi/install/lib/libffi.dylib"
COMMAND cp "${CMAKE_CURRENT_BINARY_DIR}/build/libffi/install/lib/${DYLIB_EXT}" "${CMAKE_CURRENT_BINARY_DIR}/build/bin/"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build/bin"
COMMENT "Changing RPath of Libffi")
else()
add_custom_command(
OUTPUT ${LIBFFI_OUTPUT}
DEPENDS build_libFFI
COMMAND cp "${LIBFFI_FILES}" "${CMAKE_CURRENT_BINARY_DIR}/build/bin/"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build/bin"
COMMENT "Copying of Libffi")
endif()
link_directories("${CMAKE_CURRENT_BINARY_DIR}/build/libffi/install/lib")
add_custom_target(libFFI DEPENDS "${LIBFFI_OUTPUT}")
endif()
#
# Definition of the Plugin
#
set(PLUGIN_NAME PThreadedPlugin)
# Plugin sources
set(PLUGIN_SOURCES
plugin/src/functionDefinitionPrimitives.c
plugin/src/primitiveUtils.c
plugin/src/PThreadedPlugin.c
plugin/src/types.c
plugin/src/typesPrimitives.c
plugin/src/utils.c
plugin/src/primitiveCalls.c
plugin/src/callbacks/callbackPrimitives.c
plugin/src/callbacks/callbacks.c
plugin/src/queue/threadSafeQueue.c
plugin/src/sameThread/sameThread.c
plugin/src/semaphores/pharoSemaphore.c
plugin/src/semaphores/platformSemaphore.c
plugin/src/semaphores/semaphore.c
plugin/src/worker/worker.c
plugin/src/worker/workerPrimitives.c
plugin/src/worker/workerTask.c
)
addLibraryWithRPATH(${PLUGIN_NAME} SHARED ${PLUGIN_SOURCES})
target_link_libraries(${PLUGIN_NAME} "ffi")
if(WIN)
target_link_libraries(${PLUGIN_NAME} "pthread")
endif(WIN)
if(NOT SKIP_LIBFFI)
add_dependencies(${PLUGIN_NAME} vmIncludes libFFI)
link_directories(BEFORE "${CMAKE_CURRENT_BINARY_DIR}/build/libffi/install/lib")
else()
add_dependencies(${PLUGIN_NAME} vmIncludes)
endif()
target_compile_options(${PLUGIN_NAME} PUBLIC "-g")
target_include_directories(${PLUGIN_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/plugin/includes" )
target_include_directories(${PLUGIN_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/build/vmIncludes/include")
target_include_directories(${PLUGIN_NAME} PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/build/libffi/install/include/" )
#
# Definition of the Test Library
#
set(TEST_LIBRARY TestLibrary)
# Plugin sources
set(TEST_LIBRARY_SOURCES
testLibrary/src/basic_types.c
testLibrary/src/callback_types.c
testLibrary/src/callbacks.c
testLibrary/src/callout.c
testLibrary/src/registerCallback.c
testLibrary/src/structures.c
)
addLibraryWithRPATH(${TEST_LIBRARY} SHARED ${TEST_LIBRARY_SOURCES})
if(NOT SKIP_LIBFFI)
add_dependencies(${TEST_LIBRARY} ${PLUGIN_NAME} vmIncludes libFFI)
target_compile_options(${TEST_LIBRARY} PUBLIC "-g")
else()
add_dependencies(${TEST_LIBRARY} ${PLUGIN_NAME} vmIncludes)
endif()
target_include_directories(${TEST_LIBRARY} PRIVATE "${CMAKE_SOURCE_DIR}/testLibrary/includes" )
#
# Preparing tests
#
make_directory("${CMAKE_CURRENT_BINARY_DIR}/build/test")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/build/test/Pharo.image"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/build/bin/${DYLIB_EXT}" "${CMAKE_CURRENT_BINARY_DIR}/build/bin/${TEST_LIBRARY_DLL}"
COMMAND wget -O - "get.pharo.org/64/90+vmHeadlessLatest" | bash
COMMAND rm -rf "${CMAKE_CURRENT_BINARY_DIR}/build/test/pharo-vm/*"
COMMAND wget "${VM_URL}"
COMMAND unzip "PharoVM-*-bin.zip" -d "${CMAKE_CURRENT_BINARY_DIR}/build/test/pharo-vm/"
COMMAND cp "${CMAKE_CURRENT_BINARY_DIR}/build/bin/${DYLIB_EXT}" ${PHARO_PLUGIN_DIR}
COMMAND cp "${CMAKE_CURRENT_BINARY_DIR}/build/bin/${TEST_LIBRARY_DLL}" .
COMMAND ./pharo Pharo.image metacello install "tonel://${CMAKE_CURRENT_SOURCE_DIR_TO_OUT}/src" BaselineOfThreadedFFI
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build/test"
COMMENT "Creating Test Image")
add_custom_target("prepare-tests"
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/build/test/Pharo.image"
COMMENT "Preparing Tests")
#
# Adding tests
#
enable_testing()
add_test(
NAME "UnifiedFFI-Tests"
COMMAND ./pharo Pharo.image test --junit-xml-output --fail-on-failure "UnifiedFFI-Tests"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build/test")
add_test(
NAME "ThreadedFFI-UFFI-Tests"
COMMAND ./pharo Pharo.image test --junit-xml-output --fail-on-failure "ThreadedFFI-UFFI-Tests"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build/test")
#
# Packaging Setup
#
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/build/dist")
install(
DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build/bin/"
USE_SOURCE_PERMISSIONS
DESTINATION "./"
USE_SOURCE_PERMISSIONS FILES_MATCHING PATTERN *)
make_directory("build/packages")
get_full_platform_name(FULL_PLATFORM_NAME)
set(CPACK_PACKAGE_DESCRIPTION "Pharo Threaded FFI for ${FULL_PLATFORM_NAME}")
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
set(CPACK_PACKAGE_VENDOR "Pharo")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://pharo.org")
set(CPACK_PACKAGE_FILE_NAME "PThreadedFFI-${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}-${FULL_PLATFORM_NAME}")
set(CPACK_PACKAGE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/build/packages")
set(CPACK_PACKAGE_CHECKSUM "SHA1")
set(CPACK_GENERATOR "ZIP")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY FALSE)
include (CPack)