2017-05-20 16:58:30 +08:00
if ( VCPKG_LIBRARY_LINKAGE STREQUAL dynamic AND VCPKG_CRT_LINKAGE STREQUAL static )
message ( STATUS "Warning: Dynamic library with static CRT is not supported. Building static library." )
set ( VCPKG_LIBRARY_LINKAGE static )
endif ( )
2023-12-12 17:51:55 +08:00
if ( NOT VCPKG_HOST_IS_WINDOWS )
message ( WARNING " ${ PORT } currently requires the following programs from the system package manager:
a u t o c o n f a u t o m a k e a u t o c o n f - a r c h i v e
O n D e b i a n a n d U b u n t u d e r i v a t i v e s :
s u d o a p t - g e t i n s t a l l a u t o c o n f a u t o m a k e a u t o c o n f - a r c h i v e
O n r e c e n t R e d H a t a n d F e d o r a d e r i v a t i v e s :
s u d o d n f i n s t a l l a u t o c o n f a u t o m a k e a u t o c o n f - a r c h i v e
O n A r c h L i n u x a n d d e r i v a t i v e s :
s u d o p a c m a n - S a u t o c o n f a u t o m a k e a u t o c o n f - a r c h i v e
O n A l p i n e :
a p k a d d a u t o c o n f a u t o m a k e a u t o c o n f - a r c h i v e
O n m a c O S :
b r e w i n s t a l l a u t o c o n f a u t o m a k e a u t o c o n f - a r c h i v e \ n " )
endif ( )
2023-08-08 04:19:53 +08:00
string ( REGEX MATCH "^([0-9]+)\\.([0-9]+)\\.([0-9]+)" PYTHON_VERSION "${VERSION}" )
set ( PYTHON_VERSION_MAJOR "${CMAKE_MATCH_1}" )
set ( PYTHON_VERSION_MINOR "${CMAKE_MATCH_2}" )
set ( PYTHON_VERSION_PATCH "${CMAKE_MATCH_3}" )
2017-05-20 05:31:04 +08:00
2020-12-19 04:00:45 +08:00
set ( PATCHES
2022-11-19 03:53:08 +08:00
0 0 0 1 - o n l y - b u i l d - r e q u i r e d - p r o j e c t s . p a t c h
0 0 0 3 - u s e - v c p k g - z l i b . p a t c h
0 0 0 4 - d e v e n d o r - e x t e r n a l - d e p e n d e n c i e s . p a t c h
0 0 0 5 - d o n t - c o p y - v c r u n t i m e . p a t c h
0 0 0 8 - p y t h o n . p c . p a t c h
0 0 1 0 - d o n t - s k i p - r p a t h . p a t c h
2023-11-11 03:30:23 +08:00
0 0 1 2 - f o r c e - d i s a b l e - m o d u l e s . p a t c h
2023-04-27 02:51:50 +08:00
0 0 1 4 - f i x - g e t - p y t h o n - i n c - o u t p u t . p a t c h
2023-08-10 01:29:22 +08:00
0 0 1 5 - d o n t - u s e - W I N D O W S - d e f . p a t c h
2024-01-20 04:30:11 +08:00
0 0 1 6 - u n d u p - f f i - s y m b o l s . p a t c h # Required for lld-link.
2023-11-07 02:59:04 +08:00
0 0 1 8 - f i x - s y s c o n f i g - i n c l u d e . p a t c h
2020-12-19 04:00:45 +08:00
)
2022-11-19 03:53:08 +08:00
2020-12-19 04:00:45 +08:00
if ( VCPKG_LIBRARY_LINKAGE STREQUAL "static" )
2022-11-19 03:53:08 +08:00
list ( APPEND PATCHES 0002-static-library.patch )
2020-06-12 13:23:26 +08:00
endif ( )
2022-11-19 03:53:08 +08:00
2022-10-15 07:14:12 +08:00
# Fix build failures with GCC for built-in modules (https://github.com/microsoft/vcpkg/issues/26573)
2023-08-10 01:29:22 +08:00
if ( VCPKG_TARGET_IS_LINUX )
2022-11-19 03:53:08 +08:00
list ( APPEND PATCHES 0011-gcc-ldflags-fix.patch )
2022-10-15 07:14:12 +08:00
endif ( )
2020-06-12 13:23:26 +08:00
2021-03-30 01:09:14 +08:00
# Python 3.9 removed support for Windows 7. This patch re-adds support for Windows 7 and is therefore
# required to build this port on Windows 7 itself due to Python using itself in its own build system.
if ( "deprecated-win7-support" IN_LIST FEATURES )
2021-10-07 03:53:06 +08:00
list ( APPEND PATCHES 0006-restore-support-for-windows-7.patch )
2021-03-30 01:09:14 +08:00
message ( WARNING "Windows 7 support is deprecated and may be removed at any time." )
elseif ( VCPKG_TARGET_IS_WINDOWS AND CMAKE_SYSTEM_VERSION EQUAL 6.1 )
message ( FATAL_ERROR "python3 requires the feature deprecated-win7-support when building on Windows 7." )
endif ( )
2023-08-10 01:29:22 +08:00
if ( VCPKG_TARGET_IS_WINDOWS )
2022-06-01 07:20:33 +08:00
string ( COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" PYTHON_ALLOW_EXTENSIONS )
# The Windows 11 SDK has a problem that causes it to error on the resource files, so we patch that.
2021-09-30 00:00:21 +08:00
vcpkg_get_windows_sdk ( WINSDK_VERSION )
if ( "${WINSDK_VERSION}" VERSION_GREATER_EQUAL "10.0.22000" )
2021-10-07 03:53:06 +08:00
list ( APPEND PATCHES "0007-workaround-windows-11-sdk-rc-compiler-error.patch" )
2021-09-30 00:00:21 +08:00
endif ( )
2023-08-10 01:29:22 +08:00
if ( VCPKG_CROSSCOMPILING )
list ( APPEND PATCHES "0016-fix-win-cross.patch" )
2023-08-19 03:04:24 +08:00
else ( )
list ( APPEND PATCHES "0017-fix-win.patch" )
2023-08-10 01:29:22 +08:00
endif ( )
2021-09-30 00:00:21 +08:00
endif ( )
2017-05-20 05:31:04 +08:00
vcpkg_from_github (
2020-12-19 04:00:45 +08:00
O U T _ S O U R C E _ P A T H S O U R C E _ P A T H
2017-05-20 05:31:04 +08:00
R E P O p y t h o n / c p y t h o n
2018-01-05 00:55:01 +08:00
R E F v $ { P Y T H O N _ V E R S I O N }
2023-09-08 04:12:03 +08:00
S H A 5 1 2 6 3 c 1 c c 8 1 7 8 4 4 5 8 4 c 9 e a 8 8 0 b e 0 2 7 7 e b c c 1 8 1 8 2 c 5 0 5 0 f 5 9 e b b b 8 d d 4 2 c 9 7 1 9 7 9 b b 2 c e e 0 f 0 9 a f 6 a 1 e 6 2 a 6 c 8 c 2 3 1 4 3 d f a 6 f f 2 1 f c 1 a b a 2 5 e f 5 0 a 4 2 5 f d e a 4 6 f f 3 e 3 5 8 9 6
2017-05-20 05:31:04 +08:00
H E A D _ R E F m a s t e r
2020-06-12 13:23:26 +08:00
P A T C H E S $ { P A T C H E S }
2018-03-18 19:31:30 +08:00
)
2022-02-04 17:17:37 +08:00
vcpkg_replace_string ( "${SOURCE_PATH}/Makefile.pre.in" "$(INSTALL) -d -m $(DIRMODE)" "$(MKDIR_P)" )
2022-02-08 13:58:30 +08:00
function ( make_python_pkgconfig )
cmake_parse_arguments ( PARSE_ARGV 0 arg "" "FILE;INSTALL_ROOT;EXEC_PREFIX;INCLUDEDIR;ABIFLAGS" "" )
set ( prefix "${CURRENT_PACKAGES_DIR}" )
set ( libdir [[ ${ prefix } /lib]] )
set ( exec_prefix ${ arg_EXEC_PREFIX } )
set ( includedir ${ arg_INCLUDEDIR } )
set ( VERSION "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}" )
set ( ABIFLAGS ${ arg_ABIFLAGS } )
string ( REPLACE "python" "python-${VERSION}" out_file ${ arg_FILE } )
set ( out_full_path "${arg_INSTALL_ROOT}/lib/pkgconfig/${out_file}" )
configure_file ( "${SOURCE_PATH}/Misc/${arg_FILE}.in" ${ out_full_path } @ONLY )
file ( READ ${ out_full_path } pkgconfig_file )
string ( REPLACE "-lpython${VERSION}" "-lpython${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}" pkgconfig_file "${pkgconfig_file}" )
file ( WRITE ${ out_full_path } "${pkgconfig_file}" )
endfunction ( )
2023-08-08 04:19:53 +08:00
if ( VCPKG_TARGET_IS_WINDOWS )
2020-12-19 04:00:45 +08:00
# Due to the way Python handles C extension modules on Windows, a static python core cannot
# load extension modules.
if ( PYTHON_ALLOW_EXTENSIONS )
find_library ( BZ2_RELEASE NAMES bz2 PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH )
find_library ( BZ2_DEBUG NAMES bz2d PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH )
find_library ( CRYPTO_RELEASE NAMES libcrypto PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH )
find_library ( CRYPTO_DEBUG NAMES libcrypto PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH )
2022-11-24 02:12:44 +08:00
find_library ( EXPAT_RELEASE NAMES libexpat libexpatMD libexpatMT PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH )
find_library ( EXPAT_DEBUG NAMES libexpatd libexpatdMD libexpatdMT PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH )
2023-08-25 03:51:20 +08:00
find_library ( FFI_RELEASE NAMES ffi PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH )
find_library ( FFI_DEBUG NAMES ffi PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH )
2020-12-19 04:00:45 +08:00
find_library ( LZMA_RELEASE NAMES lzma PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH )
2022-03-01 02:25:31 +08:00
find_library ( LZMA_DEBUG NAMES lzma PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH )
2020-12-19 04:00:45 +08:00
find_library ( SQLITE_RELEASE NAMES sqlite3 PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH )
find_library ( SQLITE_DEBUG NAMES sqlite3 PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH )
find_library ( SSL_RELEASE NAMES libssl PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH )
find_library ( SSL_DEBUG NAMES libssl PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH )
2023-08-10 01:29:22 +08:00
list ( APPEND add_libs_rel "${BZ2_RELEASE};${EXPAT_RELEASE};${FFI_RELEASE};${LZMA_RELEASE};${SQLITE_RELEASE}" )
list ( APPEND add_libs_dbg "${BZ2_DEBUG};${EXPAT_DEBUG};${FFI_DEBUG};${LZMA_DEBUG};${SQLITE_DEBUG}" )
2020-12-19 04:00:45 +08:00
else ( )
message ( STATUS "WARNING: Static builds of Python will not have C extension modules available." )
endif ( )
find_library ( ZLIB_RELEASE NAMES zlib PATHS "${CURRENT_INSTALLED_DIR}/lib" NO_DEFAULT_PATH )
find_library ( ZLIB_DEBUG NAMES zlib zlibd PATHS "${CURRENT_INSTALLED_DIR}/debug/lib" NO_DEFAULT_PATH )
2023-08-10 01:29:22 +08:00
list ( APPEND add_libs_rel "${ZLIB_RELEASE}" )
list ( APPEND add_libs_dbg "${ZLIB_DEBUG}" )
2020-12-19 04:00:45 +08:00
2021-09-14 11:00:44 +08:00
configure_file ( "${SOURCE_PATH}/PC/pyconfig.h" "${SOURCE_PATH}/PC/pyconfig.h" )
configure_file ( "${CMAKE_CURRENT_LIST_DIR}/python_vcpkg.props.in" "${SOURCE_PATH}/PCbuild/python_vcpkg.props" )
configure_file ( "${CMAKE_CURRENT_LIST_DIR}/openssl.props.in" "${SOURCE_PATH}/PCbuild/openssl.props" )
file ( WRITE "${SOURCE_PATH}/PCbuild/libffi.props"
2023-08-10 01:29:22 +08:00
" < ? x m l v e r s i o n = ' 1 . 0 ' e n c o d i n g = ' u t f - 8 ' ? > "
" < P r o j e c t x m l n s = ' h t t p : / / s c h e m a s . m i c r o s o f t . c o m / d e v e l o p e r / m s b u i l d / 2 0 0 3 ' / > "
2020-12-19 04:00:45 +08:00
)
2023-08-10 01:29:22 +08:00
list ( APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS "-DVCPKG_SET_CHARSET_FLAG=OFF" )
2020-12-19 04:00:45 +08:00
if ( PYTHON_ALLOW_EXTENSIONS )
set ( OPTIONS
" / p : I n c l u d e E x t e n s i o n s = t r u e "
" / p : I n c l u d e E x t e r n a l s = t r u e "
" / p : I n c l u d e C T y p e s = t r u e "
" / p : I n c l u d e S S L = t r u e "
" / p : I n c l u d e T k i n t e r = f a l s e "
" / p : I n c l u d e T e s t s = f a l s e "
" / 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 O U R C E _ P A T H } / P C b u i l d / p y t h o n _ v c p k g . p r o p s "
)
else ( )
set ( OPTIONS
" / p : I n c l u d e E x t e n s i o n s = f a l s e "
" / p : I n c l u d e E x t e r n a l s = f a l s e "
" / p : I n c l u d e T e s t s = f a l s e "
" / 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 O U R C E _ P A T H } / P C b u i l d / p y t h o n _ v c p k g . p r o p s "
)
endif ( )
if ( VCPKG_TARGET_IS_UWP )
list ( APPEND OPTIONS "/p:IncludeUwp=true" )
else ( )
list ( APPEND OPTIONS "/p:IncludeUwp=false" )
endif ( )
if ( VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic" )
list ( APPEND OPTIONS "/p:_VcpkgPythonLinkage=DynamicLibrary" )
else ( )
list ( APPEND OPTIONS "/p:_VcpkgPythonLinkage=StaticLibrary" )
2020-05-22 02:39:48 +08:00
endif ( )
2020-03-11 03:25:18 +08:00
2023-08-10 01:29:22 +08:00
vcpkg_find_acquire_program ( PYTHON3 )
get_filename_component ( PYTHON3_DIR "${PYTHON3}" DIRECTORY )
set ( ENV{PythonForBuild} "${PYTHON3_DIR}/python.exe" ) # PythonForBuild is what's used on windows, despite the readme
2020-12-19 04:00:45 +08:00
2023-08-10 01:29:22 +08:00
if ( VCPKG_CROSSCOMPILING )
vcpkg_add_to_path ( "${CURRENT_HOST_INSTALLED_DIR}/manual-tools/${PORT}" )
endif ( )
2023-08-08 04:19:53 +08:00
2023-08-10 01:29:22 +08:00
vcpkg_msbuild_install (
2021-09-14 11:00:44 +08:00
S O U R C E _ P A T H " $ { S O U R C E _ P A T H } "
2020-12-19 04:00:45 +08:00
P R O J E C T _ S U B P A T H " P C b u i l d / p c b u i l d . p r o j "
2023-08-10 01:29:22 +08:00
A D D _ B I N _ T O _ P A T H
2020-12-19 04:00:45 +08:00
O P T I O N S $ { O P T I O N S }
2023-08-10 01:29:22 +08:00
A D D I T I O N A L _ L I B S _ R E L E A S E $ { a d d _ l i b s _ r e l }
A D D I T I O N A L _ L I B S _ D E B U G $ { a d d _ l i b s _ d b g }
2020-12-19 04:00:45 +08:00
)
2023-08-10 01:29:22 +08:00
if ( NOT VCPKG_CROSSCOMPILING )
file ( GLOB_RECURSE freeze_module "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/PCbuild/**/_freeze_module.exe" )
file ( COPY "${freeze_module}" DESTINATION "${CURRENT_PACKAGES_DIR}/manual-tools/${PORT}" )
vcpkg_copy_tool_dependencies ( "${CURRENT_PACKAGES_DIR}/manual-tools/${PORT}" )
endif ( )
2020-12-19 04:00:45 +08:00
# The extension modules must be placed in the DLLs directory, so we can't use vcpkg_copy_tools()
if ( PYTHON_ALLOW_EXTENSIONS )
2023-07-27 02:11:05 +08:00
file ( GLOB_RECURSE PYTHON_EXTENSIONS_RELEASE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/*.pyd" )
file ( COPY ${ PYTHON_EXTENSIONS_RELEASE } DESTINATION "${CURRENT_PACKAGES_DIR}/bin" )
file ( COPY ${ PYTHON_EXTENSIONS_RELEASE } DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}/DLLs" )
2020-12-19 04:00:45 +08:00
vcpkg_copy_tool_dependencies ( "${CURRENT_PACKAGES_DIR}/tools/${PORT}/DLLs" )
file ( REMOVE "${CURRENT_PACKAGES_DIR}/tools/${PORT}/DLLs/python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}.dll" )
2023-07-27 02:11:05 +08:00
file ( GLOB_RECURSE PYTHON_EXTENSIONS_DEBUG "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/*.pyd" )
file ( COPY ${ PYTHON_EXTENSIONS_DEBUG } DESTINATION "${CURRENT_PACKAGES_DIR}/debug/bin" )
2020-12-19 04:00:45 +08:00
endif ( )
file ( COPY "${SOURCE_PATH}/Include/" "${SOURCE_PATH}/PC/pyconfig.h"
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 / p y t h o n $ { P Y T H O N _ V E R S I O N _ M A J O R } . $ { P Y T H O N _ V E R S I O N _ M I N O R } "
F I L E S _ M A T C H I N G P A T T E R N * . h
)
file ( COPY "${SOURCE_PATH}/Lib" DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}" )
# Remove any extension libraries and other unversioned binaries that could conflict with the python2 port.
# You don't need to link against these anyway.
file ( GLOB PYTHON_LIBS
" $ { C U R R E N T _ P A C K A G E S _ D I R } / l i b / * . l i b "
" $ { C U R R E N T _ P A C K A G E S _ D I R } / d e b u g / l i b / * . l i b "
)
list ( FILTER PYTHON_LIBS EXCLUDE REGEX [[python[0-9]*(_d ) ? \ . l i b $ ] ] )
file ( GLOB PYTHON_INSTALLERS "${CURRENT_PACKAGES_DIR}/tools/${PORT}/wininst-*.exe" )
file ( REMOVE ${ PYTHON_LIBS } ${ PYTHON_INSTALLERS } )
2022-01-04 06:24:11 +08:00
# pkg-config files
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release" )
2022-02-08 13:58:30 +08:00
make_python_pkgconfig ( FILE python.pc INSTALL_ROOT ${ CURRENT_PACKAGES_DIR }
E X E C _ P R E F I X " \ $ { p r e f i x } / t o o l s / $ { P O R T } " I N C L U D E D I R [ [ $ { p r e f i x } / i n c l u d e ] ] A B I F L A G S " " )
make_python_pkgconfig ( FILE python-embed.pc INSTALL_ROOT ${ CURRENT_PACKAGES_DIR }
E X E C _ P R E F I X " \ $ { p r e f i x } / t o o l s / $ { P O R T } " I N C L U D E D I R [ [ $ { p r e f i x } / i n c l u d e ] ] A B I F L A G S " " )
2022-01-04 06:24:11 +08:00
endif ( )
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug" )
2022-02-08 13:58:30 +08:00
make_python_pkgconfig ( FILE python.pc INSTALL_ROOT "${CURRENT_PACKAGES_DIR}/debug"
E X E C _ P R E F I X " \ $ { p r e f i x } / . . / t o o l s / $ { P O R T } " I N C L U D E D I R [ [ $ { p r e f i x } / . . / i n c l u d e ] ] A B I F L A G S " _ d " )
make_python_pkgconfig ( FILE python-embed.pc INSTALL_ROOT "${CURRENT_PACKAGES_DIR}/debug"
E X E C _ P R E F I X " \ $ { p r e f i x } / . . / t o o l s / $ { P O R T } " I N C L U D E D I R [ [ $ { p r e f i x } / . . / i n c l u d e ] ] A B I F L A G S " _ d " )
2022-01-04 06:24:11 +08:00
endif ( )
vcpkg_fixup_pkgconfig ( )
2022-03-03 07:00:38 +08:00
# Remove static library belonging to executable
if ( VCPKG_LIBRARY_LINKAGE STREQUAL "static" )
if ( EXISTS "${CURRENT_PACKAGES_DIR}/lib/python.lib" )
file ( MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/lib/manual-link" )
file ( RENAME "${CURRENT_PACKAGES_DIR}/lib/python.lib"
" $ { C U R R E N T _ P A C K A G E S _ D I R } / l i b / m a n u a l - l i n k / p y t h o n . l i b " )
endif ( )
if ( EXISTS "${CURRENT_PACKAGES_DIR}/debug/lib/python_d.lib" )
file ( MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/debug/lib/manual-link" )
file ( RENAME "${CURRENT_PACKAGES_DIR}/debug/lib/python_d.lib"
" $ { C U R R E N T _ P A C K A G E S _ D I R } / d e b u g / l i b / m a n u a l - l i n k / p y t h o n _ d . l i b " )
endif ( )
endif ( )
2020-12-19 04:00:45 +08:00
else ( )
2022-08-05 04:49:06 +08:00
# The Python Stable ABI, `libpython3.so` is not produced by the upstream build system with --with-pydebug option
if ( VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic" AND NOT VCPKG_BUILD_TYPE )
set ( VCPKG_POLICY_MISMATCHED_NUMBER_OF_BINARIES enabled )
endif ( )
2020-12-19 04:00:45 +08:00
set ( OPTIONS
" - - w i t h - o p e n s s l = $ { C U R R E N T _ I N S T A L L E D _ D I R } "
2022-06-01 07:20:33 +08:00
" - - w i t h o u t - e n s u r e p i p "
2021-10-01 14:58:36 +08:00
" - - w i t h - s u f f i x = "
2020-12-19 04:00:45 +08:00
" - - w i t h - s y s t e m - e x p a t "
2022-03-14 16:09:48 +08:00
" - - w i t h o u t - r e a d l i n e "
" - - d i s a b l e - t e s t - m o d u l e s "
2020-12-19 04:00:45 +08:00
)
if ( VCPKG_TARGET_IS_OSX )
list ( APPEND OPTIONS "LIBS=-liconv -lintl" )
endif ( )
2019-11-19 06:04:25 +08:00
2023-08-08 04:19:53 +08:00
# The version of the build Python must match the version of the cross compiled host Python.
# https://docs.python.org/3/using/configure.html#cross-compiling-options
if ( VCPKG_CROSSCOMPILING )
set ( _python_for_build "${CURRENT_HOST_INSTALLED_DIR}/tools/python3/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}" )
list ( APPEND OPTIONS "--with-build-python=${_python_for_build}" )
endif ( )
2020-12-19 04:00:45 +08:00
vcpkg_configure_make (
2021-09-14 11:00:44 +08:00
S O U R C E _ P A T H " $ { S O U R C E _ P A T H } "
2023-08-08 04:19:53 +08:00
A U T O C O N F I G
O P T I O N S
$ { O P T I O N S }
O P T I O N S _ D E B U G
" - - w i t h - p y d e b u g "
" v c p k g _ r p a t h = $ { C U R R E N T _ I N S T A L L E D _ D I R } / d e b u g / l i b "
O P T I O N S _ R E L E A S E
" v c p k g _ r p a t h = $ { C U R R E N T _ I N S T A L L E D _ D I R } / l i b "
2020-12-19 04:00:45 +08:00
)
vcpkg_install_make ( ADD_BIN_TO_PATH INSTALL_TARGET altinstall )
file ( COPY "${CURRENT_PACKAGES_DIR}/tools/${PORT}/bin/" DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}" )
# Makefiles, c files, __pycache__, and other junk.
file ( GLOB PYTHON_LIB_DIRS LIST_DIRECTORIES true
" $ { C U R R E N T _ P A C K A G E S _ D I R } / l i b / p y t h o n $ { P Y T H O N _ V E R S I O N _ M A J O R } . $ { P Y T H O N _ V E R S I O N _ M I N O R } / * "
" $ { C U R R E N T _ P A C K A G E S _ D I R } / d e b u g / l i b / p y t h o n $ { P Y T H O N _ V E R S I O N _ M A J O R } . $ { P Y T H O N _ V E R S I O N _ M I N O R } / * " )
list ( FILTER PYTHON_LIB_DIRS INCLUDE REGEX [[config-[0-9].*.*]] )
file ( REMOVE_RECURSE ${ PYTHON_LIB_DIRS } )
file ( REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" )
file ( REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/bin" )
file ( REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include" )
file ( REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share" )
file ( REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/include/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}d" )
file ( REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/share/${PORT}/man1" )
file ( REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/tools/${PORT}/bin" )
file ( REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/tools/${PORT}/debug" )
2021-11-10 03:45:15 +08:00
vcpkg_fixup_pkgconfig ( )
2022-08-05 04:49:06 +08:00
# Perform some post-build checks on modules
file ( GLOB python_libs_dynload_debug LIST_DIRECTORIES false "${CURRENT_PACKAGES_DIR}/debug/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/lib-dynload/*.so*" )
file ( GLOB python_libs_dynload_release LIST_DIRECTORIES false "${CURRENT_PACKAGES_DIR}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/lib-dynload/*.so*" )
set ( python_libs_dynload_failed_debug ${ python_libs_dynload_debug } )
set ( python_libs_dynload_failed_release ${ python_libs_dynload_release } )
list ( FILTER python_libs_dynload_failed_debug INCLUDE REGEX ".*_failed\.so.*" )
list ( FILTER python_libs_dynload_failed_release INCLUDE REGEX ".*_failed\.so.*" )
if ( python_libs_dynload_failed_debug OR python_libs_dynload_failed_release )
list ( JOIN python_libs_dynload_failed_debug "\n" python_libs_dynload_failed_debug_str )
list ( JOIN python_libs_dynload_failed_release "\n" python_libs_dynload_failed_release_str )
message ( FATAL_ERROR "There should be no modules with \" _failed\ " suffix:\n${python_libs_dynload_failed_debug_str}\n${python_libs_dynload_failed_release_str}" )
endif ( )
if ( NOT VCPKG_BUILD_TYPE )
list ( LENGTH python_libs_dynload_release python_libs_dynload_release_length )
list ( LENGTH python_libs_dynload_debug python_libs_dynload_debug_length )
if ( NOT python_libs_dynload_release_length STREQUAL python_libs_dynload_debug_length )
message ( FATAL_ERROR "Mismatched number of modules: ${python_libs_dynload_debug_length} in debug, ${python_libs_dynload_release_length} in release" )
endif ( )
endif ( )
2019-09-30 09:58:00 +08:00
endif ( )
2021-01-06 05:39:53 +08:00
2023-08-10 01:29:22 +08:00
vcpkg_install_copyright ( FILE_LIST "${SOURCE_PATH}/LICENSE" )
2022-06-01 07:20:33 +08:00
file ( READ "${CMAKE_CURRENT_LIST_DIR}/usage" usage )
if ( VCPKG_TARGET_IS_WINDOWS )
if ( PYTHON_ALLOW_EXTENSIONS )
file ( READ "${CMAKE_CURRENT_LIST_DIR}/usage.win" usage_extra )
else ( )
set ( usage_extra "" )
endif ( )
else ( )
file ( READ "${CMAKE_CURRENT_LIST_DIR}/usage.unix" usage_extra )
endif ( )
2023-08-08 04:19:53 +08:00
string ( REPLACE "@PYTHON_VERSION_MINOR@" "${PYTHON_VERSION_MINOR}" usage_extra "${usage_extra}" )
2022-06-01 07:20:33 +08:00
file ( WRITE "${CURRENT_PACKAGES_DIR}/share/${PORT}/usage" "${usage}\n${usage_extra}" )
2021-01-06 05:39:53 +08:00
function ( _generate_finder )
cmake_parse_arguments ( PythonFinder "NO_OVERRIDE" "DIRECTORY;PREFIX" "" ${ ARGN } )
configure_file (
" $ { C M A K E _ C U R R E N T _ L I S T _ D I R } / v c p k g - c m a k e - w r a p p e r . c m a k e "
" $ { C U R R E N T _ P A C K A G E S _ D I R } / s h a r e / $ { P y t h o n F i n d e r _ D I R E C T O R Y } / v c p k g - c m a k e - w r a p p e r . c m a k e "
@ O N L Y
)
endfunction ( )
message ( STATUS "Installing cmake wrappers" )
_generate_finder ( DIRECTORY "python" PREFIX "Python" )
_generate_finder ( DIRECTORY "python3" PREFIX "Python3" )
_generate_finder ( DIRECTORY "pythoninterp" PREFIX "PYTHON" NO_OVERRIDE )
2021-11-10 03:45:15 +08:00
if ( NOT VCPKG_TARGET_IS_WINDOWS )
2021-12-03 11:51:47 +08:00
function ( replace_dirs_in_config_file python_config_file )
vcpkg_replace_string ( "${python_config_file}" "${CURRENT_INSTALLED_DIR}" "' + _base + '" )
2023-08-08 04:19:53 +08:00
vcpkg_replace_string ( "${python_config_file}" "${CURRENT_HOST_INSTALLED_DIR}" "' + _base + '/../${HOST_TRIPLET}" )
2021-12-03 11:51:47 +08:00
vcpkg_replace_string ( "${python_config_file}" "${CURRENT_PACKAGES_DIR}" "' + _base + '" )
vcpkg_replace_string ( "${python_config_file}" "${CURRENT_BUILDTREES_DIR}" "not/existing" )
endfunction ( )
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release" )
file ( GLOB python_config_files "${CURRENT_PACKAGES_DIR}/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/_sysconfigdata*" )
list ( POP_FRONT python_config_files python_config_file )
vcpkg_replace_string ( "${python_config_file}" "# system configuration generated and used by the sysconfig module" "# system configuration generated and used by the sysconfig module\nimport os\n_base = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))\n" )
replace_dirs_in_config_file ( "${python_config_file}" )
endif ( )
if ( NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug" )
file ( GLOB python_config_files "${CURRENT_PACKAGES_DIR}/debug/lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/_sysconfigdata*" )
list ( POP_FRONT python_config_files python_config_file )
vcpkg_replace_string ( "${python_config_file}" "# system configuration generated and used by the sysconfig module" "# system configuration generated and used by the sysconfig module\nimport os\n_base = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))\n" )
replace_dirs_in_config_file ( "${python_config_file}" )
endif ( )
2021-11-10 03:45:15 +08:00
endif ( )
2024-01-20 04:30:11 +08:00
if ( VCPKG_TARGET_IS_WINDOWS )
vcpkg_replace_string ( "${CURRENT_PACKAGES_DIR}/tools/python3/Lib/distutils/command/build_ext.py" "'libs'" "'../../lib'" )
else ( )
vcpkg_replace_string ( "${CURRENT_PACKAGES_DIR}/lib/python3.${PYTHON_VERSION_MINOR}/distutils/command/build_ext.py" "'libs'" "'../../lib'" )
file ( COPY_FILE "${CURRENT_PACKAGES_DIR}/tools/python3/python3.${PYTHON_VERSION_MINOR}" "${CURRENT_PACKAGES_DIR}/tools/python3/python3" )
endif ( )
configure_file ( "${CMAKE_CURRENT_LIST_DIR}/vcpkg-port-config.cmake" "${CURRENT_PACKAGES_DIR}/share/python3/vcpkg-port-config.cmake" @ONLY )