Справка по сборке CMake для `pyembree`

Мне нужна помощь в создании из исходников с помощью CMake для Windows. Более подробная информация об истории этого вопроса приведена здесь, на GitHub. Поддержка Windows для conda-forge была только что удалена, поэтому мы будем очень благодарны за любую помощь, которая может быть предоставлена!

инструкции по установке

Система

Проверено на:

ОС: Windows 10 x64 Professional, сборка 1909Python: 3.8.10

Шаги

  1. Установите Microsoft Visual C ++ 14.X и Windows 10 SDK . Они необходимы для строительства cython код.

(ПРИМЕЧАНИЕ: версия Microsoft Visual Studio не совпадает с версией Microsoft Visual C++. Visual Studio 2015, 2017 и 2019 все имеют инструменты сборки MSVCv14X. На момент написания этой статьи установка Visual Studio 2019 Build Tools с

MSVCv142 - VS 2019 C++ x64/x86 build tools и Windows 10 SDK (10.0.18362.0)

компонентов будет достаточно (выберите Desktop development with C++ Рабочая нагрузка при установке Visual Studio 2019).

  1. Установите vcpkg в C:\\vcpkg и добавьте путь к вашему System Environment Variables:
      C:
mkdir vcpkg
cd C:\\vcpkg
git clone https://github.com/Microsoft/vcpkg.git
bootstrap-vcpkg.bat
vcpkg integrate install
  1. Установить embree2 64-bit:
      vcpkg install embree2:x64-windows

ПРИМЕЧАНИЕ. На сегодняшний день Pyembree по-прежнему использует Embree 2 и не обновляется для Embree 3.

  1. Установите cmake.

  2. Создайте папку своего проекта и инициализируйте виртуальную среду с помощью venv (Использовать Python 3.6 - 3.8). В этом примере Python 3.8.5 x64-bit выбрана, поскольку это версия Python, используемая в Miniconda py38_4.9.2.

  3. Установите следующие пакеты:

      py -m pip install numpy cython cmake ninja scikit-build wheel setuptools pyvista pykdtree
  1. Добавьте следующие модули cmake в папку модулей cmake вашей системы (например, C:\Program Files\CMake\share\cmake-3.21\Modules\).

  2. Перейдите к <virtual environment folder>\Lib\site-packages и клонировать репо:

      git clone https://github.com/scopatz/pyembree.git
  1. Измените каталоги в папку и создайте следующий верхний уровень
      cmake_minimum_required(VERSION 3.21.0)
project(pyembree
    VERSION 0.1.6
    LANGUAGES CXX
)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED True)

if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
endif()

