-
Notifications
You must be signed in to change notification settings - Fork 26
/
CMakeLists.txt
177 lines (140 loc) · 5.91 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
project(zlibPlugin)
# Name and version of our package
set(PACKAGE_NAME zlib)
set(PACKAGE_VERSION 1.2.11)
# Version of our library
set(MAJOR_LIBRARY_VERSION 1)
set(LIBRARY_VERSION ${MAJOR_LIBRARY_VERSION}.2.11)
# Git tag for our library
set(GIT_TAG v1.2.11)
# 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)
if(RELEASE_MODE)
set(DEBUG_TAG)
else()
set(DEBUG_TAG d)
endif()
set(SHARED_LIBRARY zlib${DEBUG_TAG}${CMAKE_SHARED_LIBRARY_SUFFIX})
set(IMPORT_LIBRARY zlib${DEBUG_TAG}${CMAKE_IMPORT_LIBRARY_SUFFIX})
else()
set(SHARED_LIBRARY ${CMAKE_SHARED_LIBRARY_PREFIX}z${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_ZLIB_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} 40fb8671f71f4ecd30c497da77a056deff27e68e
SHA1_FILES ${SHA1_FILES}
SHA1_VALUES 14aa954cecdf06d43bb0781b293df7f53b5a525f
1f7132f2eb4416f2b9771f0ddb19f834783a3059)
else()
retrieve_package_file(${PACKAGE_NAME} ${PACKAGE_VERSION}
${RELATIVE_PROJECT_SOURCE_DIR} c453bb28a886e000af2351093ca0a883906955e5
SHA1_FILES ${SHA1_FILES}
SHA1_VALUES eca444670fe39117f19027fda3608475a1ec1c91
d4ef983ceb32fcde51dffeb118f686394ccbf32f)
endif()
elseif(APPLE)
retrieve_package_file(${PACKAGE_NAME} ${PACKAGE_VERSION}
${RELATIVE_PROJECT_SOURCE_DIR} e98147832b1933945e5a29c194fd570669e49f0f
SHA1_FILES ${SHA1_FILES}
SHA1_VALUES 9c23f1d64dfa64a120e77521c896ac8e645156b1)
else()
retrieve_package_file(${PACKAGE_NAME} ${PACKAGE_VERSION}
${RELATIVE_PROJECT_SOURCE_DIR} 31a17a86ec78a19bae8df80a1a1a69dae990a710
SHA1_FILES ${SHA1_FILES}
SHA1_VALUES 112f25f4f4b2a9c4e223970851e3392182d06ef8)
endif()
else()
# Ignore some warnings
if(WIN32)
set(PACKAGE_C_FLAGS "${CMAKE_C_FLAGS} /wd4267")
endif()
# Build zlib 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/zlib
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>
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 library 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}z${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}
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 zlib package
set(ZLIB_ROOT_DIR ${FULL_LOCAL_EXTERNAL_PACKAGE_DIR} PARENT_SCOPE)
set(ZLIB_INCLUDE_DIR ${FULL_LOCAL_EXTERNAL_PACKAGE_DIR}/include PARENT_SCOPE)
set(ZLIB_LIBRARY ${EXTERNAL_BINARIES_DIR}/${IMPORT_LIBRARY} PARENT_SCOPE)
# Add the plugin
add_plugin(${PACKAGE_NAME}
SOURCES
../../plugininfo.cpp
src/zlibplugin.cpp
HEADERS_MOC
src/zlibplugin.h
QT_MODULES
Core
EXTERNAL_BINARIES_DIR
${EXTERNAL_BINARIES_DIR}
EXTERNAL_BINARIES
${EXTERNAL_BINARIES}
DEPENDS_ON
${DEPENDS_ON}
)