# Copyright 2016, Raffi Enficiaud.

cmake_minimum_required(VERSION 3.21)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

enable_testing()

project(TestCMakePIPExt)

# Development.Module: headers and platform-correct linking for extension modules;
# Python3_EXECUTABLE is pinned by cmake-pip to the driving interpreter.
find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED)

# This REQUIRED is satisfiable: setup.py declares cmake_install_component, so
# cmake-pip injects -Dcmakepip_DIR=<cmake_pip>/cmake_modules.
find_package(cmakepip REQUIRED)

# the target name matches the module name (PyInit_cmake_test2), which becomes the
# file name of the extension; WITH_SOABI appends the canonical platform suffix
python3_add_library(cmake_test2 MODULE WITH_SOABI
    src/python_header.hpp
    src/python_dummy_ext.cpp)

# The declaration: emits the install rules with COMPONENT pythondist_EXT_TEST and
# records the package into the configure-time manifest (cmake_pip_packages.txt).
# setup.py addresses it by the PYTHON_PACKAGE name ("ext_test"), which the python
# side resolves through that manifest. The destination is the python package
# directory, relative to the root of the staged distribution.
python_package_add_target(TARGET cmake_test2
                          PYTHON_PACKAGE ext_test
                          DESTINATION ext_test_with_cmake_python_package)

# A registered test whose output is unmistakable in a pip log: the suite asserts the
# string is ABSENT from this fixture's install -- setup.py does not opt into
# cmake_run_tests, and ctest must not run by default.
add_test(NAME cmakepip_probe
         COMMAND ${CMAKE_COMMAND} -E echo cmake_pip_ctest_probe)