set(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake")

find_package(PythonExtensions REQUIRED)
find_package(Cython REQUIRED)
find_package(embree 2 CONFIG REQUIRED)

add_subdirectory(${PROJECT_NAME})
  1. Перейдите в подпапку и создайте следующий подуровень CMakeLists.txt:
      add_cython_target(mesh_construction.pyx CXX)
add_cython_target(rtcore_scene.pyx CXX)
add_cython_target(rtcore.pyx CXX)
add_cython_target(triangles.pyx CXX)

add_library(${PROJECT_NAME} STATIC ${mesh_constructions} ${rtcore_scene} ${rtcore} ${triangles})

target_sources(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_include_directories(${PROJECT_NAME}
    PUBLIC "<system python path>/include"
    PUBLIC "C:/vcpkg/installed/x64-windows/include/embree2"
    PUBLIC "<virtual environment folder>/Lib/site-packages/numpy/core/include"
)

target_link_directories(${PROJECT_NAME}
    PUBLIC "<system python path>/libs"
    PUBLIC "C:/vcpkg/installed/x64-windows/lib"
    PUBLIC "C:/vcpkg/installed/x64-windows/bin"
    PUBLIC "<virtual environment folder>/Lib/site-packages/numpy/core/lib"
)

target_link_libraries(${PROJECT_NAME}
    embree
)

python_extension_module(${PROJECT_NAME})

install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION lib)

замена <system python path> (например C:/Program Files/Python38) и <virtual environment folder> соответственно.

  1. Вернитесь в папку верхнего уровня и создайте следующий setup.py файл:
      from setuptools import find_packages
from skbuild import setup

import numpy as np
from Cython.Build import cythonize

include_path = [np.get_include()]

ext_modules = cythonize('pyembree/*.pyx', language_level=3, include_path=include_path)
for ext in ext_modules:
    ext.include_dirs = include_path
    ext.libraries = ["embree"]

setup(
    name="pyembree",
    version='0.1.6',
    ext_modules=ext_modules,
    zip_safe=False,
    packages=find_packages(),
    include_package_data=True
)
  1. Добавьте следующую строку вверху каждого *.pyx и *.pxd файл в:
      # distutils: language=c++
  1. Выполните сборку и установку, запустив следующее с верхнего уровня pyembree папка:
      py setup.py build
py setup.py install
  1. Наконец, установите rtree и trimesh:
      py -m pip install rtree trimesh

Текущий вызов

Я застрял.

  1. В настоящее время мне нужно скопировать и вставить embree заголовки и библиотеки ( .lib и .dll) в исходную папку ( <virtual environment folder>/Lib/site-packages/pyembree) и сгенерированную папку сборки ( <virtual environment folder>\Lib\site-packages\pyembree\_skbuild\win-amd64-3.8\cmake-build\pyembree)

Есть ли команда копирования файлов, которую я могу использовать в CMake?

  1. При беге py setup.py build, Я получаю следующий вывод с ошибкой о том, что компоновщик не может открыть входной файл embree.lib. В выводе я вижу, что путь к embree.lib не добавляется в командной строке.

Любая помощь по этой ошибке также будет оценена! В частности, ошибка LNK1181 для MSVC означает

A /LIBPATH statement that specifies the directory containing filename is missing

так что, если бы кто-то мог помочь мне с правильной инструкцией CMake, чтобы добавить это, это было бы признательно!

      py setup.py build


--------------------------------------------------------------------------------
-- Trying "Ninja (Visual Studio 15 2017 Win64 v141)" generator
--------------------------------
---------------------------
----------------------
-----------------
------------
-------
--
Not searching for unused variables given on the command line.
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):     
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell  
  CMake that the project does not need compatibility with older versions.   


-- The C compiler identification is MSVC 19.16.27045.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- The CXX compiler identification is MSVC 19.16.27045.0
CMake Warning (dev) at C:/Project/.venv/Lib/site-packages/cmake/data/share/cmake-3.21/Modules/CMakeDetermineCXXCompiler.cmake:167 (if):
  Policy CMP0054 is not set: Only interpret if() arguments as variables or
  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  Quoted variables like "MSVC" will no longer be dereferenced when the policy
  is set to NEW.  Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
  CMakeLists.txt:4 (ENABLE_LANGUAGE)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at C:/Project/.venv/Lib/site-packages/cmake/data/share/cmake-3.21/Modules/CMakeDetermineCXXCompiler.cmake:188 (elseif):
  Policy CMP0054 is not set: Only interpret if() arguments as variables or
  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  Quoted variables like "MSVC" will no longer be dereferenced when the policy
  is set to NEW.  Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
  CMakeLists.txt:4 (ENABLE_LANGUAGE)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Project/.venv/Lib/site-packages/pyembree/_cmake_test_compile/build
--
-------
------------
-----------------
----------------------
---------------------------
--------------------------------
-- Trying "Ninja (Visual Studio 15 2017 Win64 v141)" generator - success
--------------------------------------------------------------------------------

Configuring Project
  Working directory:
    C:\Project\.venv\lib\site-packages\pyembree\_skbuild\win-amd64-3.8\cmake-build
  Command:
    cmake 'C:\Project\.venv\lib\site-packages\pyembree' -G Ninja '-DCMAKE_INSTALL_PREFIX:PATH=C:\Project\.venv\lib\site-packages\pyembree\_skbuild\win-amd64-3.8\cmake-install' '-DPYTHON_EXECUTABLE:FILEPATH=C:\Project\.venv\Scripts\python.exe' -DPYTHON_VERSION_STRING:STRING=3.8.5 '-DPYTHON_INCLUDE_DIR:PATH=C:\Program Files\Python38\Include' '-DPYTHON_LIBRARY:FILEPATH=C:\Program Files\Python38\libs\python38.lib' -DSKBUILD:BOOL=TRUE '-DCMAKE_MODULE_PATH:PATH=C:\Project\.venv\lib\site-packages\skbuild\resources\cmake' -DCMAKE_BUILD_TYPE:STRING=Release

