aboutsummaryrefslogtreecommitdiff
path: root/vcpkg/scripts/test_ports/vcpkg-ci-python3/project
diff options
context:
space:
mode:
authorEthan Morgan <ethan@gweithio.com>2026-02-14 16:44:06 +0000
committerEthan Morgan <ethan@gweithio.com>2026-02-14 16:44:06 +0000
commit54409423f767d8b1cf30cb7d0efca6b4ca138823 (patch)
treed915ac7828703ce4b963efdd9728a1777ba18c1e /vcpkg/scripts/test_ports/vcpkg-ci-python3/project
move to own git serverHEADmaster
Diffstat (limited to 'vcpkg/scripts/test_ports/vcpkg-ci-python3/project')
-rw-r--r--vcpkg/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt87
-rw-r--r--vcpkg/scripts/test_ports/vcpkg-ci-python3/project/main.c19
2 files changed, 106 insertions, 0 deletions
diff --git a/vcpkg/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt b/vcpkg/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt
new file mode 100644
index 0000000..6339bfa
--- /dev/null
+++ b/vcpkg/scripts/test_ports/vcpkg-ci-python3/project/CMakeLists.txt
@@ -0,0 +1,87 @@
+cmake_minimum_required(VERSION 3.12)
+project(python3-test)
+
+set(Python_ARTIFACTS_PREFIX "_MEOW")
+
+# We need to opt-out of CMP0148 to be able to test the pre-CMake 3.12 Python
+# find modules. The old policy is deprecated, so, at some point, this aspect
+# of the test will have to go away.
+if(POLICY CMP0148)
+ cmake_policy(SET CMP0148 OLD)
+endif()
+
+# The purpose of this test is to ensure that we get the expected values
+# from the finders, not crosscompiling. So, let's not even go there.
+# These find_package() calls aren't required because FindPythonInterp
+# seems to not return a result in CI. Probably because FindPythonInterp
+# prefers the system Python instead of the executable from the python3
+# port.
+if(NOT CMAKE_CROSSCOMPILING)
+ find_package(PythonInterp)
+endif()
+find_package(PythonLibs)
+
+# The old find modules should NOT be prefixed.
+if(DEFINED PythonInterp_MEOW_FOUND OR DEFINED PYTHON_MEOW_EXECUTABLE)
+ message(FATAL_ERROR "FindPythonInterp prefixed the result variables")
+endif()
+if(DEFINED PythonLibs_MEOW_FOUND OR DEFINED PYTHON_MEOW_LIBRARIES)
+ message(FATAL_ERROR "FindPythonLibs prefixed the result variables")
+endif()
+
+function(test_result NAME TYPE EXPECTED UNEXPECTED)
+ if(NOT ${TYPE} ${EXPECTED}${NAME})
+ message(FATAL_ERROR "${EXPECTED}${NAME} should be ${TYPE}")
+ endif()
+ if(${TYPE} ${UNEXPECTED}${NAME})
+ message(FATAL_ERROR "${UNEXPECTED}${NAME} should not be ${TYPE}")
+ endif()
+endfunction()
+
+function(test_new_finder EXPECTED UNEXPECTED)
+ test_result(::Python TARGET ${EXPECTED} ${UNEXPECTED})
+ test_result(_LIBRARIES DEFINED ${EXPECTED} ${UNEXPECTED})
+
+ if(NOT CMAKE_CROSSCOMPILING)
+ test_result(_EXECUTABLE DEFINED ${EXPECTED} ${UNEXPECTED})
+ test_result(_STDLIB DEFINED ${EXPECTED} ${UNEXPECTED})
+ test_result(::Interpreter TARGET ${EXPECTED} ${UNEXPECTED})
+ endif()
+endfunction()
+
+if(NOT CMAKE_CROSSCOMPILING)
+ set(_INTERPRETER "Interpreter")
+endif()
+
+# The new find modules should be prefixed if CMake is 4.0+
+find_package(Python REQUIRED COMPONENTS ${_INTERPRETER} Development)
+if(CMAKE_VERSION VERSION_GREATER_EQUAL 4.0)
+ set(EXPECTED_PYTHON Python_MEOW)
+ set(UNEXPECTED_PYTHON Python)
+else()
+ set(EXPECTED_PYTHON Python)
+ set(UNEXPECTED_PYTHON Python_MEOW)
+endif()
+test_new_finder(${EXPECTED_PYTHON} ${UNEXPECTED_PYTHON})
+
+# Also test non-prefixed. Use Python3:: to avoid conflicts with Python_MEOW::
+# The test against Python3_MEOW should never happen because the prefix variable
+# should be Python3_ARTIFACT_PREFIX, but we set Python_ARTIFACT_PREFIX.
+find_package(Python3 REQUIRED COMPONENTS ${_INTERPRETER} Development)
+test_new_finder(Python3 Python3_MEOW)
+
+# Test embedding the libraries found.
+function(add_test_executable TARGET LIBRARIES INCLUDES)
+ add_executable(${TARGET} main.c)
+ target_link_libraries(${TARGET} PRIVATE ${LIBRARIES})
+ if(INCLUDES)
+ target_include_directories(${TARGET} PRIVATE ${INCLUDES})
+ endif()
+endfunction()
+
+# We're purposefully not testing the result of the old finders.
+# The python3 port never added a vcpkg-cmake-wrapper for FindPythonLibs,
+# and it seems like a poor use of time to do so at this point - the
+# old finders are soft removed as of CMake 3.27.
+add_test_executable(new_with_prefix "${EXPECTED_PYTHON}::Python" "")
+add_test_executable(new_without_prefix "${Python3_LIBRARIES}" "${Python3_INCLUDE_DIRS}")
diff --git a/vcpkg/scripts/test_ports/vcpkg-ci-python3/project/main.c b/vcpkg/scripts/test_ports/vcpkg-ci-python3/project/main.c
new file mode 100644
index 0000000..cdd5cbe
--- /dev/null
+++ b/vcpkg/scripts/test_ports/vcpkg-ci-python3/project/main.c
@@ -0,0 +1,19 @@
+#include <Python.h>
+
+int main()
+{
+ PyConfig config;
+ PyConfig_InitPythonConfig(&config);
+ config.write_bytecode = 0;
+ PyConfig_SetString(&config, &config.program_name, L"test");
+
+ PyStatus status = Py_InitializeFromConfig(&config);
+ if (PyStatus_Exception(status)) {
+ PyConfig_Clear(&config);
+ Py_ExitStatusException(status);
+ }
+
+ Py_FinalizeEx();
+ PyConfig_Clear(&config);
+ return 0;
+}