diff --git a/ports/itk/portfile.cmake b/ports/itk/portfile.cmake index c89c65aa59ec5a..8961379a5a66cc 100644 --- a/ports/itk/portfile.cmake +++ b/ports/itk/portfile.cmake @@ -108,22 +108,6 @@ if("python" IN_LIST FEATURES) "-DSWIG_EXECUTABLE=${SWIG}" "-DSWIG_DIR=${SWIG_DIR}" ) - # Due to ITKs internal shenanigans with the variables ...... - if(VCPKG_TARGET_IS_WINDOWS) - list(APPEND ADDITIONAL_OPTIONS "-DPython3_LIBRARY_RELEASE:PATH=${CURRENT_INSTALLED_DIR}/lib/python39.lib" - "-DPython3_LIBRARY_DEBUG:PATH=${CURRENT_INSTALLED_DIR}/debug/lib/python39_d.lib" - "-DPython3_INCLUDE_DIR:PATH=${CURRENT_INSTALLED_DIR}/include/python3.9") - list(APPEND OPTIONS_DEBUG "-DPython3_LIBRARY=${CURRENT_INSTALLED_DIR}/debug/lib/python39_d.lib") - list(APPEND OPTIONS_RELEASE "-DPython3_LIBRARY=${CURRENT_INSTALLED_DIR}/lib/python39.lib") - elseif(VCPKG_TARGET_IS_LINUX) - list(APPEND ADDITIONAL_OPTIONS "-DPython3_LIBRARY_RELEASE:PATH=${CURRENT_INSTALLED_DIR}/lib/libpython39m.a" - "-DPython3_LIBRARY_DEBUG:PATH=${CURRENT_INSTALLED_DIR}/debug/lib/libpython39md.a" - "-DPython3_INCLUDE_DIR:PATH=${CURRENT_INSTALLED_DIR}/include/python3.9m") - list(APPEND OPTIONS_DEBUG "-DPython3_LIBRARY=${CURRENT_INSTALLED_DIR}/debug/lib/libpython39md.a") - list(APPEND OPTIONS_RELEASE "-DPython3_LIBRARY=${CURRENT_INSTALLED_DIR}/lib/libpython39m.a") - elseif(VCPKG_TARGET_IS_OSX) - #Need Python3 information on OSX within VCPKG - endif() #ITK_PYTHON_SITE_PACKAGES_SUFFIX should be set to the install dir of the site-packages within vcpkg endif() diff --git a/ports/itk/vcpkg.json b/ports/itk/vcpkg.json index 24de005c6794f1..394b45afba00f2 100644 --- a/ports/itk/vcpkg.json +++ b/ports/itk/vcpkg.json @@ -1,7 +1,7 @@ { "name": "itk", "version-string": "5.1.0", - "port-version": 4, + "port-version": 5, "description": "Insight Segmentation and Registration Toolkit (ITK) is used for image processing and analysis.", "homepage": "https://github.com/InsightSoftwareConsortium/ITK", "dependencies": [ diff --git a/ports/pybind11/CONTROL b/ports/pybind11/CONTROL index be711e1b1be0d2..8b14c31ec0123b 100644 --- a/ports/pybind11/CONTROL +++ b/ports/pybind11/CONTROL @@ -1,6 +1,6 @@ Source: pybind11 Version: 2.6.0 -Port-Version: 1 +Port-Version: 2 Homepage: https://github.com/pybind/pybind11 Description: pybind11 is a lightweight header-only library that exposes C++ types in Python and vice versa, mainly to create Python bindings of existing C++ code. Build-Depends: python3 (windows) diff --git a/ports/pybind11/portfile.cmake b/ports/pybind11/portfile.cmake index 458c2a669a9882..e227e0971f79c3 100644 --- a/ports/pybind11/portfile.cmake +++ b/ports/pybind11/portfile.cmake @@ -7,23 +7,18 @@ vcpkg_from_github( ) vcpkg_find_acquire_program(PYTHON3) -get_filename_component(PYPATH ${PYTHON3} PATH) -vcpkg_add_to_path("${PYPATH}") vcpkg_configure_cmake( SOURCE_PATH ${SOURCE_PATH} PREFER_NINJA OPTIONS -DPYBIND11_TEST=OFF - -DPYTHONLIBS_FOUND=ON - -DPYTHON_INCLUDE_DIRS=${CURRENT_INSTALLED_DIR}/include - -DPYTHON_MODULE_EXTENSION=.dll + -DPYBIND11_FINDPYTHON=ON + -DPython3_EXECUTABLE=${PYTHON3} OPTIONS_RELEASE -DPYTHON_IS_DEBUG=OFF - -DPYTHON_LIBRARIES=${CURRENT_INSTALLED_DIR}/lib/python39.lib OPTIONS_DEBUG -DPYTHON_IS_DEBUG=ON - -DPYTHON_LIBRARIES=${CURRENT_INSTALLED_DIR}/debug/lib/python39_d.lib ) vcpkg_install_cmake() diff --git a/ports/python3/portfile.cmake b/ports/python3/portfile.cmake index 711b317e02c448..72b4ee3bd8e6c1 100644 --- a/ports/python3/portfile.cmake +++ b/ports/python3/portfile.cmake @@ -179,3 +179,19 @@ else() file(INSTALL "${SOURCE_PATH}/LICENSE" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME "copyright") endif() + +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") + +function(_generate_finder) + cmake_parse_arguments(PythonFinder "NO_OVERRIDE" "DIRECTORY;PREFIX" "" ${ARGN}) + configure_file( + "${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake" + "${CURRENT_PACKAGES_DIR}/share/${PythonFinder_DIRECTORY}/vcpkg-cmake-wrapper.cmake" + @ONLY + ) +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) diff --git a/ports/python3/usage b/ports/python3/usage new file mode 100644 index 00000000000000..e177b11f63bd7d --- /dev/null +++ b/ports/python3/usage @@ -0,0 +1,4 @@ +The package python3 is compatible with built-in CMake targets: + + find_package(Python3 COMPONENTS Development REQUIRED) + target_link_libraries(main PRIVATE Python3::Python) diff --git a/ports/python3/vcpkg-cmake-wrapper.cmake b/ports/python3/vcpkg-cmake-wrapper.cmake new file mode 100644 index 00000000000000..83c3fbd1cfec33 --- /dev/null +++ b/ports/python3/vcpkg-cmake-wrapper.cmake @@ -0,0 +1,120 @@ +# For very old ports whose upstream do not properly set the minimum CMake version. +cmake_policy(SET CMP0012 NEW) +cmake_policy(SET CMP0057 NEW) + +# This prevents the port's python.exe from overriding the Python fetched by +# vcpkg_find_acquire_program(PYTHON3) and prevents the vcpkg toolchain from +# stomping on FindPython's default functionality. +list(REMOVE_ITEM CMAKE_PROGRAM_PATH "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/tools/python3") +if(@PythonFinder_NO_OVERRIDE@) + _find_package(${ARGS}) + return() +endif() + +# CMake's FindPython's separation of concerns is very muddy. We only want to force vcpkg's Python +# if the consumer is using the development component. What we don't want to do is break detection +# of the system Python, which may have certain packages the user expects. But - if the user is +# embedding Python or using both the development and interpreter components, then we need the +# interpreter matching vcpkg's Python libraries. Note that the "Development" component implies +# both "Development.Module" and "Development.Embed" +if("Development" IN_LIST ARGS OR "Development.Embed" IN_LIST ARGS) + set(_PythonFinder_WantInterp TRUE) + set(_PythonFinder_WantLibs TRUE) +elseif("Development.Module" IN_LIST ARGS) + if("Interpreter" IN_LIST ARGS) + set(_PythonFinder_WantInterp TRUE) + endif() + set(_PythonFinder_WantLibs TRUE) +endif() + +if(_PythonFinder_WantLibs) + find_path( + @PythonFinder_PREFIX@_INCLUDE_DIR + NAMES "Python.h" + PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include" + PATH_SUFFIXES "python@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@" + NO_DEFAULT_PATH + ) + + # Don't set the public facing hint or the finder will be unable to detect the debug library. + # Internally, it uses the same value with an underscore prepended. + find_library( + _@PythonFinder_PREFIX@_LIBRARY_RELEASE + NAMES + "python@PYTHON_VERSION_MAJOR@@PYTHON_VERSION_MINOR@" + "python@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@" + PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib" + NO_DEFAULT_PATH + ) + find_library( + _@PythonFinder_PREFIX@_LIBRARY_DEBUG + NAMES + "python@PYTHON_VERSION_MAJOR@@PYTHON_VERSION_MINOR@_d" + "python@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@d" + PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib" + NO_DEFAULT_PATH + ) + + if(_PythonFinder_WantInterp) + find_program( + @PythonFinder_PREFIX@_EXECUTABLE + NAMES "python" "python@PYTHON_VERSION_MAJOR@.@PYTHON_VERSION_MINOR@" + PATHS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/tools/python3" + NO_DEFAULT_PATH + ) + endif() + + _find_package(${ARGS}) + + if(@VCPKG_LIBRARY_LINKAGE@ STREQUAL static) + include(CMakeFindDependencyMacro) + + # Python for Windows embeds the zlib module into the core, so we have to link against it. + # This is a separate extension module on Unix-like platforms. + if(WIN32) + find_dependency(ZLIB) + if(TARGET @PythonFinder_PREFIX@::Python) + set_property(TARGET @PythonFinder_PREFIX@::Python APPEND PROPERTY INTERFACE_LINK_LIBRARIES ZLIB::ZLIB) + endif() + if(TARGET @PythonFinder_PREFIX@::Module) + set_property(TARGET @PythonFinder_PREFIX@::Module APPEND PROPERTY INTERFACE_LINK_LIBRARIES ZLIB::ZLIB) + endif() + if(DEFINED @PythonFinder_PREFIX@_LIBRARIES) + list(APPEND @PythonFinder_PREFIX@_LIBRARIES ${ZLIB_LIBRARIES}) + endif() + endif() + + if(APPLE) + find_dependency(Iconv) + find_dependency(Intl) + if(TARGET @PythonFinder_PREFIX@::Python) + get_target_property(_PYTHON_INTERFACE_LIBS @PythonFinder_PREFIX@::Python INTERFACE_LINK_LIBRARIES) + list(REMOVE_ITEM _PYTHON_INTERFACE_LIBS "-liconv" "-lintl") + list(APPEND _PYTHON_INTERFACE_LIBS + Iconv::Iconv + "$,${Intl_LIBRARY_DEBUG},${Intl_LIBRARY_RELEASE}>" + ) + set_property(TARGET @PythonFinder_PREFIX@::Python PROPERTY INTERFACE_LINK_LIBRARIES ${_PYTHON_INTERFACE_LIBS}) + unset(_PYTHON_INTERFACE_LIBS) + endif() + if(TARGET @PythonFinder_PREFIX@::Module) + get_target_property(_PYTHON_INTERFACE_LIBS @PythonFinder_PREFIX@::Module INTERFACE_LINK_LIBRARIES) + list(REMOVE_ITEM _PYTHON_INTERFACE_LIBS "-liconv" "-lintl") + list(APPEND _PYTHON_INTERFACE_LIBS + Iconv::Iconv + "$,${Intl_LIBRARY_DEBUG},${Intl_LIBRARY_RELEASE}>" + ) + set_property(TARGET @PythonFinder_PREFIX@::Module PROPERTY INTERFACE_LINK_LIBRARIES ${_PYTHON_INTERFACE_LIBS}) + unset(_PYTHON_INTERFACE_LIBS) + endif() + if(DEFINED @PythonFinder_PREFIX@_LIBRARIES) + list(APPEND @PythonFinder_PREFIX@_LIBRARIES "-framework CoreFoundation" ${Iconv_LIBRARIES} ${Intl_LIBRARIES}) + endif() + endif() + endif() +else() + _find_package(${ARGS}) +endif() + +unset(_PythonFinder_WantInterp) +unset(_PythonFinder_WantLibs) diff --git a/ports/python3/vcpkg.json b/ports/python3/vcpkg.json index b8aa2ac3c1ed55..d89136da3bdb68 100644 --- a/ports/python3/vcpkg.json +++ b/ports/python3/vcpkg.json @@ -1,7 +1,7 @@ { "name": "python3", "version-string": "3.9.0", - "port-version": 2, + "port-version": 3, "description": "The Python programming language", "homepage": "https://github.com/python/cpython", "supports": "!(arm | uwp)", @@ -11,10 +11,18 @@ "platform": "!(windows & static)" }, "expat", + { + "name": "gettext", + "platform": "osx" + }, { "name": "libffi", "platform": "!(windows & static)" }, + { + "name": "libiconv", + "platform": "osx" + }, { "name": "liblzma", "platform": "!(windows & static)"