2017-05-25 14:33:16 +08:00
## # vcpkg_configure_cmake
##
## Configure CMake for Debug and Release builds of a project.
##
## ## Usage
## ```cmake
## vcpkg_configure_cmake(
## SOURCE_PATH <${SOURCE_PATH}>
## [PREFER_NINJA]
## [GENERATOR <"NMake Makefiles">]
## [OPTIONS <-DUSE_THIS_IN_ALL_BUILDS=1>...]
## [OPTIONS_RELEASE <-DOPTIMIZE=1>...]
## [OPTIONS_DEBUG <-DDEBUGGABLE=1>...]
## )
## ```
##
## ## Parameters
## ### SOURCE_PATH
## Specifies the directory containing the `CMakeLists.txt`. By convention, this is usually set in the portfile as the variable `SOURCE_PATH`.
##
## ### PREFER_NINJA
## Indicates that, when available, Vcpkg should use Ninja to perform the build. This should be specified unless the port is known to not work under Ninja.
##
## ### GENERATOR
## Specifies the precise generator to use.
##
## This is useful if some project-specific buildsystem has been wrapped in a cmake script that won't perform an actual build. If used for this purpose, it should be set to "NMake Makefiles".
##
## ### OPTIONS
## Additional options passed to CMake during the configuration.
##
## ### OPTIONS_RELEASE
## Additional options passed to CMake during the Release configuration. These are in addition to `OPTIONS`.
##
## ### OPTIONS_DEBUG
## Additional options passed to CMake during the Debug configuration. These are in addition to `OPTIONS`.
##
## ## Notes
## This command supplies many common arguments to CMake. To see the full list, examine the source.
##
## ## Examples
##
## * [zlib](https://github.com/Microsoft/vcpkg/blob/master/ports/zlib/portfile.cmake)
## * [cpprestsdk](https://github.com/Microsoft/vcpkg/blob/master/ports/cpprestsdk/portfile.cmake)
## * [poco](https://github.com/Microsoft/vcpkg/blob/master/ports/poco/portfile.cmake)
## * [opencv](https://github.com/Microsoft/vcpkg/blob/master/ports/opencv/portfile.cmake)
2016-09-19 11:50:08 +08:00
function ( vcpkg_configure_cmake )
2017-02-04 00:16:13 +08:00
cmake_parse_arguments ( _csc "PREFER_NINJA" "SOURCE_PATH;GENERATOR" "OPTIONS;OPTIONS_DEBUG;OPTIONS_RELEASE" ${ ARGN } )
2016-09-19 11:50:08 +08:00
2017-01-25 10:55:41 +08:00
if ( NOT VCPKG_PLATFORM_TOOLSET )
2017-04-01 18:58:45 +08:00
message ( FATAL_ERROR "Vcpkg has been updated with VS2017 support, however you need to rebuild vcpkg.exe by re-running bootstrap-vcpkg.bat\n" )
2017-01-25 10:55:41 +08:00
endif ( )
2017-05-04 01:11:29 +08:00
if ( DEFINED ENV{PROCESSOR_ARCHITEW6432} )
2017-04-23 15:11:42 +08:00
set ( _csc_HOST_ARCHITECTURE $ENV{ PROCESSOR_ARCHITEW6432 } )
else ( )
set ( _csc_HOST_ARCHITECTURE $ENV{ PROCESSOR_ARCHITECTURE } )
endif ( )
2016-09-19 11:50:08 +08:00
if ( _csc_GENERATOR )
set ( GENERATOR ${ _csc_GENERATOR } )
2017-04-23 15:11:42 +08:00
elseif ( _csc_PREFER_NINJA AND NOT VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND NOT _csc_HOST_ARCHITECTURE STREQUAL "x86" )
2017-02-04 00:16:13 +08:00
set ( GENERATOR "Ninja" )
2017-11-06 02:13:16 +08:00
elseif ( VCPKG_TARGET_ARCHITECTURE MATCHES "x86" AND VCPKG_PLATFORM_TOOLSET MATCHES "v120" )
2017-09-02 22:48:29 +08:00
set ( GENERATOR "Visual Studio 12 2013" )
2017-11-06 02:13:16 +08:00
elseif ( VCPKG_TARGET_ARCHITECTURE MATCHES "x64" AND VCPKG_PLATFORM_TOOLSET MATCHES "v120" )
2017-09-02 22:48:29 +08:00
set ( GENERATOR "Visual Studio 12 2013 Win64" )
2017-11-06 02:13:16 +08:00
elseif ( VCPKG_TARGET_ARCHITECTURE MATCHES "arm" AND VCPKG_PLATFORM_TOOLSET MATCHES "v120" )
2017-09-02 22:48:29 +08:00
set ( GENERATOR "Visual Studio 12 2013 ARM" )
2017-11-26 03:49:15 +08:00
elseif ( VCPKG_CHAINLOAD_TOOLCHAIN_FILE )
set ( GENERATOR "Ninja" )
2017-10-17 02:22:21 +08:00
elseif ( VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND VCPKG_TARGET_ARCHITECTURE MATCHES "x86" AND VCPKG_PLATFORM_TOOLSET MATCHES "v140" )
2016-09-19 11:50:08 +08:00
set ( GENERATOR "Visual Studio 14 2015" )
2017-10-17 02:22:21 +08:00
elseif ( VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND VCPKG_TARGET_ARCHITECTURE MATCHES "x64" AND VCPKG_PLATFORM_TOOLSET MATCHES "v140" )
2016-09-19 11:50:08 +08:00
set ( GENERATOR "Visual Studio 14 2015 Win64" )
2017-10-17 02:22:21 +08:00
elseif ( VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND VCPKG_TARGET_ARCHITECTURE MATCHES "arm" AND VCPKG_PLATFORM_TOOLSET MATCHES "v140" )
2016-09-19 11:50:08 +08:00
set ( GENERATOR "Visual Studio 14 2015 ARM" )
2017-10-17 02:22:21 +08:00
elseif ( VCPKG_TARGET_ARCHITECTURE MATCHES "x86" AND VCPKG_PLATFORM_TOOLSET MATCHES "v140" )
2016-09-19 11:50:08 +08:00
set ( GENERATOR "Visual Studio 14 2015" )
2017-10-17 02:22:21 +08:00
elseif ( VCPKG_TARGET_ARCHITECTURE MATCHES "x64" AND VCPKG_PLATFORM_TOOLSET MATCHES "v140" )
2016-09-19 11:50:08 +08:00
set ( GENERATOR "Visual Studio 14 2015 Win64" )
2017-10-17 02:22:21 +08:00
elseif ( VCPKG_TARGET_ARCHITECTURE MATCHES "arm" AND VCPKG_PLATFORM_TOOLSET MATCHES "v140" )
2017-03-14 08:59:41 +08:00
set ( GENERATOR "Visual Studio 14 2015 ARM" )
2017-01-24 11:25:47 +08:00
2017-10-17 02:22:21 +08:00
elseif ( VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND VCPKG_TARGET_ARCHITECTURE MATCHES "x86" AND VCPKG_PLATFORM_TOOLSET MATCHES "v141" )
2017-01-24 11:25:47 +08:00
set ( GENERATOR "Visual Studio 15 2017" )
2017-10-17 02:22:21 +08:00
elseif ( VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND VCPKG_TARGET_ARCHITECTURE MATCHES "x64" AND VCPKG_PLATFORM_TOOLSET MATCHES "v141" )
2017-01-24 11:25:47 +08:00
set ( GENERATOR "Visual Studio 15 2017 Win64" )
2017-10-17 02:22:21 +08:00
elseif ( VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND VCPKG_TARGET_ARCHITECTURE STREQUAL "arm" AND VCPKG_PLATFORM_TOOLSET MATCHES "v141" )
2017-01-24 11:25:47 +08:00
set ( GENERATOR "Visual Studio 15 2017 ARM" )
2017-10-17 02:22:21 +08:00
elseif ( VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64" AND VCPKG_PLATFORM_TOOLSET MATCHES "v141" )
2017-09-24 21:01:37 +08:00
set ( GENERATOR "Visual Studio 15 2017" )
set ( ARCH "ARM64" )
2017-10-17 02:22:21 +08:00
elseif ( VCPKG_TARGET_ARCHITECTURE MATCHES "x86" AND VCPKG_PLATFORM_TOOLSET MATCHES "v141" )
2017-01-24 11:25:47 +08:00
set ( GENERATOR "Visual Studio 15 2017" )
2017-10-17 02:22:21 +08:00
elseif ( VCPKG_TARGET_ARCHITECTURE MATCHES "x64" AND VCPKG_PLATFORM_TOOLSET MATCHES "v141" )
2017-01-24 11:25:47 +08:00
set ( GENERATOR "Visual Studio 15 2017 Win64" )
2017-10-17 02:22:21 +08:00
elseif ( VCPKG_TARGET_ARCHITECTURE STREQUAL "arm" AND VCPKG_PLATFORM_TOOLSET MATCHES "v141" )
2017-03-14 08:59:41 +08:00
set ( GENERATOR "Visual Studio 15 2017 ARM" )
2017-10-17 02:22:21 +08:00
elseif ( VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64" AND VCPKG_PLATFORM_TOOLSET MATCHES "v141" )
2017-09-24 21:01:37 +08:00
set ( GENERATOR "Visual Studio 15 2017" )
set ( ARCH "ARM64" )
2017-10-17 02:22:21 +08:00
else ( )
message ( FATAL_ERROR "Unable to determine appropriate generator for: ${VCPKG_CMAKE_SYSTEM_NAME}-${VCPKG_TARGET_ARCHITECTURE}-${VCPKG_PLATFORM_TOOLSET}" )
2016-09-19 11:50:08 +08:00
endif ( )
2017-02-04 00:16:13 +08:00
# If we use Ninja, make sure it's on PATH
if ( GENERATOR STREQUAL "Ninja" )
vcpkg_find_acquire_program ( NINJA )
get_filename_component ( NINJA_PATH ${ NINJA } DIRECTORY )
2017-02-09 09:39:31 +08:00
set ( ENV{PATH} "$ENV{PATH};${NINJA_PATH}" )
2017-02-04 00:16:13 +08:00
endif ( )
2016-09-19 11:50:08 +08:00
file ( REMOVE_RECURSE ${ CURRENT_BUILDTREES_DIR } / ${ TARGET_TRIPLET } -rel ${ CURRENT_BUILDTREES_DIR } / ${ TARGET_TRIPLET } -dbg )
2016-10-07 04:46:41 +08:00
if ( DEFINED VCPKG_CMAKE_SYSTEM_NAME )
2017-10-17 02:22:21 +08:00
list ( APPEND _csc_OPTIONS "-DCMAKE_SYSTEM_NAME=${VCPKG_CMAKE_SYSTEM_NAME}" )
2016-10-07 04:46:41 +08:00
endif ( )
if ( DEFINED VCPKG_CMAKE_SYSTEM_VERSION )
2017-10-17 02:22:21 +08:00
list ( APPEND _csc_OPTIONS "-DCMAKE_SYSTEM_VERSION=${VCPKG_CMAKE_SYSTEM_VERSION}" )
2016-10-07 04:46:41 +08:00
endif ( )
2017-10-17 02:22:21 +08:00
if ( VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic" )
2016-10-08 07:34:31 +08:00
list ( APPEND _csc_OPTIONS -DBUILD_SHARED_LIBS=ON )
2017-10-17 02:22:21 +08:00
elseif ( VCPKG_LIBRARY_LINKAGE STREQUAL "static" )
2016-10-19 03:55:37 +08:00
list ( APPEND _csc_OPTIONS -DBUILD_SHARED_LIBS=OFF )
2017-10-17 02:22:21 +08:00
else ( )
message ( FATAL_ERROR "Invalid setting for VCPKG_LIBRARY_LINKAGE: \" ${ VCPKG_LIBRARY_LINKAGE } \". It must be \"static\" or \"dynamic\"")
2016-10-07 04:46:41 +08:00
endif ( )
2017-01-24 11:25:47 +08:00
2017-05-31 03:24:21 +08:00
if ( ( NOT DEFINED VCPKG_CXX_FLAGS_DEBUG AND NOT DEFINED VCPKG_C_FLAGS_DEBUG ) OR
( D E F I N E D V C P K G _ C X X _ F L A G S _ D E B U G A N D D E F I N E D V C P K G _ C _ F L A G S _ D E B U G ) )
else ( )
message ( FATAL_ERROR "You must set both the VCPKG_CXX_FLAGS_DEBUG and VCPKG_C_FLAGS_DEBUG" )
endif ( )
if ( ( NOT DEFINED VCPKG_CXX_FLAGS_RELEASE AND NOT DEFINED VCPKG_C_FLAGS_RELEASE ) OR
( D E F I N E D V C P K G _ C X X _ F L A G S _ R E L E A S E A N D D E F I N E D V C P K G _ C _ F L A G S _ R E L E A S E ) )
else ( )
message ( FATAL_ERROR "You must set both the VCPKG_CXX_FLAGS_RELEASE and VCPKG_C_FLAGS_RELEASE" )
endif ( )
if ( ( NOT DEFINED VCPKG_CXX_FLAGS AND NOT DEFINED VCPKG_C_FLAGS ) OR
( D E F I N E D V C P K G _ C X X _ F L A G S A N D D E F I N E D V C P K G _ C _ F L A G S ) )
else ( )
message ( FATAL_ERROR "You must set both the VCPKG_CXX_FLAGS and VCPKG_C_FLAGS" )
endif ( )
2016-10-07 04:46:41 +08:00
2017-10-17 02:22:21 +08:00
if ( VCPKG_CHAINLOAD_TOOLCHAIN_FILE )
list ( APPEND _csc_OPTIONS "-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}" )
else ( )
set ( VCPKG_CXX_FLAGS " /DWIN32 /D_WINDOWS /W3 /utf-8 /GR /EHsc /MP ${VCPKG_CXX_FLAGS}" )
set ( VCPKG_C_FLAGS " /DWIN32 /D_WINDOWS /W3 /utf-8 /MP ${VCPKG_C_FLAGS}" )
if ( VCPKG_CRT_LINKAGE STREQUAL "dynamic" )
list ( APPEND _csc_OPTIONS_DEBUG
" - D C M A K E _ C X X _ F L A G S _ D E B U G = / D _ D E B U G / M D d / Z 7 / O b 0 / O d / R T C 1 $ { V C P K G _ C X X _ F L A G S _ D E B U G } "
" - D C M A K E _ C _ F L A G S _ D E B U G = / D _ D E B U G / M D d / Z 7 / O b 0 / O d / R T C 1 $ { V C P K G _ C _ F L A G S _ D E B U G } "
)
list ( APPEND _csc_OPTIONS_RELEASE
" - D C M A K E _ C X X _ F L A G S _ R E L E A S E = / M D / O 2 / O i / G y / D N D E B U G / Z 7 $ { V C P K G _ C X X _ F L A G S _ R E L E A S E } "
" - D C M A K E _ C _ F L A G S _ R E L E A S E = / M D / O 2 / O i / G y / D N D E B U G / Z 7 $ { V C P K G _ C _ F L A G S _ R E L E A S E } "
)
elseif ( VCPKG_CRT_LINKAGE STREQUAL "static" )
list ( APPEND _csc_OPTIONS_DEBUG
" - D C M A K E _ C X X _ F L A G S _ D E B U G = / D _ D E B U G / M T d / Z 7 / O b 0 / O d / R T C 1 $ { V C P K G _ C X X _ F L A G S _ D E B U G } "
" - D C M A K E _ C _ F L A G S _ D E B U G = / D _ D E B U G / M T d / Z 7 / O b 0 / O d / R T C 1 $ { V C P K G _ C _ F L A G S _ D E B U G } "
)
list ( APPEND _csc_OPTIONS_RELEASE
" - D C M A K E _ C X X _ F L A G S _ R E L E A S E = / M T / O 2 / O i / G y / D N D E B U G / Z 7 $ { V C P K G _ C X X _ F L A G S _ R E L E A S E } "
" - D C M A K E _ C _ F L A G S _ R E L E A S E = / M T / O 2 / O i / G y / D N D E B U G / Z 7 $ { V C P K G _ C _ F L A G S _ R E L E A S E } "
)
else ( )
message ( FATAL_ERROR "Invalid setting for VCPKG_CRT_LINKAGE: \" ${ VCPKG_CRT_LINKAGE } \". It must be \"static\" or \"dynamic\"")
endif ( )
list ( APPEND _csc_OPTIONS_RELEASE
" - D C M A K E _ S H A R E D _ L I N K E R _ F L A G S _ R E L E A S E = / D E B U G / I N C R E M E N T A L : N O / O P T : R E F / O P T : I C F $ { V C P K G _ L I N K E R _ F L A G S } "
" - D C M A K E _ E X E _ L I N K E R _ F L A G S _ R E L E A S E = / D E B U G / I N C R E M E N T A L : N O / O P T : R E F / O P T : I C F $ { V C P K G _ L I N K E R _ F L A G S } "
)
list ( APPEND _csc_OPTIONS
" - D C M A K E _ C X X _ F L A G S = $ { V C P K G _ C X X _ F L A G S } "
" - D C M A K E _ C _ F L A G S = $ { V C P K G _ C _ F L A G S } "
)
endif ( )
2016-10-12 01:32:40 +08:00
list ( APPEND _csc_OPTIONS
2017-03-31 15:35:40 +08:00
" - D V C P K G _ T A R G E T _ T R I P L E T = $ { T A R G E T _ T R I P L E T } "
2016-12-06 17:26:21 +08:00
" - D C M A K E _ E X P O R T _ N O _ P A C K A G E _ R E G I S T R Y = O N "
" - D C M A K E _ F I N D _ P A C K A G E _ N O _ P A C K A G E _ R E G I S T R Y = O N "
" - D C M A K E _ F I N D _ P A C K A G E _ N O _ S Y S T E M _ P A C K A G E _ R E G I S T R Y = O N "
2017-03-07 02:35:03 +08:00
" - D C M A K E _ I N S T A L L _ S Y S T E M _ R U N T I M E _ L I B S _ S K I P = T R U E "
" - D C M A K E _ V E R B O S E _ M A K E F I L E = O N "
2017-03-21 16:48:40 +08:00
" - D V C P K G _ A P P L O C A L _ D E P S = O F F "
" - D C M A K E _ T O O L C H A I N _ F I L E = $ { V C P K G _ R O O T _ D I R } / s c r i p t s / b u i l d s y s t e m s / v c p k g . c m a k e "
" - D C M A K E _ E R R O R _ O N _ A B S O L U T E _ I N S T A L L _ D E S T I N A T I O N = O N "
2016-10-12 01:32:40 +08:00
)
2017-05-31 03:24:21 +08:00
2017-09-24 21:01:37 +08:00
if ( DEFINED ARCH )
list ( APPEND _csc_OPTIONS
" - A $ { A R C H } "
)
endif ( )
2017-11-26 07:25:18 +08:00
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release" )
message ( STATUS "Configuring ${TARGET_TRIPLET}-rel" )
file ( MAKE_DIRECTORY ${ CURRENT_BUILDTREES_DIR } / ${ TARGET_TRIPLET } -rel )
vcpkg_execute_required_process (
C O M M A N D $ { C M A K E _ C O M M A N D } $ { _ c s c _ S O U R C E _ P A T H } $ { _ c s c _ O P T I O N S } $ { _ c s c _ O P T I O N S _ R E L E A S E }
- G $ { G E N E R A T O R }
- D C M A K E _ B U I L D _ T Y P E = R e l e a s e
- D C M A K E _ I N S T A L L _ P R E F I X = $ { C U R R E N T _ P A C K A G E S _ D I R }
W O R K I N G _ D I R E C T O R Y $ { C U R R E N T _ B U I L D T R E E S _ D I R } / $ { T A R G E T _ T R I P L E T } - r e l
L O G N A M E c o n f i g - $ { T A R G E T _ T R I P L E T } - r e l
)
message ( STATUS "Configuring ${TARGET_TRIPLET}-rel done" )
endif ( )
2016-09-19 11:50:08 +08:00
2017-11-26 07:25:18 +08:00
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug" )
message ( STATUS "Configuring ${TARGET_TRIPLET}-dbg" )
file ( MAKE_DIRECTORY ${ CURRENT_BUILDTREES_DIR } / ${ TARGET_TRIPLET } -dbg )
vcpkg_execute_required_process (
C O M M A N D $ { C M A K E _ C O M M A N D } $ { _ c s c _ S O U R C E _ P A T H } $ { _ c s c _ O P T I O N S } $ { _ c s c _ O P T I O N S _ D E B U G }
- G $ { G E N E R A T O R }
- D C M A K E _ B U I L D _ T Y P E = D e b u g
- D C M A K E _ I N S T A L L _ P R E F I X = $ { C U R R E N T _ P A C K A G E S _ D I R } / d e b u g
W O R K I N G _ D I R E C T O R Y $ { C U R R E N T _ B U I L D T R E E S _ D I R } / $ { T A R G E T _ T R I P L E T } - d b g
L O G N A M E c o n f i g - $ { T A R G E T _ T R I P L E T } - d b g
)
message ( STATUS "Configuring ${TARGET_TRIPLET}-dbg done" )
endif ( )
2017-10-06 08:49:28 +08:00
set ( _VCPKG_CMAKE_GENERATOR "${GENERATOR}" PARENT_SCOPE )
2016-09-19 11:50:08 +08:00
endfunction ( )