Merged PR 2098454: Add cmake option to statically link the runtime library for Windows by passing /MT or /MTd

To enable statically link the runtime library use "makewin <arch> -mt" or pass "-DUSE_STATIC_MSVC=on". Default is off.
Note: This increase the size of the binary considerably.

Related work items: #18288248
This commit is contained in:
Ruben Guerrero Samaniego 2018-07-16 23:19:00 +00:00 коммит произвёл msftrubengu
Родитель b48b443d71
Коммит bd45ddfcba
3 изменённых файлов: 289 добавлений и 289 удалений

Просмотреть файл

@ -2,24 +2,31 @@
# 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)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
MESSAGE (STATUS "--------------------------------")
MESSAGE (STATUS "MSIX Packaging SDK")
MESSAGE (STATUS "--------------------------------")
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(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)
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")
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.
@ -28,61 +35,61 @@ find_package(Git) # QUIET) # if we don't find git or FindGit.cmake is not on the
## 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)
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})
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}'" )
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})
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")
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()
set(VERSION_MAJOR ${CMAKE_MATCH_1})
set(VERSION_MINOR ${CMAKE_MATCH_2})
set(VERSION_PATCH "0")
endif()
IF(NOT ${GIT_REFSPEC})
if(NOT ${GIT_REFSPEC})
string(REGEX MATCH "refs/heads/([a-zA-Z0-9_/]+)" _dummy3 ${GIT_REFSPEC})
SET(GIT_BRANCH_NAME ${CMAKE_MATCH_1})
ELSE()
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()
set(GIT_BRANCH_NAME "master")
endif()
MESSAGE(STATUS "GIT branch name '${GIT_BRANCH_NAME}'" )
ELSE()
MESSAGE("git not found.")
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}")
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}")
# 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 "--------------------------------")
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 "--------------------------------")
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
list(APPEND CERTS_TO_PUBLISH
base64_MSFT_RCA_2010.cer
base64_MSFT_RCA_2011.cer
base64_STORE_PCA_2011.cer
@ -90,91 +97,77 @@ LIST(APPEND CERTS_TO_PUBLISH
base64_Windows_Production.cer
Microsoft_MarketPlace_PCA_2011.cer
)
FOREACH(CERT_TO_PUBLISH ${CERTS_TO_PUBLISH})
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 "--------------------------------")
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")
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")
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")
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()
endif()
endif()
# Enforce parser PAL
IF(NOT USE_VALIDATION_PARSER)
MESSAGE (STATUS "To choose type of validation, Use the -DUSE_VALIDATION_PARSER=on to enable. Default is 'off'")
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()
IF(NOT XML_PARSER)
MESSAGE (STATUS "Choose the type of parser, options are: [xerces, msxml6]. Use the -DXML_PARSER=[option] to specify.")
INCLUDE(CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX(msxml6.h HAVE_MSXML6)
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
IF (HAVE_MSXML6)
SET(XML_PARSER msxml6 CACHE STRING "Using msxml6." FORCE)
ELSE()
SET(XML_PARSER xerces CACHE STRING "Using xerces" FORCE)
ENDIF()
ENDIF()
# Enforce build type
IF(NOT CMAKE_BUILD_TYPE)
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."
FORCE)
ENDIF()
# Enforce build libraries
IF(NOT USE_SHARED_ZLIB)
MESSAGE (STATUS "Choose the type of dependency for zlib, Use the -DUSE_SHARED_ZLIB=on to have a shared dependency. Default is 'off' (static)")
ENDIF()
IF((NOT USE_SHARED_OPENSSL) AND (NOT WIN32))
MESSAGE (STATUS "Choose the type of dependency for openssl, Use the -DUSE_SHARED_OPENSSL=on to have a shared dependency. Default is 'off' (static)")
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))
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()
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((MACOS) OR (IOS))
if ((CMAKE_BUILD_TYPE MATCHES Release) OR (CMAKE_BUILD_TYPE MATCHES MinSizeRel))
MESSAGE (STATUS "optimized build, symbol generation turned-OFF" )
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" )
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
@ -199,36 +192,36 @@ IF((MACOS) OR (IOS))
"${DSYMUTIL_PROGRAM} <TARGET>")
endif ()
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")
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)
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")
message(STATUS " ")
message(STATUS "--------------------------------")
message(STATUS "MSIX Packaging SDK")
message(STATUS "--------------------------------")
message(STATUS "libs processed")
add_subdirectory(src)
MESSAGE (STATUS "src processed")
message(STATUS "src processed")
ADD_DEPENDENCIES(SRC LIBS)
MESSAGE (STATUS "dependencies added")
message(STATUS "dependencies added")
add_subdirectory(sample)
MESSAGE (STATUS "sample processed")
message(STATUS "sample processed")
add_subdirectory(test)
MESSAGE (STATUS "tests processed")
MESSAGE (STATUS "DONE!")
message(STATUS "tests processed")
message(STATUS "DONE!")

