forked from microsoft/msix-packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
229 lines (203 loc) · 9.56 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
# Copyright (C) 2017 Microsoft. All rights reserved.
# See LICENSE file in the project root for full license information.
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
message(STATUS "--------------------------------")
message(STATUS "MSIX Packaging SDK")
message(STATUS "--------------------------------")
# Set build options
option(WIN32 "Build for Win32" OFF)
option(MACOS "Build for MacOS" OFF)
option(IOS "Build for iOS" OFF)
option(AOSP "Build for Android" OFF)
option(LINUX "Build for Linux" OFF)
option(USE_VALIDATION_PARSER "Turn on to validates using the resouce schemas. Default (OFF) validates XML files are just valid XML" OFF)
option(USE_SHARED_ZLIB "Choose the type of dependency for zlib, Use the -DUSE_SHARED_ZLIB=on to have a shared dependency. Default is 'off' (static)" OFF)
option(USE_STATIC_MSVC "Windows only. Pass /MT as a compiler flag to use the staic version of the run-time library. Default is 'off' (dynamic)" OFF)
option(SKIP_BUNDLES "Removes bundle functionality from the MSIX SDK. Default is 'off'" OFF)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel. Use the -DCMAKE_BUILD_TYPE=[option] to specify.")
set(XML_PARSER "" CACHE STRING "Choose the type of parser, options are: [xerces, msxml6]. Use the -DXML_PARSER=[option] to specify.")
# Default version is 0.0.0
set(VERSION_MAJOR "0")
set(VERSION_MINOR "0")
set(VERSION_PATCH "0")
set(GIT_BRANCH_NAME "master")
## Git (and its revision)
find_package(Git) # QUIET) # if we don't find git or FindGit.cmake is not on the system we ignore it.
## GetGitRevisionDescription module to retreive branch and revision information from Git
## Starting with Git 1.9 the module will be part of official cMake distribution, until then it has to be
## part of the application
## The Git module will trigger a reconfiguration for each pull that will bring a new revision on the local repository
set(VCS_REVISION "-1")
if(GIT_FOUND)
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
message(STATUS "GIT refspec ${GIT_REFSPEC}")
message(STATUS "GIT revision ${GIT_SHA1}")
set(VCS_REVISION ${GIT_SHA1})
git_describe(GIT_DESCRIPTION)
message(STATUS "GIT Description '${GIT_DESCRIPTION}'" )
string(REGEX MATCH "v([0-9]+)\\.([0-9]+)\\-([0-9]+)" _dummy1 "${GIT_DESCRIPTION}")
set(VERSION_MAJOR ${CMAKE_MATCH_1})
set(VERSION_MINOR ${CMAKE_MATCH_2})
set(VERSION_PATCH ${CMAKE_MATCH_3})
if(NOT VERSION_PATCH)
message(STATUS "GIT Description is from NEW tag")
string(REGEX MATCH "v([0-9]+)\\.([0-9]+)" _dummy2 "${GIT_DESCRIPTION}")
set(VERSION_MAJOR ${CMAKE_MATCH_1})
set(VERSION_MINOR ${CMAKE_MATCH_2})
set(VERSION_PATCH "0")
endif()
if(NOT ${GIT_REFSPEC})
string(REGEX MATCH "refs/heads/([a-zA-Z0-9_/]+)" _dummy3 ${GIT_REFSPEC})
set(GIT_BRANCH_NAME ${CMAKE_MATCH_1})
else()
# VSO doesn't checkout a branch do a pull, it checks out a hash and does a pull
set(GIT_BRANCH_NAME "master")
endif()
message(STATUS "GIT branch name '${GIT_BRANCH_NAME}'" )
else()
message("git not found.")
endif()
# Set the version number of your project here (format is MAJOR.MINOR.PATCHLEVEL - e.g. 1.0.0)
set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
message(STATUS "MSIX Packaging SDK version ${VERSION}")
message(STATUS "MSIX Packaging SDK branch name ${GIT_BRANCH_NAME}")
add_definitions(-DSDK_VERSION="${VERSION}")
# Configure Package.nuspec
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Package.nuspec.cmakein ${CMAKE_CURRENT_BINARY_DIR}/Package.nuspec CRLF)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Microsoft.MSIX.Packaging.targets ${CMAKE_BINARY_DIR}/build/native/Microsoft.MSIX.Packaging.targets)
message(STATUS "Package.Nuspec created")
message(STATUS "--------------------------------")
# Configure license txt
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/LICENSE ${CMAKE_BINARY_DIR}/build/LICENSE)
message(STATUS "LICENSE created")
message(STATUS "--------------------------------")
# Configure certificates
# list each certificate by name that is to be published in the nuget package
list(APPEND CERTS_TO_PUBLISH
base64_MSFT_RCA_2010.cer
base64_MSFT_RCA_2011.cer
base64_STORE_PCA_2011.cer
base64_Windows_Production_PCA_2011.cer
base64_Windows_Production.cer
Microsoft_MarketPlace_PCA_2011.cer
)
foreach(CERT_TO_PUBLISH ${CERTS_TO_PUBLISH})
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/resources/certs/${CERT_TO_PUBLISH} ${CMAKE_BINARY_DIR}/build/certs/${CERT_TO_PUBLISH})
endforeach()
message(STATUS "Certificates published")
message(STATUS "--------------------------------")
# Enforce that target platform is specified.
if((NOT WIN32) AND (NOT MACOS) AND (NOT IOS) AND (NOT AOSP) AND (NOT LINUX))
message(STATUS "You must specify one of: [WIN32|MACOS|IOS|AOSP|LINUX]" )
message(STATUS "For example, use cmake -DWIN32=on .." )
return()
else()
if(WIN32)
message(STATUS "Building for WIN32")
if(USE_STATIC_MSVC)
# By default these flags have /MD set. Modified it to use /MT instead.
foreach(buildType RELEASE MINSIZEREL RELWITHDEBINFO)
set(cxxFlag "CMAKE_CXX_FLAGS_${buildType}")
string(REPLACE "/MD" "/MT" ${cxxFlag} "${${cxxFlag}}")
endforeach()
set(cxxFlagDebug "CMAKE_CXX_FLAGS_DEBUG")
string(REPLACE "/MDd" "/MTd" ${cxxFlagDebug} "${${cxxFlagDebug}}")
endif()
endif()
if(MACOS)
message(STATUS "Building for MacOS")
endif()
if(IOS)
message(STATUS "Building for iOS")
if(IOS_DEPLOYMENT_TARGET VERSION_LESS 10.0)
message(FATAL_ERROR "Unsupported iOS version: ${IOS_DEPLOYMENT_TARGET}, this project requires at least iOS version 10.0")
endif()
set(PLATFORM_APPLE 1)
endif()
if(AOSP)
message(STATUS "Building for Android")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
if(LINUX)
message(STATUS "Building for Linux")
# Static libraries must be position independent to be linked with a shared object.
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()
endif()
if(NOT XML_PARSER)
include(CheckIncludeFileCXX)
check_include_file_cxx(msxml6.h HAVE_MSXML6)
if(HAVE_MSXML6)
set(XML_PARSER msxml6 CACHE STRING "Using msxml6." FORCE)
else()
set(XML_PARSER xerces CACHE STRING "Using xerces" FORCE)
endif()
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
if((CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) OR (CMAKE_BUILD_TYPE MATCHES Release) OR (CMAKE_BUILD_TYPE MATCHES MinSizeRel))
ADD_DEFINITIONS(-DNDEBUG)
message(STATUS "NDEBUG defined, assert should be turned-off" )
else()
message(STATUS "NDEBUG NOT defined, assert should be turned-on" )
endif()
if((MACOS) OR (IOS))
if ((CMAKE_BUILD_TYPE MATCHES Release) OR (CMAKE_BUILD_TYPE MATCHES MinSizeRel))
message(STATUS "optimized build, symbol generation turned-OFF" )
# on optimized builds, do NOT turn-on symbol generation.
else()
message(STATUS "non-optimized build, symbol generation turned-ON" )
# Incredibly, for both clang and g++, while a single compile-and-link
# invocation will create an executable.dSYM/ dir with debug info,
# with separate compilation the final link does NOT create the
# dSYM dir.
# The "dsymutil" program will create the dSYM dir for us.
# Strangely it takes in the executable and not the object
# files even though it's the latter that contain the debug info.
# Thus it will only work if the object files are still sitting around.
find_program(DSYMUTIL_PROGRAM dsymutil)
if (DSYMUTIL_PROGRAM)
set(CMAKE_C_LINK_EXECUTABLE
"${CMAKE_C_LINK_EXECUTABLE}"
"${DSYMUTIL_PROGRAM} <TARGET>")
set(CMAKE_C_CREATE_SHARED_LIBRARY
"${CMAKE_C_CREATE_SHARED_LIBRARY}"
"${DSYMUTIL_PROGRAM} <TARGET>")
set(CMAKE_CXX_LINK_EXECUTABLE
"${CMAKE_CXX_LINK_EXECUTABLE}"
"${DSYMUTIL_PROGRAM} <TARGET>")
set(CMAKE_CXX_CREATE_SHARED_LIBRARY
"${CMAKE_CXX_CREATE_SHARED_LIBRARY}"
"${DSYMUTIL_PROGRAM} <TARGET>")
endif ()
endif()
endif()
enable_testing() # needed on top-level CMakeLists.txt
# CMake useful variables
set(CMAKE_PROJECT_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
# Mac needed variables
# [TODO: adapt as needed]
set(CMAKE_MACOSX_RPATH ON)
#set(CMAKE_SKIP_BUILD_RPATH FALSE)
#set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
#set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
#set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
add_subdirectory(lib)
message(STATUS " ")
message(STATUS "--------------------------------")
message(STATUS "MSIX Packaging SDK")
message(STATUS "--------------------------------")
message(STATUS "libs processed")
add_subdirectory(src)
message(STATUS "src processed")
ADD_DEPENDENCIES(SRC LIBS)
message(STATUS "dependencies added")
add_subdirectory(sample)
message(STATUS "sample processed")
add_subdirectory(test)
message(STATUS "tests processed")
message(STATUS "DONE!")