# Copyright 2016, Raffi Enficiaud.
#
# The cmake-pip module SHOULD be found here: the extension declares
# cmake_install_component, and cmake-pip only injects
# -Dcmakepip_DIR=<cmake_pip>/cmake_modules when cmake_install_component is set.

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)

find_package(cmakepip REQUIRED)
if(NOT (COMMAND python_package_add_target))
  # REQUIRED above should do, just in case ...
  message(FATAL_ERROR "python_package_add_target not found")
endif()

# WITH_SOABI appends the canonical platform suffix to the module file name
python3_add_library(cmake_test MODULE WITH_SOABI
    src/python_header.hpp
    src/python_dummy_ext.cpp)

# this is the module declaration
python_package_add_target(TARGET cmake_test
                          DESTINATION test_path/
                          PYTHON_PACKAGE first_package)

# NOTE: a guarded python_package_create() call used to sit here, testing a
# pythondist_first_package_DESTINATION variable that has never existed under any
# spelling -- the guard was always false and the branch never ran. The package
# *declaration* protocol is now the configure-time manifest written by
# python_package_add_target above (cmake_pip_packages.txt in the build tree);
# python_package_create is the legacy packaging path and is not exercised here.