Просмотреть файл

@ -28,6 +28,7 @@ set build="MinSizeRel"
set validationParser="-DUSE_VALIDATION_PARSER=off"
set zlib="-DUSE_SHARED_ZLIB=off"
set parser="-DXML_PARSER=msxml6"
set msvc="-DUSE_STATIC_MSVC=off"
:parseArgs
if /I "%~2" == "--debug" (
@ -54,6 +55,9 @@ if /I "%~2" == "--shared-zlib" (
if /I "%~2" == "-sz" (
set zlib="-DUSE_SHARED_ZLIB=on"
)
if /I "%~2" == "-mt" (
set msvc="-DUSE_STATIC_MSVC=on"
)
shift /2
if not "%~2"=="" goto parseArgs
@ -62,8 +66,8 @@ cd .vs
if exist CMakeFiles rd /s /q CMakeFiles
if exist CMakeCache.txt del CMakeCache.txt
echo cmake -DWIN32=on -DCMAKE_BUILD_TYPE=%build% %validationParser% %zlib% %parser% -G"NMake Makefiles" ..
cmake -DWIN32=on -DCMAKE_BUILD_TYPE=%build% %validationParser% %zlib% %parser% -G"NMake Makefiles" ..
echo cmake -DWIN32=on -DCMAKE_BUILD_TYPE=%build% %validationParser% %zlib% %parser% %msvc% -G"NMake Makefiles" ..
cmake -DWIN32=on -DCMAKE_BUILD_TYPE=%build% %validationParser% %zlib% %parser% %msvc% -G"NMake Makefiles" ..
nmake
goto Exit
@ -80,6 +84,7 @@ echo --debug, -d = Build chk binary.
echo --parser-xerces, -px = use Xerces-C parser. Default MSXML6.
echo --validation-parser, -vp = enable XML schema validation.
echo --shared-zlib, -sz = don't statically link zlib.
echo -mt = use compiler flag /MT to use static version of the run-time library.
echo --help, -h, /? = print this usage information and exit.
:Exit
EXIT /B 0

Просмотреть файл

@ -10,27 +10,27 @@ set(LIBRARY_NAME msix)
project(${LIBRARY_NAME})
# Define PALs
IF (XML_PARSER MATCHES xerces)
MESSAGE (STATUS "XML_PARSER defined. Using XERCES-C XML parser." )
SET (XmlParser PAL/XML/xerces-c/XmlObject.cpp)
if(XML_PARSER MATCHES xerces)
message(STATUS "XML_PARSER defined. Using XERCES-C XML parser." )
set(XmlParser PAL/XML/xerces-c/XmlObject.cpp)
add_definitions(-DUSING_XERCES=1)
ENDIF()
endif()
IF (XML_PARSER MATCHES msxml6)
MESSAGE (STATUS "XML_PARSER defined. Using MSXML6 XML parser." )
SET (XmlParser PAL/XML/msxml6/XmlObject.cpp)
if(XML_PARSER MATCHES msxml6)
message(STATUS "XML_PARSER defined. Using MSXML6 XML parser." )
set(XmlParser PAL/XML/msxml6/XmlObject.cpp)
add_definitions(-DUSING_MSXML=1)
ENDIF()
endif()
IF(WIN32)
SET (DirectoryObject PAL/FileSystem/Win32/DirectoryObject.cpp)
SET (SHA256 PAL/SHA256/Win32/SHA256.cpp)
SET (Signature PAL/Signature/Win32/SignatureValidator.cpp)
SET (Applicability PAL/Applicability/Win32/Applicability.cpp)
ELSE()
if(WIN32)
set(DirectoryObject PAL/FileSystem/Win32/DirectoryObject.cpp)
set(SHA256 PAL/SHA256/Win32/SHA256.cpp)
set(Signature PAL/Signature/Win32/SignatureValidator.cpp)
set(Applicability PAL/Applicability/Win32/Applicability.cpp)
else()
# Visibility variables for non-win32 platforms
SET(MSIX_EXPORTS)
LIST(APPEND MSIX_EXPORTS
set(MSIX_EXPORTS)
list(APPEND MSIX_EXPORTS
"CoCreateAppxFactory"
"CoCreateAppxFactoryWithHeap"
"CreateStreamOnFile"
@ -76,89 +76,88 @@ ELSE()
"IID_IMSIXElement"
"IID_IMSIXElementEnumerator"
)
IF((IOS) OR (MACOS))
if((IOS) OR (MACOS))
# on Apple platforms you can explicitly define which symbols are exported
SET(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
SET(CMAKE_C_VISIBILITY_PRESET hidden)
SET(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
# iOS and Mac exports start with '_' .The first '_' is be in the exports.def.cmakein
STRING(REGEX REPLACE ";" "\n_" MSIX_EXPORTS "${MSIX_EXPORTS}")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/exports.def.cmakein ${CMAKE_CURRENT_BINARY_DIR}/exports.def CRLF)
SET(DEFINE_EXPORTS "-exported_symbols_list ${CMAKE_CURRENT_BINARY_DIR}/exports.def")
string(REGEX REPLACE ";" "\n_" MSIX_EXPORTS "${MSIX_EXPORTS}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/exports.def.cmakein ${CMAKE_CURRENT_BINARY_DIR}/exports.def CRLF)
set(DEFINE_EXPORTS "-exported_symbols_list ${CMAKE_CURRENT_BINARY_DIR}/exports.def")
# used to get the languages of the device
FIND_LIBRARY(COREFOUNDATION_LIBRARY CoreFoundation)
IF(NOT COREFOUNDATION_LIBRARY)
MESSAGE(FATAL_ERROR "CoreFoundation not found")
ENDIF()
SET (Applicability PAL/Applicability/Apple/Applicability.cpp)
find_library(COREFOUNDATION_LIBRARY CoreFoundation)
if(NOT COREFOUNDATION_LIBRARY)
message(FATAL_ERROR "CoreFoundation not found")
endif()
set(Applicability PAL/Applicability/Apple/Applicability.cpp)
if(IOS)
add_definitions(-DIOS)
else()
add_definitions(-DMACOS)
endif()
ELSE()
IF(LINUX)
else()
if(LINUX)
add_definitions(-DLINUX)
FIND_PACKAGE(ICU COMPONENTS uc)
SET (Applicability PAL/Applicability/Linux/Applicability.cpp)
ENDIF()
IF(AOSP)
find_package(ICU COMPONENTS uc)
set(Applicability PAL/Applicability/Linux/Applicability.cpp)
endif()
if(AOSP)
# add here any exports specific for android
add_definitions(-DAOSP)
LIST(APPEND MSIX_EXPORTS
list(APPEND MSIX_EXPORTS
"JNI_OnLoad"
)
SET (Applicability PAL/Applicability/AOSP/Applicability.cpp)
ENDIF()
set(Applicability PAL/Applicability/AOSP/Applicability.cpp)
endif()
# on Linux and linux-derived platforms, you use a version script to achieve similar ends.
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
# Make it look readable. The last ; is in the symbol.map.cmakein file
STRING(REGEX REPLACE ";" ";\n\t" MSIX_EXPORTS "${MSIX_EXPORTS}")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/symbol.map.cmakein ${CMAKE_CURRENT_BINARY_DIR}/symbol.map CRLF)
SET(DEFINE_EXPORTS "-Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/symbol.map")
ENDIF()
MESSAGE(STATUS "Using export flag: ${DEFINE_EXPORTS}")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${DEFINE_EXPORTS}")
string(REGEX REPLACE ";" ";\n\t" MSIX_EXPORTS "${MSIX_EXPORTS}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/symbol.map.cmakein ${CMAKE_CURRENT_BINARY_DIR}/symbol.map CRLF)
set(DEFINE_EXPORTS "-Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/symbol.map")
endif()
message(STATUS "Using export flag: ${DEFINE_EXPORTS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${DEFINE_EXPORTS}")
IF(OpenSSL_FOUND)
MESSAGE (STATUS "Using OpenSSL ${OpenSLL_VERSION}")
INCLUDE_DIRECTORIES(
if(OpenSSL_FOUND)
message(STATUS "Using OpenSSL ${OpenSLL_VERSION}")
include_directories(
${include_directories}
${OpenSLL_INCLUDE_PATH}
)
SET (SHA256 PAL/SHA256/OpenSSL/SHA256.cpp)
SET (Signature PAL/Signature/OpenSSL/SignatureValidator.cpp)
ELSE()
set(SHA256 PAL/SHA256/OpenSSL/SHA256.cpp)
set(Signature PAL/Signature/OpenSSL/SignatureValidator.cpp)
else()
# ... and were done here... :/
MESSAGE (STATUS "OpenSSL NOT FOUND!")
RETURN()
ENDIF()
message(STATUS "OpenSSL NOT FOUND!")
return()
endif()
set(DirectoryObject PAL/FileSystem/POSIX/DirectoryObject.cpp)
endif()
SET (DirectoryObject PAL/FileSystem/POSIX/DirectoryObject.cpp)
ENDIF()
IF(USE_VALIDATION_PARSER)
MESSAGE (STATUS "PAL: VALIDATING parser" )
if(USE_VALIDATION_PARSER)
message(STATUS "PAL: VALIDATING parser" )
add_definitions(-DVALIDATING=1)
ELSE()
MESSAGE (STATUS "PAL: non-validating parser" )
else()
message(STATUS "PAL: non-validating parser" )
add_definitions(-DVALIDATING=0)
ENDIF()
endif()
MESSAGE (STATUS "PAL: XML = ${XmlParser}")
MESSAGE (STATUS "PAL: DirectoryObject = ${DirectoryObject}")
MESSAGE (STATUS "PAL: SHA256 = ${SHA256}")
MESSAGE (STATUS "PAL: Signature = ${Signature}")
MESSAGE (STATUS "PAL: Applicability = ${Applicability}")
message(STATUS "PAL: XML = ${XmlParser}")
message(STATUS "PAL: DirectoryObject = ${DirectoryObject}")
message(STATUS "PAL: SHA256 = ${SHA256}")
message(STATUS "PAL: Signature = ${Signature}")
message(STATUS "PAL: Applicability = ${Applicability}")
include(msix_resources)
SET(LIB_PUBLIC_HEADERS
set(LIB_PUBLIC_HEADERS
../inc/AppxPackaging.hpp
../inc/MSIXWindows.hpp
)
SET(LIB_PRIVATE_HEADERS
set(LIB_PRIVATE_HEADERS
../inc/Applicability.hpp
../inc/AppxBlockMapObject.hpp
../inc/AppxFactory.hpp
@ -189,7 +188,7 @@ SET(LIB_PRIVATE_HEADERS
../inc/ZipObject.hpp
)
SET(LIB_SOURCES
set(LIB_SOURCES
AppxBlockMapObject.cpp
AppxFactory.cpp
AppxManifestObject.cpp
@ -211,88 +210,14 @@ SET(LIB_SOURCES
)
# Copy out public headers
CONFIGURE_FILE(../inc/MSIXWindows.hpp ${CMAKE_CURRENT_BINARY_DIR}/MSIXWindows.hpp )
CONFIGURE_FILE(../inc/AppxPackaging.hpp ${CMAKE_CURRENT_BINARY_DIR}/AppxPackaging.hpp)
configure_file(../inc/MSIXWindows.hpp ${CMAKE_CURRENT_BINARY_DIR}/MSIXWindows.hpp )
configure_file(../inc/AppxPackaging.hpp ${CMAKE_CURRENT_BINARY_DIR}/AppxPackaging.hpp)
# Define the library
ADD_LIBRARY(${LIBRARY_NAME} SHARED ${LIB_SOURCES} ${LIB_PUBLIC_HEADERS} ${LIB_PRIVATE_HEADERS})
# specify that this library is to be built with C++14
SET_PROPERTY(TARGET ${LIBRARY_NAME} PROPERTY CXX_STANDARD 14)
# Set the build version. It will be used in the name of the lib, with corresponding
# symlinks created. SOVERSION could also be specified for api version.
SET_TARGET_PROPERTIES(${LIBRARY_NAME} PROPERTIES
VERSION ${VERSION} # ${VERSION} was defined in the main CMakeLists.
FRAMEWORK FALSE
PUBLIC_HEADER "${LIB_HEADERS}" # specify the public headers
)
INCLUDE_DIRECTORIES(
${include_directories}
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/zlib
${CMAKE_PROJECT_ROOT}/lib/zlib
)
IF(USE_SHARED_ZLIB)
MESSAGE(STATUS "MSIX takes a dynamic dependency on zlib")
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE zlib)
else()
MESSAGE(STATUS "MSIX takes a static dependency on zlib")
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE zlibstatic)
endif()
IF (XML_PARSER MATCHES xerces)
MESSAGE(STATUS "MSIX takes a static dependency on xerces")
INCLUDE_DIRECTORIES(
${include_directories}
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/xerces/src
${CMAKE_PROJECT_ROOT}/lib/xerces/src
)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE xerces-c)
ENDIF()
IF(AOSP)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE -latomic)
FIND_PACKAGE(Java REQUIRED)
IF(NOT ANDROID_SDK)
IF(NOT DEFINED ENV{ANDROID_HOME})
MESSAGE(FATAL_ERROR "ANDROID_HOME enviroment variable not found.")
ENDIF()
SET(ANDROID_SDK $ENV{ANDROID_HOME})
ENDIF()
IF(NOT ANDROID_SDK_VERSION)
SET(ANDROID_SDK_VERSION 24)
ENDIF()
IF(ANDROID_SDK_VERSION LESS 24)
MESSAGE(FATAL_ERROR "MSIX minimum Android SDK is 24")
ENDIF()
INCLUDE(UseJava)
MESSAGE(STATUS "Android SDK = ${ANDROID_SDK}")
ADD_JAR(${PROJECT_NAME}-jni
SOURCES
PAL/java/com/microsoft/msix/JniHelper.java
INCLUDE_JARS
${ANDROID_SDK}/platforms/android-${ANDROID_SDK_VERSION}/android.jar
OUTPUT_DIR
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
)
ENDIF()
IF((IOS) OR (MACOS))
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE ${COREFOUNDATION_LIBRARY})
ENDIF()
IF(LINUX)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE ${ICU_LIBRARIES})
ENDIF()
IF(OpenSSL_FOUND)
# include the libraries needed to use OpenSSL
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE crypto)
ENDIF()
add_library(${LIBRARY_NAME} SHARED ${LIB_SOURCES} ${LIB_PUBLIC_HEADERS} ${LIB_PRIVATE_HEADERS})
if(WIN32)
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES
set_target_properties(${PROJECT_NAME} PROPERTIES
COMPILE_FLAGS "/source-charset:utf-8"
VS_WINRT_COMPONENT TRUE)
# Using /DELAYLOAD as linker option will use a helper funtion provided by
@ -300,11 +225,88 @@ if(WIN32)
# This dlls are NOT supposed to be loaded ever on Win7. See Exceptions.cpp
# on how we handle failure of delayloading these.
# https://docs.microsoft.com/en-us/cpp/build/reference/error-handling-and-notification
SET(DELAYFLAGS)
LIST(APPEND DELAYFLAGS
set(DELAYFLAGS)
list(APPEND DELAYFLAGS
"/DELAYLOAD:api-ms-win-core-winrt-string-l1-1-0.dll"
"/DELAYLOAD:api-ms-win-core-winrt-l1-1-0.dll")
STRING(REPLACE ";" " " DELAYFLAGS "${DELAYFLAGS}")
SET_PROPERTY(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS "${DELAYFLAGS}")
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PRIVATE bcrypt crypt32 wintrust runtimeobject.lib delayimp.lib)
string(REPLACE ";" " " DELAYFLAGS "${DELAYFLAGS}")
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS "${DELAYFLAGS}")
if(USE_STATIC_MSVC)
set_property(TARGET ${PROJECT_NAME} APPEND_STRING PROPERTY LINK_FLAGS " /NODEFAULTLIB:MSVCRT")
endif()
target_link_libraries(${PROJECT_NAME} PRIVATE bcrypt crypt32 wintrust runtimeobject.lib delayimp.lib)
endif()
# specify that this library is to be built with C++14
set_property(TARGET ${LIBRARY_NAME} PROPERTY CXX_STANDARD 14)
# Set the build version. It will be used in the name of the lib, with corresponding
# symlinks created. SOVERSION could also be specified for api version.
set_target_properties(${LIBRARY_NAME} PROPERTIES
VERSION ${VERSION} # ${VERSION} was defined in the main CMakeLists.
FRAMEWORK FALSE
PUBLIC_HEADER "${LIB_HEADERS}" # specify the public headers
)
include_directories(
${include_directories}
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/zlib
${CMAKE_PROJECT_ROOT}/lib/zlib
)
if(USE_SHARED_ZLIB)
message(STATUS "MSIX takes a dynamic dependency on zlib")
target_link_libraries(${PROJECT_NAME} PRIVATE zlib)
else()
message(STATUS "MSIX takes a static dependency on zlib")
target_link_libraries(${PROJECT_NAME} PRIVATE zlibstatic)
endif()
if(XML_PARSER MATCHES xerces)
message(STATUS "MSIX takes a static dependency on xerces")
include_directories(
${include_directories}
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/xerces/src
${CMAKE_PROJECT_ROOT}/lib/xerces/src
)
target_link_libraries(${PROJECT_NAME} PRIVATE xerces-c)
endif()
if(AOSP)
target_link_libraries(${PROJECT_NAME} PRIVATE -latomic)
find_package(Java REQUIRED)
if(NOT ANDROID_SDK)
if(NOT DEFINED ENV{ANDROID_HOME})
message(FATAL_ERROR "ANDROID_HOME enviroment variable not found.")
endif()
set(ANDROID_SDK $ENV{ANDROID_HOME})
endif()
if(NOT ANDROID_SDK_VERSION)
SET(ANDROID_SDK_VERSION 24)
endif()
if(ANDROID_SDK_VERSION LESS 24)
message(FATAL_ERROR "MSIX minimum Android SDK is 24")
endif()
include(UseJava)
message(STATUS "Android SDK = ${ANDROID_SDK}")
add_jar(${PROJECT_NAME}-jni
SOURCES
PAL/java/com/microsoft/msix/JniHelper.java
INCLUDE_JARS
${ANDROID_SDK}/platforms/android-${ANDROID_SDK_VERSION}/android.jar
OUTPUT_DIR
${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
)
endif()
if((IOS) OR (MACOS))
target_link_libraries(${PROJECT_NAME} PRIVATE ${COREFOUNDATION_LIBRARY})
endif()
if(LINUX)
target_link_libraries(${PROJECT_NAME} PRIVATE ${ICU_LIBRARIES})
endif()
if(OpenSSL_FOUND)
# include the libraries needed to use OpenSSL
target_link_libraries(${PROJECT_NAME} PRIVATE crypto)
endif()