-
Notifications
You must be signed in to change notification settings - Fork 26
/
CMakeLists.txt
232 lines (184 loc) · 8.37 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
project(SBMLAPIPlugin)
# Name and version of our package
set(PACKAGE_NAME libSBML)
set(PACKAGE_VERSION 5.16.0)
# Version of our package's libraries
set(MAJOR_LIBRARY_VERSION 5)
set(LIBRARY_VERSION ${MAJOR_LIBRARY_VERSION}.16.0)
# Git tag for our library
set(GIT_TAG v5.16.0)
# Package repository
set(PACKAGE_REPOSITORY libsbml)
# Specify where our local package will be installed
set(FULL_LOCAL_EXTERNAL_PACKAGE_DIR ${PROJECT_SOURCE_DIR}/${LOCAL_EXTERNAL_PACKAGE_DIR})
# Name of our package's shared library (and of its import library, if any)
if(WIN32)
set(SHARED_LIBRARY libsbml${CMAKE_SHARED_LIBRARY_SUFFIX})
set(IMPORT_LIBRARY libsbml${CMAKE_IMPORT_LIBRARY_SUFFIX})
else()
set(SHARED_LIBRARY ${CMAKE_SHARED_LIBRARY_PREFIX}sbml${CMAKE_SHARED_LIBRARY_SUFFIX_PRE}.${MAJOR_LIBRARY_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX_POST})
set(IMPORT_LIBRARY ${SHARED_LIBRARY})
endif()
# Retrieve our package's binaries
set(EXTERNAL_BINARIES_DIR ${FULL_LOCAL_EXTERNAL_PACKAGE_DIR}/lib)
set(EXTERNAL_BINARIES
${SHARED_LIBRARY}
)
# Specify the files that need to have their SHA-1 value checked
set(SHA1_FILES
lib/${SHARED_LIBRARY}
)
if(WIN32)
list(APPEND SHA1_FILES
lib/${IMPORT_LIBRARY}
)
endif()
# Use the pre-built version of our package unless instructed otherwise
if(USE_PREBUILT_SBMLAPI_PACKAGE)
# Retrieve the plugin's package
string(REPLACE "${${CMAKE_PROJECT_NAME}_SOURCE_DIR}/" ""
RELATIVE_PROJECT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/${REMOTE_EXTERNAL_PACKAGE_DIR}")
if(WIN32)
if(RELEASE_MODE)
retrieve_package_file(${PACKAGE_NAME} ${PACKAGE_VERSION}
${RELATIVE_PROJECT_SOURCE_DIR} ca2eef818a6a1ea5c717a0b6c1f09bee3509b667
PACKAGE_REPOSITORY ${PACKAGE_REPOSITORY}
SHA1_FILES ${SHA1_FILES}
SHA1_VALUES 6b46f6ee6d0af8480e21f365f9b332f804a8c5d1
71de6d57060841d7a109b1e8137df836ed7f5fab)
else()
retrieve_package_file(${PACKAGE_NAME} ${PACKAGE_VERSION}
${RELATIVE_PROJECT_SOURCE_DIR} cf2c0431a83ac1d9f5778229fe516e311155aedd
PACKAGE_REPOSITORY ${PACKAGE_REPOSITORY}
SHA1_FILES ${SHA1_FILES}
SHA1_VALUES dbfe9bc7c1b8c48aa1a616bbe80df6bdd88f0412
f7f60e508009a01b1db08e6a5c51eea52b09afdd)
endif()
elseif(APPLE)
retrieve_package_file(${PACKAGE_NAME} ${PACKAGE_VERSION}
${RELATIVE_PROJECT_SOURCE_DIR} 057474b665d11fb2cbb33289f75f7648f4321aa7
PACKAGE_REPOSITORY ${PACKAGE_REPOSITORY}
SHA1_FILES ${SHA1_FILES}
SHA1_VALUES 032edbbf75dde4457afcf36d62fc96ca4aff7e11)
else()
retrieve_package_file(${PACKAGE_NAME} ${PACKAGE_VERSION}
${RELATIVE_PROJECT_SOURCE_DIR} 20a00698c35c909570ce4d2936b327ad7090a26a
PACKAGE_REPOSITORY ${PACKAGE_REPOSITORY}
SHA1_FILES ${SHA1_FILES}
SHA1_VALUES 3fce349986f1abaff0710b205f431f97c37d3f51)
endif()
else()
# Download some dependencies for Windows, if needed
if(WIN32)
if(RELEASE_MODE)
set(MODE release)
else()
set(MODE debug)
endif()
set(DEPENDENCIES_FILENAME libSBML_dependencies_vs14_${MODE}_x64.zip)
set(DEPENDENCIES_DIR ${CMAKE_SOURCE_DIR}/src/plugins/api/SBMLAPI/ext/dependencies)
set(DEPENDENCIES_MODE_DIR ${DEPENDENCIES_DIR}/${MODE})
if(NOT EXISTS ${DEPENDENCIES_MODE_DIR})
message("Retrieving the 'libSBML' dependencies...")
set(REAL_DEPENDENCIES_FILENAME ${DEPENDENCIES_DIR}/${DEPENDENCIES_FILENAME})
file(DOWNLOAD "https://github.com/opencor/${PACKAGE_REPOSITORY}/releases/download/${GIT_TAG}/${DEPENDENCIES_FILENAME}" ${REAL_DEPENDENCIES_FILENAME}
SHOW_PROGRESS STATUS STATUS)
list(GET STATUS 0 STATUS_CODE)
if(${STATUS_CODE} EQUAL 0)
execute_process(COMMAND ${CMAKE_COMMAND} -E tar -xf ${REAL_DEPENDENCIES_FILENAME}
WORKING_DIRECTORY ${DEPENDENCIES_DIR}
OUTPUT_QUIET)
execute_process(COMMAND ${CMAKE_COMMAND} -E rename "libSBML Dependencies-1.0.0-b1-win64" ${MODE}
WORKING_DIRECTORY ${DEPENDENCIES_DIR}
OUTPUT_QUIET)
file(REMOVE ${REAL_DEPENDENCIES_FILENAME})
else()
file(REMOVE ${REAL_DEPENDENCIES_FILENAME})
# Note: this is in case we had an HTTP error of sorts, in which case we
# would end up with an empty file...
message(FATAL_ERROR "The libSBML depencies could not be retrieved...")
endif()
endif()
endif()
# Ignore some warnings
if(APPLE)
set(PACKAGE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-switch")
endif()
# Build libSBML as an external project
set(PACKAGE_BUILD ${PACKAGE_NAME}Build)
ExternalProject_Add(${PACKAGE_BUILD}
SOURCE_DIR
${CMAKE_SOURCE_DIR}/ext/${PACKAGE_NAME}
INSTALL_DIR
${FULL_LOCAL_EXTERNAL_PACKAGE_DIR}
GIT_REPOSITORY
https://github.com/opencor/libsbml
GIT_TAG
${GIT_TAG}
CMAKE_CACHE_ARGS
-DCMAKE_C_FLAGS:STRING=${PACKAGE_C_FLAGS}
CMAKE_GENERATOR
${CMAKE_GENERATOR}
CMAKE_ARGS
${CMAKE_ARGS}
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DLIBSBML_DEPENDENCY_DIR=${DEPENDENCIES_MODE_DIR}
-DWITH_BZIP2=OFF
-DWITH_CPP_NAMESPACE=ON
-DWITH_SWIG=OFF
-DWITH_ZLIB=OFF
BUILD_BYPRODUCTS
<INSTALL_DIR>/lib/${IMPORT_LIBRARY}
)
# Do some post-processing that is specific to each platform
if(WIN32)
# We want both our shared and import libraries to be in the same place
ExternalProject_Add_Step(${PACKAGE_BUILD} copyDll
COMMAND ${CMAKE_COMMAND} -E copy bin/${SHARED_LIBRARY} lib
WORKING_DIRECTORY ${FULL_LOCAL_EXTERNAL_PACKAGE_DIR}
DEPENDEES install)
else()
# Dereference the symbolic link to the libraries since CMake's tar can't
# do this
ExternalProject_Add_Step(${PACKAGE_BUILD} copyLibrary
COMMAND ${CMAKE_COMMAND} -E remove -f ${SHARED_LIBRARY}
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SHARED_LIBRARY_PREFIX}sbml${CMAKE_SHARED_LIBRARY_SUFFIX_PRE}.${LIBRARY_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX_POST}
${SHARED_LIBRARY}
WORKING_DIRECTORY ${EXTERNAL_BINARIES_DIR}
DEPENDEES install)
endif()
# Package our external project
create_package_file(${PACKAGE_NAME} ${PACKAGE_VERSION}
${LOCAL_EXTERNAL_PACKAGE_DIR}
PACKAGE_REPOSITORY ${PACKAGE_REPOSITORY}
PACKAGED_FILES include ${SHA1_FILES}
SHA1_FILES ${SHA1_FILES}
TARGET ${PACKAGE_BUILD})
set(DEPENDS_ON ${PACKAGE_BUILD})
endif()
# Allow other external projects to find our libSBML package
set(SBMLAPI_ROOT_DIR ${FULL_LOCAL_EXTERNAL_PACKAGE_DIR} PARENT_SCOPE)
set(SBMLAPI_INCLUDE_DIR ${FULL_LOCAL_EXTERNAL_PACKAGE_DIR}/include PARENT_SCOPE)
set(SBMLAPI_LIBRARY ${EXTERNAL_BINARIES_DIR}/${IMPORT_LIBRARY} PARENT_SCOPE)
# Add the plugin
# Note: we would normally use '${PACKAGE_NAME}' rather than 'SBMLAPI', but it
# can't be done here since the name of our package is different from that
# of our plugin...
add_plugin(SBMLAPI
SOURCES
../../plugininfo.cpp
src/sbmlapiplugin.cpp
HEADERS_MOC
src/sbmlapiplugin.h
QT_MODULES
Core
EXTERNAL_BINARIES_DIR
${EXTERNAL_BINARIES_DIR}
EXTERNAL_BINARIES
${EXTERNAL_BINARIES}
TESTS
tests
DEPENDS_ON
${DEPENDS_ON}
)