-- The CXX compiler identification is MSVC 19.16.27045.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: C:/Project/.venv/Scripts/python.exe (found version "3.8.5")
-- Found PythonLibs: optimized;C:/Program Files/Python38/libs/python38.lib;debug;C:/Program Files/Python38/libs/python38_d.lib (found version "3.8.5")
-- Found Cython: C:/Project/.venv/Scripts/cython.exe
-- Found PythonLibs: optimized;optimized;optimized;C:/Program Files/Python38/libs/python38.lib;optimized;debug;optimized;C:/Program Files/Python38/libs/python38_d.lib;debug;C:/Program Files/Python38/libs/python38_d.lib (found version "3.8.5")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Project/.venv/Lib/site-packages/pyembree/_skbuild/win-amd64-3.8/cmake-build
[0/1] Install the project...
-- Install configuration: "Release"
-- Up-to-date: C:/Project/.venv/lib/site-packages/pyembree/_skbuild/win-amd64-3.8/cmake-install/lib/pyembree.lib

copying pyembree\__init__.py -> _skbuild\win-amd64-3.8\cmake-install\pyembree\__init__.py

running build
running build_py
copying _skbuild\win-amd64-3.8\cmake-install\pyembree\__init__.py -> _skbuild\win-amd64-3.8\setuptools\lib.win-amd64-3.8\pyembree
running egg_info
writing pyembree.egg-info\PKG-INFO
writing dependency_links to pyembree.egg-info\dependency_links.txt
writing top-level names to pyembree.egg-info\top_level.txt
reading manifest file 'pyembree.egg-info\SOURCES.txt'
writing manifest file 'pyembree.egg-info\SOURCES.txt'
copied 1 files
running build_ext
building 'pyembree.mesh_construction' extension
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Project\.venv\lib\site-packages\numpy\core\include -IC:\Project\.venv\include "-IC:\Program Files\Python38\include" "-IC:\Program Files\Python38\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files 
(x86)\Windows Kits\10\include\10.0.19041.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt" /EHsc /Tppyembree\mesh_construction.cpp /Fo_skbuild\win-amd64-3.8\setuptools\temp.win-amd64-3.8\Release\pyembree\mesh_construction.obj
mesh_construction.cpp
C:\Project\.venv\lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(14) : Warning Msg: Using deprecated NumPy API, disable it with #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
pyembree\mesh_construction.cpp(2074): warning C4244: '=': conversion from 'npy_intp' to 'int', possible loss of data
pyembree\mesh_construction.cpp(2353): warning C4244: '=': conversion from 'npy_intp' to 'int', possible loss of data
pyembree\mesh_construction.cpp(2362): warning C4244: '=': conversion from 'npy_intp' to 'int', possible loss of data
pyembree\mesh_construction.cpp(2940): warning C4244: '=': conversion from 'npy_intp' to 'int', possible loss of data
pyembree\mesh_construction.cpp(2949): warning C4244: '=': conversion from 'npy_intp' to 'int', possible loss of data
pyembree\mesh_construction.cpp(3245): warning C4244: '=': conversion from 'npy_intp' to 'int', possible loss of data
pyembree\mesh_construction.cpp(3254): warning C4244: '=': conversion from 'npy_intp' to 'int', possible loss of data
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Project\.venv\libs "/LIBPATH:C:\Program Files\Python38\libs" "/LIBPATH:C:\Program Files\Python38" /LIBPATH:C:\Project\.venv\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x64" embree.lib /EXPORT:PyInit_mesh_construction _skbuild\win-amd64-3.8\setuptools\temp.win-amd64-3.8\Release\pyembree\mesh_construction.obj /OUT:_skbuild\win-amd64-3.8\setuptools\lib.win-amd64-3.8\pyembree\mesh_construction.cp38-win_amd64.pyd /IMPLIB:_skbuild\win-amd64-3.8\setuptools\temp.win-amd64-3.8\Release\pyembree\mesh_construction.cp38-win_amd64.lib
LINK : fatal error LNK1181: cannot open input file 'embree.lib'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30037\\bin\\HostX86\\x64\\link.exe' failed with exit status 1181

1 ответ

CMake на самом деле не требуется. Полные инструкции см. В моем решении по установке pyembreeв Windows без Conda #468 .

Другие вопросы по тегам