2018-03-01 00:41:55 +03:00
# Copyright (C) 2017 Microsoft. All rights reserved.
# See LICENSE file in the project root for full license information.
2017-10-20 04:17:46 +03:00
2018-10-04 21:27:58 +03:00
cmake_minimum_required ( VERSION 3.8.0 FATAL_ERROR )
2018-07-17 02:19:00 +03:00
set ( CMAKE_MODULE_PATH ${ CMAKE_MODULE_PATH } ${ CMAKE_CURRENT_SOURCE_DIR } /cmake )
2017-10-21 02:18:01 +03:00
2018-07-17 02:19:00 +03:00
message ( STATUS "--------------------------------" )
message ( STATUS "MSIX Packaging SDK" )
message ( STATUS "--------------------------------" )
2017-10-30 23:04:28 +03:00
2019-03-28 03:55:05 +03:00
message ( STATUS "CMake version: ${CMAKE_VERSION}" )
2018-10-04 21:27:58 +03:00
# specify that this binary is to be built with C++14
set ( CMAKE_CXX_STANDARD 14 )
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
set ( CMAKE_CXX_EXTENSIONS OFF )
2019-03-06 01:14:11 +03:00
# Support CMake 3.12. See https://cmake.org/cmake/help/latest/policy/CMP0077.html
if ( POLICY CMP0077 )
cmake_policy ( SET CMP0077 NEW )
endif ( )
2017-10-21 02:18:01 +03:00
# Set build options
2018-07-17 02:19:00 +03:00
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 )
Merged PR 2308191: [MSIX SDK] add a c-make switch to exclude bundles from unpack
Enable the user to disable bundle support for the SDK by specifying -DSKIP_BUNDLES=on on CMake. If the user tries to unpack a bundle or create a bundle factory they will get 0x80070032 (E_NOTSUPPORTED). The binary size decreases ~60k.
Win x64
- bundle: 464 k
- no bundle: 413 k
Win x86
- bundle: 330 k
- no bundle: 293 k
Linux
- bundle: 5,424 k
- no bundle: 5,330 k
AOSP arm
- bundle: 4,381 k
- no bundle: 4,313 k
AOSP arm v7a
- bundle: 4,288 k
- no bundle: 4,220 k
MacOS
- bundle: 4,487 k
- no bundle: 4,413 k
iOS arm64
- bundle: 4,516 k
- no bundle: 4,458 k
Related work items: #18753331
2018-09-06 21:45:34 +03:00
option ( SKIP_BUNDLES "Removes bundle functionality from the MSIX SDK. Default is 'off'" OFF )
2019-07-16 03:13:34 +03:00
option ( MSIX_PACK "Include packaging features for the MSIX SDK. Not supported for mobile. Default is 'off'" OFF )
2018-07-17 02:19:00 +03:00
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." )
2018-09-15 03:58:26 +03:00
set ( XML_PARSER "" CACHE STRING "Choose the type of parser, options are: [xerces, msxml6, javaxml]. Use the -DXML_PARSER=[option] to specify." )
2019-04-09 01:38:31 +03:00
set ( CRYPTO_LIB "" CACHE STRING "Choose the cryptography library to use, options are: [openssl, crypt32]. Use the -DCRYPTO_LIB=[option] to specify." )
2017-10-21 02:18:01 +03:00
2017-11-17 04:15:02 +03:00
# Default version is 0.0.0
2018-07-17 02:19:00 +03:00
set ( VERSION_MAJOR "0" )
set ( VERSION_MINOR "0" )
set ( VERSION_PATCH "0" )
set ( GIT_BRANCH_NAME "master" )
2017-11-17 04:15:02 +03:00
## 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
2018-07-17 02:19:00 +03:00
set ( VCS_REVISION "-1" )
if ( GIT_FOUND )
2017-11-17 04:15:02 +03:00
include ( GetGitRevisionDescription )
get_git_head_revision ( GIT_REFSPEC GIT_SHA1 )
2018-07-17 02:19:00 +03:00
message ( STATUS "GIT refspec ${GIT_REFSPEC}" )
message ( STATUS "GIT revision ${GIT_SHA1}" )
set ( VCS_REVISION ${ GIT_SHA1 } )
2017-11-17 04:15:02 +03:00
git_describe ( GIT_DESCRIPTION )
2018-07-17 02:19:00 +03:00
message ( STATUS "GIT Description '${GIT_DESCRIPTION}'" )
2017-11-17 04:15:02 +03:00
string ( REGEX MATCH "v([0-9]+)\\.([0-9]+)\\-([0-9]+)" _dummy1 "${GIT_DESCRIPTION}" )
2018-07-17 02:19:00 +03:00
set ( VERSION_MAJOR ${ CMAKE_MATCH_1 } )
set ( VERSION_MINOR ${ CMAKE_MATCH_2 } )
set ( VERSION_PATCH ${ CMAKE_MATCH_3 } )
2017-11-17 04:15:02 +03:00
2018-07-17 02:19:00 +03:00
if ( NOT VERSION_PATCH )
message ( STATUS "GIT Description is from NEW tag" )
2017-11-17 04:15:02 +03:00
string ( REGEX MATCH "v([0-9]+)\\.([0-9]+)" _dummy2 "${GIT_DESCRIPTION}" )
2018-07-17 02:19:00 +03:00
set ( VERSION_MAJOR ${ CMAKE_MATCH_1 } )
set ( VERSION_MINOR ${ CMAKE_MATCH_2 } )
set ( VERSION_PATCH "0" )
endif ( )
2017-11-17 04:15:02 +03:00
2018-07-17 02:19:00 +03:00
if ( NOT ${ GIT_REFSPEC } )
2017-11-17 04:15:02 +03:00
string ( REGEX MATCH "refs/heads/([a-zA-Z0-9_/]+)" _dummy3 ${ GIT_REFSPEC } )
2018-07-17 02:19:00 +03:00
set ( GIT_BRANCH_NAME ${ CMAKE_MATCH_1 } )
else ( )
2017-11-17 04:15:02 +03:00
# VSO doesn't checkout a branch do a pull, it checks out a hash and does a pull
2018-07-17 02:19:00 +03:00
set ( GIT_BRANCH_NAME "master" )
endif ( )
2017-11-17 04:15:02 +03:00
2018-07-17 02:19:00 +03:00
message ( STATUS "GIT branch name '${GIT_BRANCH_NAME}'" )
else ( )
message ( "git not found." )
endif ( )
2017-11-17 04:15:02 +03:00
# Set the version number of your project here (format is MAJOR.MINOR.PATCHLEVEL - e.g. 1.0.0)
2018-10-04 21:27:58 +03:00
set ( MSIX_VERSION ${ VERSION_MAJOR } . ${ VERSION_MINOR } . ${ VERSION_PATCH } )
message ( STATUS "MSIX Packaging SDK version ${MSIX_VERSION}" )
2018-07-17 02:19:00 +03:00
message ( STATUS "MSIX Packaging SDK branch name ${GIT_BRANCH_NAME}" )
2018-10-04 21:27:58 +03:00
add_definitions ( -DSDK_VERSION= "${MSIX_VERSION}" )
2017-11-17 04:15:02 +03:00
# Configure Package.nuspec
2019-02-05 21:53:44 +03:00
if ( WIN32 )
set ( MSIX_NUGET_NAME "Microsoft.MSIX.Packaging.Windows" )
elseif ( MACOS )
set ( MSIX_NUGET_NAME "Microsoft.MSIX.Packaging.MacOS" )
elseif ( IOS )
set ( MSIX_NUGET_NAME "Microsoft.MSIX.Packaging.iOS" )
elseif ( AOSP )
set ( MSIX_NUGET_NAME "Microsoft.MSIX.Packaging.AOSP" )
elseif ( LINUX )
set ( MSIX_NUGET_NAME "Microsoft.MSIX.Packaging.Linux" )
else ( )
set ( MSIX_NUGET_NAME "Microsoft.MSIX.Packaging" ) # cmake ..
endif ( )
2017-11-17 04:15:02 +03:00
configure_file ( ${ CMAKE_CURRENT_SOURCE_DIR } /Package.nuspec.cmakein ${ CMAKE_CURRENT_BINARY_DIR } /Package.nuspec CRLF )
2019-02-05 21:53:44 +03:00
configure_file ( ${ CMAKE_CURRENT_SOURCE_DIR } /Microsoft.MSIX.Packaging.targets ${ CMAKE_BINARY_DIR } /build/native/ ${ MSIX_NUGET_NAME } .targets )
2018-07-17 02:19:00 +03:00
message ( STATUS "Package.Nuspec created" )
message ( STATUS "--------------------------------" )
2017-11-17 04:15:02 +03:00
2018-01-18 00:59:19 +03:00
# Configure license txt
configure_file ( ${ CMAKE_CURRENT_SOURCE_DIR } /LICENSE ${ CMAKE_BINARY_DIR } /build/LICENSE )
2019-02-05 21:53:44 +03:00
configure_file ( ${ CMAKE_CURRENT_SOURCE_DIR } /THIRD\ PARTY\ CODE\ NOTICE ${ CMAKE_BINARY_DIR } /build/THIRD\ PARTY\ CODE\ NOTICE )
2018-07-17 02:19:00 +03:00
message ( STATUS "LICENSE created" )
message ( STATUS "--------------------------------" )
2018-01-18 00:59:19 +03:00
# Configure certificates
# list each certificate by name that is to be published in the nuget package
2018-07-17 02:19:00 +03:00
list ( APPEND CERTS_TO_PUBLISH
2018-01-18 00:59:19 +03:00
b a s e 6 4 _ M S F T _ R C A _ 2 0 1 0 . c e r
b a s e 6 4 _ M S F T _ R C A _ 2 0 1 1 . c e r
b a s e 6 4 _ S T O R E _ P C A _ 2 0 1 1 . c e r
b a s e 6 4 _ W i n d o w s _ P r o d u c t i o n _ P C A _ 2 0 1 1 . c e r
b a s e 6 4 _ W i n d o w s _ P r o d u c t i o n . c e r
M i c r o s o f t _ M a r k e t P l a c e _ P C A _ 2 0 1 1 . c e r
)
2018-07-17 02:19:00 +03:00
foreach ( CERT_TO_PUBLISH ${ CERTS_TO_PUBLISH } )
2018-03-07 03:45:39 +03:00
configure_file ( ${ CMAKE_CURRENT_SOURCE_DIR } /resources/certs/ ${ CERT_TO_PUBLISH } ${ CMAKE_BINARY_DIR } /build/certs/ ${ CERT_TO_PUBLISH } )
2018-07-17 02:19:00 +03:00
endforeach ( )
message ( STATUS "Certificates published" )
message ( STATUS "--------------------------------" )
2018-01-18 00:59:19 +03:00
2017-10-21 02:18:01 +03:00
# Enforce that target platform is specified.
2018-07-17 02:19:00 +03:00
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" )
2017-12-12 23:50:36 +03:00
set ( CMAKE_POSITION_INDEPENDENT_CODE ON )
2018-07-17 02:19:00 +03:00
endif ( )
if ( LINUX )
message ( STATUS "Building for Linux" )
2017-11-14 04:44:06 +03:00
# Static libraries must be position independent to be linked with a shared object.
set ( CMAKE_POSITION_INDEPENDENT_CODE ON )
2018-07-17 02:19:00 +03:00
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 ) )
2017-12-01 03:59:55 +03:00
ADD_DEFINITIONS ( -DNDEBUG )
2018-07-17 02:19:00 +03:00
message ( STATUS "NDEBUG defined, assert should be turned-off" )
else ( )
message ( STATUS "NDEBUG NOT defined, assert should be turned-on" )
endif ( )
2017-12-01 03:59:55 +03:00
2018-07-17 02:19:00 +03:00
if ( ( MACOS ) OR ( IOS ) )
2018-04-18 19:35:41 +03:00
if ( ( CMAKE_BUILD_TYPE MATCHES Release ) OR ( CMAKE_BUILD_TYPE MATCHES MinSizeRel ) )
2018-07-17 02:19:00 +03:00
message ( STATUS "optimized build, symbol generation turned-OFF" )
2018-04-18 19:35:41 +03:00
# on optimized builds, do NOT turn-on symbol generation.
else ( )
2018-07-17 02:19:00 +03:00
message ( STATUS "non-optimized build, symbol generation turned-ON" )
2018-04-18 19:35:41 +03:00
# 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
" $ { C M A K E _ C _ L I N K _ E X E C U T A B L E } "
" $ { D S Y M U T I L _ P R O G R A M } < T A R G E T > " )
set ( CMAKE_C_CREATE_SHARED_LIBRARY
" $ { C M A K E _ C _ C R E A T E _ S H A R E D _ L I B R A R Y } "
" $ { D S Y M U T I L _ P R O G R A M } < T A R G E T > " )
set ( CMAKE_CXX_LINK_EXECUTABLE
" $ { C M A K E _ C X X _ L I N K _ E X E C U T A B L E } "
" $ { D S Y M U T I L _ P R O G R A M } < T A R G E T > " )
set ( CMAKE_CXX_CREATE_SHARED_LIBRARY
" $ { C M A K E _ C X X _ C R E A T E _ S H A R E D _ L I B R A R Y } "
" $ { D S Y M U T I L _ P R O G R A M } < T A R G E T > " )
endif ( )
endif ( )
2018-07-17 02:19:00 +03:00
endif ( )
2017-10-20 04:17:46 +03:00
2019-05-13 08:12:51 +03:00
# Packing is not enabled for mobile devices
if ( MSIX_PACK AND ( AOSP OR IOS ) )
set ( MSIX_PACK OFF )
message ( STATUS "Packaging is not supported for mobile devices." )
endif ( )
2019-05-02 21:29:11 +03:00
# If not defined as a cmake argument do a best effort
if ( NOT XML_PARSER )
include ( CheckIncludeFileCXX )
check_include_file_cxx ( msxml6.h HAVE_MSXML6 )
if ( HAVE_MSXML6 )
set ( XML_PARSER msxml6 CACHE STRING "XML Parser not defined. Using msxml6" FORCE )
elseif ( AOSP )
set ( XML_PARSER javaxml CACHE STRING "XML Parser not defined. Using javaxml" FORCE )
elseif ( MAC OR IOS )
set ( XML_PARSER applexml CACHE STRING "XML Parser not defined. Using applexml" FORCE )
else ( )
set ( XML_PARSER xerces CACHE STRING "XML Parser not defined. Using xerces" FORCE )
endif ( )
endif ( )
if ( NOT CRYPTO_LIB )
include ( CheckIncludeFileCXX )
check_include_file_cxx ( wincrypt.h HAVE_CRYPT32 )
if ( HAVE_CRYPT32 )
set ( CRYPTO_LIB crypt32 CACHE STRING "Crypto Lib not defined. Using crypt32" FORCE )
else ( )
set ( CRYPTO_LIB openssl CACHE STRING "Crypto Lib not defined. Using openssl" FORCE )
endif ( )
endif ( )
2017-10-20 04:17:46 +03:00
# CMake useful variables
2018-07-17 02:19:00 +03:00
set ( CMAKE_PROJECT_ROOT ${ CMAKE_CURRENT_SOURCE_DIR } )
2019-02-26 21:54:01 +03:00
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin" )
set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib" )
set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib" )
2017-10-20 04:17:46 +03:00
2019-05-30 21:58:06 +03:00
# Create a bin directory for samples and msixtest to be self contained
set ( MSIX_SAMPLE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/samples" )
set ( MSIX_TEST_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/msixtest" )
2017-11-17 04:15:02 +03:00
# Mac needed variables
2017-10-20 04:17:46 +03:00
# [TODO: adapt as needed]
2018-07-17 02:19:00 +03:00
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)
2017-10-20 04:17:46 +03:00
add_subdirectory ( lib )
2018-07-17 02:19:00 +03:00
message ( STATUS " " )
message ( STATUS "--------------------------------" )
message ( STATUS "MSIX Packaging SDK" )
message ( STATUS "--------------------------------" )
message ( STATUS "libs processed" )
2017-10-20 04:17:46 +03:00
add_subdirectory ( src )
2018-07-17 02:19:00 +03:00
message ( STATUS "src processed" )
2017-10-21 03:35:25 +03:00
ADD_DEPENDENCIES ( SRC LIBS )
2018-07-17 02:19:00 +03:00
message ( STATUS "dependencies added" )
2017-11-03 10:20:08 +03:00
add_subdirectory ( sample )
2018-07-17 02:19:00 +03:00
message ( STATUS "sample processed" )
message ( STATUS "DONE!" )