2020-12-01 13:37:26 -08:00
#[===[.md:
# vcpkg_install_msbuild
B u i l d a n d i n s t a l l a m s b u i l d - b a s e d p r o j e c t . T h i s r e p l a c e s ` vcpkg_build_msbuild ( ) ` .
## Usage
` ` ` c m a k e
vcpkg_install_msbuild (
S O U R C E _ P A T H < $ { S O U R C E _ P A T H } >
P R O J E C T _ S U B P A T H < p o r t . s l n >
[ I N C L U D E S _ S U B P A T H < i n c l u d e > ]
[ L I C E N S E _ S U B P A T H < L I C E N S E > ]
[ R E L E A S E _ C O N F I G U R A T I O N < R e l e a s e > ]
[ D E B U G _ C O N F I G U R A T I O N < D e b u g > ]
[ T A R G E T < B u i l d > ]
[ T A R G E T _ P L A T F O R M _ V E R S I O N < 1 0 . 0 . 1 5 0 6 3 . 0 > ]
[ P L A T F O R M < $ { T R I P L E T _ S Y S T E M _ A R C H } > ]
[ P L A T F O R M _ T O O L S E T < $ { V C P K G _ P L A T F O R M _ T O O L S E T } > ]
[ O P T I O N S < / p : Z L I B _ I N C L U D E _ P A T H = X > . . . ]
[ O P T I O N S _ R E L E A S E < / p : Z L I B _ L I B = X > . . . ]
[ O P T I O N S _ D E B U G < / p : Z L I B _ L I B = X > . . . ]
[ U S E _ V C P K G _ I N T E G R A T I O N ]
[ A L L O W _ R O O T _ I N C L U D E S | R E M O V E _ R O O T _ I N C L U D E S ]
)
` ` `
## Parameters
### SOURCE_PATH
T h e p a t h t o t h e r o o t o f t h e s o u r c e t r e e .
B e c a u s e M S B u i l d u s e s i n - s o u r c e b u i l d s , t h e s o u r c e t r e e w i l l b e c o p i e d i n t o a t e m p o r a r y l o c a t i o n f o r t h e b u i l d . T h i s
p a r a m e t e r i s t h e b a s e f o r t h a t c o p y a n d f o r m s t h e b a s e f o r a l l X Y Z _ S U B P A T H o p t i o n s .
### USE_VCPKG_INTEGRATION
A p p l y t h e n o r m a l ` i n t e g r a t e i n s t a l l ` i n t e g r a t i o n f o r b u i l d i n g t h e p r o j e c t .
B y d e f a u l t , p r o j e c t s b u i l t w i t h t h i s c o m m a n d w i l l n o t a u t o m a t i c a l l y l i n k l i b r a r i e s o r h a v e h e a d e r p a t h s s e t .
### PROJECT_SUBPATH
T h e s u b p a t h t o t h e solution ( `.sln` ) o r project ( `.vcxproj` ) f i l e r e l a t i v e t o ` S O U R C E _ P A T H ` .
### LICENSE_SUBPATH
T h e s u b p a t h t o t h e l i c e n s e f i l e r e l a t i v e t o ` S O U R C E _ P A T H ` .
### INCLUDES_SUBPATH
T h e s u b p a t h t o t h e i n c l u d e s d i r e c t o r y r e l a t i v e t o ` S O U R C E _ P A T H ` .
T h i s p a r a m e t e r s h o u l d b e a d i r e c t o r y a n d s h o u l d n o t e n d i n a t r a i l i n g s l a s h .
### ALLOW_ROOT_INCLUDES
I n d i c a t e s t h a t t o p - l e v e l i n c l u d e files ( e.g. `include/zlib.h` ) s h o u l d b e a l l o w e d .
### REMOVE_ROOT_INCLUDES
I n d i c a t e s t h a t t o p - l e v e l i n c l u d e files ( e.g. `include/Makefile.am` ) s h o u l d b e r e m o v e d .
### SKIP_CLEAN
I n d i c a t e s t h a t t h e i n t e r m e d i a t e f i l e s s h o u l d n o t b e r e m o v e d .
P o r t s u s i n g t h i s o p t i o n s h o u l d l a t e r c a l l [ ` vcpkg_clean_msbuild ( ) ` ] ( v c p k g _ c l e a n _ m s b u i l d . m d ) t o m a n u a l l y c l e a n u p .
### RELEASE_CONFIGURATION
T h e configuration ( ``/p:Configuration`` msbuild parameter ) u s e d f o r R e l e a s e b u i l d s .
### DEBUG_CONFIGURATION
T h e configuration ( ``/p:Configuration`` msbuild parameter ) u s e d f o r D e b u g b u i l d s .
### TARGET_PLATFORM_VERSION
T h e WindowsTargetPlatformVersion ( ``/p:WindowsTargetPlatformVersion`` msbuild parameter )
### TARGET
T h e M S B u i l d t a r g e t t o b u i l d . ( ` ` / t : < T A R G E T > ` ` )
### PLATFORM
T h e platform ( ``/p:Platform`` msbuild parameter ) u s e d f o r t h e b u i l d .
### PLATFORM_TOOLSET
T h e p l a t f o r m toolset ( ``/p:PlatformToolset`` msbuild parameter ) u s e d f o r t h e b u i l d .
### OPTIONS
A d d i t i o n a l o p t i o n s p a s s e d t o m s b u i l d f o r a l l b u i l d s .
### OPTIONS_RELEASE
A d d i t i o n a l o p t i o n s p a s s e d t o m s b u i l d f o r R e l e a s e b u i l d s . T h e s e a r e i n a d d i t i o n t o ` O P T I O N S ` .
### OPTIONS_DEBUG
A d d i t i o n a l o p t i o n s p a s s e d t o m s b u i l d f o r D e b u g b u i l d s . T h e s e a r e i n a d d i t i o n t o ` O P T I O N S ` .
## Examples
2021-07-14 14:45:18 -05:00
* [ l i b i r e c o v e r y ] ( h t t p s : / / g i t h u b . c o m / M i c r o s o f t / v c p k g / b l o b / m a s t e r / p o r t s / l i b i r e c o v e r y / p o r t f i l e . c m a k e )
* [ l i b f a b r i c ] ( h t t p s : / / g i t h u b . c o m / M i c r o s o f t / v c p k g / b l o b / m a s t e r / p o r t s / l i b f a b r i c / p o r t f i l e . c m a k e )
2020-12-01 13:37:26 -08:00
#]===]
2018-08-08 13:15:13 +02:00
function ( vcpkg_install_msbuild )
cmake_parse_arguments (
2020-10-27 03:30:27 +01:00
P A R S E _ A R G V 0
2021-05-17 11:08:42 -07:00
" a r g "
2018-10-25 20:34:45 +01:00
" U S E _ V C P K G _ I N T E G R A T I O N ; A L L O W _ R O O T _ I N C L U D E S ; R E M O V E _ R O O T _ I N C L U D E S ; S K I P _ C L E A N "
2018-08-08 13:15:13 +02:00
" S O U R C E _ P A T H ; P R O J E C T _ S U B P A T H ; I N C L U D E S _ S U B P A T H ; L I C E N S E _ S U B P A T H ; R E L E A S E _ C O N F I G U R A T I O N ; D E B U G _ C O N F I G U R A T I O N ; P L A T F O R M ; P L A T F O R M _ T O O L S E T ; T A R G E T _ P L A T F O R M _ V E R S I O N ; T A R G E T "
" O P T I O N S ; O P T I O N S _ R E L E A S E ; O P T I O N S _ D E B U G "
)
2021-05-17 11:08:42 -07:00
if ( DEFINED arg_UNPARSED_ARGUMENTS )
message ( WARNING "vcpkg_install_msbuild was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}" )
endif ( )
if ( NOT DEFINED arg_RELEASE_CONFIGURATION )
set ( arg_RELEASE_CONFIGURATION Release )
2018-08-08 13:15:13 +02:00
endif ( )
2021-05-17 11:08:42 -07:00
if ( NOT DEFINED arg_DEBUG_CONFIGURATION )
set ( arg_DEBUG_CONFIGURATION Debug )
2018-08-08 13:15:13 +02:00
endif ( )
2021-05-17 11:08:42 -07:00
if ( NOT DEFINED arg_PLATFORM )
if ( VCPKG_TARGET_ARCHITECTURE STREQUAL "x64" )
set ( arg_PLATFORM x64 )
elseif ( VCPKG_TARGET_ARCHITECTURE STREQUAL "x86" )
set ( arg_PLATFORM Win32 )
elseif ( VCPKG_TARGET_ARCHITECTURE STREQUAL "arm" )
set ( arg_PLATFORM ARM )
elseif ( VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64" )
set ( arg_PLATFORM arm64 )
2018-08-08 13:15:13 +02:00
else ( )
message ( FATAL_ERROR "Unsupported target architecture" )
endif ( )
endif ( )
2021-05-17 11:08:42 -07:00
if ( NOT DEFINED arg_PLATFORM_TOOLSET )
set ( arg_PLATFORM_TOOLSET "${VCPKG_PLATFORM_TOOLSET}" )
2018-08-08 13:15:13 +02:00
endif ( )
2021-05-17 11:08:42 -07:00
if ( NOT DEFINED arg_TARGET_PLATFORM_VERSION )
vcpkg_get_windows_sdk ( arg_TARGET_PLATFORM_VERSION )
2018-08-08 13:15:13 +02:00
endif ( )
2021-05-17 11:08:42 -07:00
if ( NOT DEFINED arg_TARGET )
set ( arg_TARGET Rebuild )
2018-08-08 13:15:13 +02:00
endif ( )
2021-05-17 11:08:42 -07:00
list ( APPEND arg_OPTIONS
" / t : $ { a r g _ T A R G E T } "
" / p : P l a t f o r m = $ { a r g _ P L A T F O R M } "
" / p : P l a t f o r m T o o l s e t = $ { a r g _ P L A T F O R M _ T O O L S E T } "
" / p : V C P k g L o c a l A p p D a t a D i s a b l e d = t r u e "
" / p : U s e I n t e l M K L = N o "
" / p : W i n d o w s T a r g e t P l a t f o r m V e r s i o n = $ { a r g _ T A R G E T _ P L A T F O R M _ V E R S I O N } "
" / p : V c p k g T r i p l e t = $ { T A R G E T _ T R I P L E T } "
2021-02-12 23:42:22 -08:00
" / p : V c p k g I n s t a l l e d D i r = $ { _ V C P K G _ I N S T A L L E D _ D I R } "
2021-05-17 11:08:42 -07:00
" / p : V c p k g M a n i f e s t I n s t a l l = f a l s e "
" / m "
2018-08-08 13:15:13 +02:00
)
if ( VCPKG_LIBRARY_LINKAGE STREQUAL "static" )
# Disable LTCG for static libraries because this setting introduces ABI incompatibility between minor compiler versions
# TODO: Add a way for the user to override this if they want to opt-in to incompatibility
2021-05-17 11:08:42 -07:00
list ( APPEND arg_OPTIONS "/p:WholeProgramOptimization=false" )
2018-08-08 13:15:13 +02:00
endif ( )
2021-05-17 11:08:42 -07:00
if ( arg_USE_VCPKG_INTEGRATION )
list ( APPEND arg_OPTIONS
" / p : F o r c e I m p o r t B e f o r e C p p T a r g e t s = $ { S C R I P T S } / b u i l d s y s t e m s / m s b u i l d / v c p k g . t a r g e t s "
" / p : V c p k g A p p l o c a l D e p s = f a l s e "
)
2018-08-08 13:15:13 +02:00
endif ( )
2021-05-17 11:08:42 -07:00
get_filename_component ( source_path_suffix "${arg_SOURCE_PATH}" NAME )
2018-08-08 13:15:13 +02:00
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release" )
2021-05-17 11:08:42 -07:00
message ( STATUS "Building ${arg_PROJECT_SUBPATH} for Release" )
file ( REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel" )
file ( MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel" )
file ( COPY "${arg_SOURCE_PATH}" DESTINATION "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel" )
set ( source_copy_path "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/${source_path_suffix}" )
2018-08-08 13:15:13 +02:00
vcpkg_execute_required_process (
2021-05-17 11:08:42 -07:00
C O M M A N D m s b u i l d " $ { s o u r c e _ c o p y _ p a t h } / $ { a r g _ P R O J E C T _ S U B P A T H } "
" / p : C o n f i g u r a t i o n = $ { a r g _ R E L E A S E _ C O N F I G U R A T I O N } "
$ { a r g _ O P T I O N S }
$ { a r g _ O P T I O N S _ R E L E A S E }
W O R K I N G _ D I R E C T O R Y " $ { s o u r c e _ c o p y _ p a t h } "
L O G N A M E " b u i l d - $ { T A R G E T _ T R I P L E T } - r e l "
2018-08-08 13:15:13 +02:00
)
2021-05-17 11:08:42 -07:00
file ( GLOB_RECURSE libs "${source_copy_path}/*.lib" )
file ( GLOB_RECURSE dlls "${source_copy_path}/*.dll" )
file ( GLOB_RECURSE exes "${source_copy_path}/*.exe" )
if ( NOT libs STREQUAL "" )
file ( COPY ${ libs } DESTINATION "${CURRENT_PACKAGES_DIR}/lib" )
2018-08-08 13:15:13 +02:00
endif ( )
2021-05-17 11:08:42 -07:00
if ( NOT dlls STREQUAL "" )
file ( COPY ${ dlls } DESTINATION "${CURRENT_PACKAGES_DIR}/bin" )
2018-08-08 13:15:13 +02:00
endif ( )
2021-05-17 11:08:42 -07:00
if ( NOT exes STREQUAL "" )
file ( COPY ${ exes } DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}" )
vcpkg_copy_tool_dependencies ( "${CURRENT_PACKAGES_DIR}/tools/${PORT}" )
2018-08-08 13:15:13 +02:00
endif ( )
endif ( )
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug" )
2021-05-17 11:08:42 -07:00
message ( STATUS "Building ${arg_PROJECT_SUBPATH} for Debug" )
file ( REMOVE_RECURSE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg" )
file ( MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg" )
file ( COPY "${arg_SOURCE_PATH}" DESTINATION "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg" )
set ( source_copy_path "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/${source_path_suffix}" )
2018-08-08 13:15:13 +02:00
vcpkg_execute_required_process (
2021-05-17 11:08:42 -07:00
C O M M A N D m s b u i l d " $ { s o u r c e _ c o p y _ p a t h } / $ { a r g _ P R O J E C T _ S U B P A T H } "
" / p : C o n f i g u r a t i o n = $ { a r g _ D E B U G _ C O N F I G U R A T I O N } "
$ { a r g _ O P T I O N S }
$ { a r g _ O P T I O N S _ D E B U G }
W O R K I N G _ D I R E C T O R Y " $ { s o u r c e _ c o p y _ p a t h } "
L O G N A M E " b u i l d - $ { T A R G E T _ T R I P L E T } - d b g "
2018-08-08 13:15:13 +02:00
)
2021-05-17 11:08:42 -07:00
file ( GLOB_RECURSE libs "${source_copy_path}/*.lib" )
file ( GLOB_RECURSE dlls "${source_copy_path}/*.dll" )
if ( NOT libs STREQUAL "" )
file ( COPY ${ libs } DESTINATION "${CURRENT_PACKAGES_DIR}/debug/lib" )
2018-08-08 13:15:13 +02:00
endif ( )
2021-05-17 11:08:42 -07:00
if ( NOT dlls STREQUAL "" )
file ( COPY ${ dlls } DESTINATION "${CURRENT_PACKAGES_DIR}/debug/bin" )
2018-08-08 13:15:13 +02:00
endif ( )
endif ( )
vcpkg_copy_pdbs ( )
2021-05-17 11:08:42 -07:00
if ( NOT arg_SKIP_CLEAN )
2018-10-25 20:34:45 +01:00
vcpkg_clean_msbuild ( )
endif ( )
2018-08-08 13:15:13 +02:00
2021-05-17 11:08:42 -07:00
if ( DEFINED arg_INCLUDES_SUBPATH )
file ( COPY "${arg_SOURCE_PATH}/${arg_INCLUDES_SUBPATH}/"
D E S T I N A T I O N " $ { C U R R E N T _ P A C K A G E S _ D I R } / i n c l u d e / "
)
file ( GLOB root_includes
L I S T _ D I R E C T O R I E S f a l s e
" $ { C U R R E N T _ P A C K A G E S _ D I R } / i n c l u d e / * " )
if ( NOT root_includes STREQUAL "" )
if ( arg_REMOVE_ROOT_INCLUDES )
file ( REMOVE ${ root_includes } )
elseif ( arg_ALLOW_ROOT_INCLUDES )
2018-08-08 13:15:13 +02:00
else ( )
message ( FATAL_ERROR "Top-level files were found in ${CURRENT_PACKAGES_DIR}/include; this may indicate a problem with the call to `vcpkg_install_msbuild()`.\nTo avoid conflicts with other libraries, it is recommended to not put includes into the root `include/` directory.\nPass either ALLOW_ROOT_INCLUDES or REMOVE_ROOT_INCLUDES to handle these files.\n" )
endif ( )
endif ( )
endif ( )
2021-05-17 11:08:42 -07:00
if ( DEFINED arg_LICENSE_SUBPATH )
file ( INSTALL "${arg_SOURCE_PATH}/${arg_LICENSE_SUBPATH}"
D E S T I N A T I O N " $ { C U R R E N T _ P A C K A G E S _ D I R } / s h a r e / $ { P O R T } "
R E N A M E c o p y r i g h t
)
2018-08-08 13:15:13 +02:00
endif ( )
endfunction ( )