Почему мой CMakeLists.txt включается в мой пакет Python?C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Почему мой CMakeLists.txt включается в мой пакет Python?

Сообщение Anonymous »

Я создаю пакет Python с помощью scikit-build и Pybind11, но у меня возникла проблема: мой пакет в site-packages включает один из моих CMakeLists.txt. Вот структура моего проекта:

Код: Выделить всё

pybind11-example/
├── .venv/...
├── tests/...
├── src/
│   ├── example/
│   │   ├── __init__.py             # Python package initialization
│   │   ├── example.pyi             # Package type hinting
│   │   └── CMakeLists.txt          # Package-specific CMake config
│   ├── mylib/
│   │   ├── CMakeLists.txt          # Library-specific CMake config
│   │   ├── mylib.cpp               # Shared library implementation
│   │   └── mylib.h                 # Shared library header with exports
│   └── example.cpp                 # C++ source with pybind11 bindings
├── extern/
│   └── pybind11/...                # pybind11 submodule
├── CMakeLists.txt                  # Main CMake build configuration
└── pyproject.toml                  # Python project configuration
Конкретный файл CMakeLists.txt, копируемый в пакеты моего сайта, является CMake для конкретного пакета:

Код: Выделить всё

example/
├── __pycache__/...
├── __init__.py
├── CMakeLists.txt
├── example.cpython-314-x86_64-linux-gnu.so
├── example.pyi
└── libmylib.so
Содержимое простое:

Код: Выделить всё

install(FILES
__init__.py
example.pyi
DESTINATION example
)
Мой файл CMakeLists.txt верхнего уровня для полноты:

Код: Выделить всё

cmake_minimum_required(VERSION 3.18...4.0)
project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX)

set(PYBIND11_FINDPYTHON ON)
add_subdirectory(extern/pybind11)
add_subdirectory(src/mylib)
add_subdirectory(src/example)

target_compile_definitions(mylib PRIVATE BUILDING_MYLIB)
set_target_properties(mylib PROPERTIES
RUNTIME_OUTPUT_DIRECTORY $
)

pybind11_add_module(example src/example.cpp)
target_include_directories(example PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src)
target_link_libraries(example PRIVATE mylib)

if(NOT WIN32)
set_target_properties(example PROPERTIES
INSTALL_RPATH "$ORIGIN"
BUILD_WITH_INSTALL_RPATH TRUE
)
endif()

# Install Python files
install(TARGETS example
LIBRARY DESTINATION example
)

# Install library files
install(TARGETS mylib
RUNTIME DESTINATION example
LIBRARY DESTINATION example
)

и мой pyproject.toml:

Код: Выделить всё

[project]
name = "example"
version = "0.0.1"

[build-system]
requires = ["scikit-build-core", "pybind11"]
build-backend = "scikit_build_core.build"
Я собираю с помощью команды pip install. --force-reinstall --no-cache-dir -v, который указывает, что каталог примера будет удален. У меня не было идей, что попытаться решить проблему. Я ожидаю пакет без CMakeLists.txt.
Изменить:
Я заметил в журнале установки pip следующие строки:

Код: Выделить всё

 -- Build files have been written to: /tmp/tmp5inwaohg/build
*** Building project with Ninja...
[1/4] Building CXX object src/mylib/CMakeFiles/mylib.dir/mylib.cpp.o
[2/4] Linking CXX shared library src/mylib/libmylib.so
[3/4] Building CXX object CMakeFiles/example.dir/src/example.cpp.o
[4/4] Linking CXX shared module example.cpython-314-x86_64-linux-gnu.so
*** Installing project into wheel...
-- Install configuration: "Release"
-- Installing: /tmp/tmp5inwaohg/wheel/platlib/example/__init__.py
-- Installing: /tmp/tmp5inwaohg/wheel/platlib/example/example.pyi
-- Installing: /tmp/tmp5inwaohg/wheel/platlib/example/example.cpython-314-x86_64-linux-gnu.so
-- Installing: /tmp/tmp5inwaohg/wheel/platlib/example/libmylib.so
*** Making wheel...
*** Created example-0.0.1-cp314-cp314-linux_x86_64.whl
Building wheel for example (pyproject.toml) ... done
Похоже, это говорит о том, что CMakeLists.txt не добавляется из CMake.

Подробнее здесь: https://stackoverflow.com/questions/797 ... on-package
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»