# Copyright 2016, Raffi Enficiaud.

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

enable_testing()

project(TestCMakePIPExt)

# The modern python detection: Development.Module carries exactly what an extension
# module needs (headers, and the platform-correct linking policy -- no libpython on
# linux), and Python3_EXECUTABLE is pinned by cmake-pip to the driving interpreter.
find_package(Python3 COMPONENTS Interpreter Development.Module REQUIRED)

# a static library in a subdirectory: its objects survive the --fresh emulation of
# the editable installs, see helper_library/CMakeLists.txt
add_subdirectory(helper_library)

# MODULE WITH_SOABI produces the canonical extension file name
# (cmake_test.cpython-312-<platform>.so) -- no hand-rolled suffix detection needed.
python3_add_library(cmake_test MODULE WITH_SOABI
    src/python_header.hpp
    src/python_dummy_ext.cpp)
target_link_libraries(cmake_test PRIVATE dummy_helper)

# What the project produces is declared explicitly: cmake-pip stages this component
# ("python_module", named by cmake_install_component in setup.py) into the package with
# `cmake --install --component`. The destination is relative to the root of the staged
# distribution, ie. it is the python package directory.
install(TARGETS cmake_test
        DESTINATION simple_ext_test1
        COMPONENT python_module)
