2019-07-03 23:28:48 +00:00
if ( VCPKG_TARGET_TRIPLET )
if ( NOT DEFINED ENV{VCPKG_ROOT} )
get_filename_component ( VCPKG_ROOT ${ CMAKE_SOURCE_DIR } /../vcpkg ABSOLUTE )
set ( ENV{VCPKG_ROOT} ${ VCPKG_ROOT } )
else ( )
set ( VCPKG_ROOT $ENV{ VCPKG_ROOT } )
endif ( )
if ( NOT EXISTS ${ VCPKG_ROOT } )
get_filename_component ( vcpkg_root_parent ${ VCPKG_ROOT } /.. ABSOLUTE )
execute_process (
C O M M A N D g i t c l o n e 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 . g i t
R E S U L T _ V A R I A B L E g i t _ s t a t u s
W O R K I N G _ D I R E C T O R Y $ { v c p k g _ r o o t _ p a r e n t }
)
if ( NOT git_status EQUAL 0 )
2019-10-21 13:58:55 +00:00
message ( FATAL_ERROR "Error cloning vcpkg from git, please make sure git for windows is installed correctly, it can be installed from Visual Studio components" )
2019-07-03 23:28:48 +00:00
endif ( )
2019-10-21 13:58:55 +00:00
else ( )
# this is the case when we cache vcpkg/installed with the appveyor build cache
if ( NOT EXISTS ${ VCPKG_ROOT } /.git )
set ( git_commands
" g i t i n i t "
" g i t r e m o t e a d d o r i g i n 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 . g i t "
" g i t f e t c h - - a l l - - p r u n e "
" g i t r e s e t - - h a r d o r i g i n / m a s t e r "
" g i t b r a n c h - - s e t - u p s t r e a m - t o = o r i g i n / m a s t e r m a s t e r "
)
foreach ( git_command ${ git_commands } )
separate_arguments ( git_command )
2019-07-03 23:28:48 +00:00
2019-10-21 13:58:55 +00:00
execute_process (
C O M M A N D $ { g i t _ c o m m a n d }
R E S U L T _ V A R I A B L E g i t _ s t a t u s
W O R K I N G _ D I R E C T O R Y $ { V C P K G _ R O O T }
)
if ( NOT git_status EQUAL 0 )
break ( )
endif ( )
endforeach ( )
else ( )
2019-07-03 23:28:48 +00:00
execute_process (
2019-10-21 13:58:55 +00:00
C O M M A N D g i t p u l l - - r e b a s e
R E S U L T _ V A R I A B L E g i t _ s t a t u s
2019-07-03 23:28:48 +00:00
W O R K I N G _ D I R E C T O R Y $ { V C P K G _ R O O T }
)
endif ( )
2019-10-21 13:58:55 +00:00
if ( NOT git_status EQUAL 0 )
message ( FATAL_ERROR "Error updating vcpkg from git, please make sure git for windows is installed correctly, it can be installed from Visual Studio components" )
2019-07-03 23:28:48 +00:00
endif ( )
endif ( )
2019-10-21 13:58:55 +00:00
# build latest vcpkg
if ( WIN32 )
execute_process (
C O M M A N D b o o t s t r a p - v c p k g . b a t
W O R K I N G _ D I R E C T O R Y $ { V C P K G _ R O O T }
)
else ( )
execute_process (
C O M M A N D . / b o o t s t r a p - v c p k g . s h
W O R K I N G _ D I R E C T O R Y $ { V C P K G _ R O O T }
)
endif ( )
2019-07-03 23:28:48 +00:00
foreach ( pkg ${ VCPKG_DEPS } )
list ( APPEND VCPKG_DEPS_QUALIFIED ${ pkg } : ${ VCPKG_TARGET_TRIPLET } )
endforeach ( )
if ( WIN32 )
2019-12-03 18:59:42 +00:00
set ( vcpkg_exe vcpkg )
2019-07-03 23:28:48 +00:00
else ( )
2019-12-03 18:59:42 +00:00
set ( vcpkg_exe ./vcpkg )
2019-07-03 23:28:48 +00:00
endif ( )
2019-12-03 18:59:42 +00:00
# update portfiles
execute_process (
C O M M A N D $ { v c p k g _ e x e } u p d a t e
W O R K I N G _ D I R E C T O R Y $ { V C P K G _ R O O T }
)
# build our deps
execute_process (
C O M M A N D $ { v c p k g _ e x e } i n s t a l l $ { V C P K G _ D E P S _ Q U A L I F I E D }
W O R K I N G _ D I R E C T O R Y $ { V C P K G _ R O O T }
)
# make sure we have the latest versions
execute_process (
C O M M A N D $ { v c p k g _ e x e } u p g r a d e - - n o - d r y - r u n
W O R K I N G _ D I R E C T O R Y $ { V C P K G _ R O O T }
)
2019-12-07 16:58:12 +00:00
if ( WIN32 AND VCPKG_TARGET_TRIPLET MATCHES x64 AND CMAKE_GENERATOR MATCHES "Visual Studio" )
2019-07-03 23:28:48 +00:00
set ( CMAKE_GENERATOR_PLATFORM x64 CACHE STRING "visual studio build architecture" FORCE )
endif ( )
2019-12-07 16:58:12 +00:00
if ( NOT CMAKE_GENERATOR MATCHES "Visual Studio" )
# set toolchain to VS for e.g. Ninja or jom
set ( CMAKE_C_COMPILER cl CACHE STRING "Microsoft C/C++ Compiler" FORCE )
set ( CMAKE_CXX_COMPILER cl CACHE STRING "Microsoft C/C++ Compiler" FORCE )
endif ( )
2019-07-03 23:28:48 +00:00
set ( CMAKE_TOOLCHAIN_FILE ${ VCPKG_ROOT } /scripts/buildsystems/vcpkg.cmake CACHE FILEPATH "vcpkg toolchain" FORCE )
include ( ${ VCPKG_ROOT } /scripts/buildsystems/vcpkg.cmake )
endif ( )