0

I am building an application using Pybind11 and CMake. I got almost everything to work, but there are two things that I cannot figure out:

1.) No matter what I do, I only get a Debug folder with my .pyd files in it. How do I force CMake to make a Release version? -DCMAKE_BUILD_TYPE=Release on the command line does not do it, and setting it in the CMakeFiles.txt doesn't either.

2.) After successful building, I would like to have my .pyd files copied to my site-packages folder. I thought that the last line in my CMakeFiles.txt would do that, but it doesn't. Or do I have to invoke something besides cmake --build .?

Here's my CMakeFiles.txt:

cmake_minimum_required(VERSION 3.15...3.29)
project(b LANGUAGES CXX)

set(CMAKE_BUILD_TYPE Release)

set(pybind11_DIR C:/Users/peter/.virtualenvs/b_tool-z3PwOKEe/Lib/site-packages/pybind11/share/cmake/pybind11)
set(PYBIND11_FINDPYTHON ON)
find_package(pybind11 CONFIG REQUIRED)

set(CMAKE_CXX_STANDARD 20 CACHE STRING "C++ version selection")

include_directories(C:/Users/peter/AppData/Local/Programs/Python/Python310/include
C:/Users/peter/.virtualenvs/b_tool-z3PwOKEe/Lib/site-packages/pybind11/include
modules/surface_mesh/include
modules/magnet/include
include
C:/3rd_party/glm)


####################################################################
# mesh
####################################################################

add_library(sfc_elements modules/surface_mesh/src/sfc_elements.cpp)

pybind11_add_module(surface_mesh modules/surface_mesh/src/surface_mesh.cpp)
target_link_libraries(surface_mesh PRIVATE sfc_elements)    

####################################################################
# magnet
####################################################################

add_library(ring modules/magnet/src/ring.cpp)
add_library(b_ring modules/magnet/src/b_ring.cpp)
add_library(cel modules/magnet/src/cel.cpp)

pybind11_add_module(CMagnet modules/magnet/src/c_magnet.cpp)
target_link_libraries(CMagnet PRIVATE ring) 
target_link_libraries(CMagnet PRIVATE b_ring)
target_link_libraries(CMagnet PRIVATE cel)

install(TARGETS surface_mesh CMagnet COMPONENT python DESTINATION C:/Users/peter/.virtualenvs/b_tool-z3PwOKEe/Lib/site-packages)
5
  • Single question per question post, please. install() commands tell CMake to do things at installing stage. You could invoke that state e.g. with cmake --install. Commented Feb 9 at 0:02
  • Which CMake generator do you use for configure the project? If you are using "Visual Studio" generator, then selecting build type is performed on build stage, by --config parameter to cmake --build. See that question for more details. Commented Feb 9 at 9:14
  • CMake just remains a mystery to me. What do I have to do to to have CMake copy the generated .pyd files to some destination? Commented Feb 11 at 20:01
  • Have you checked that question? Its answers describe several ways for copy files. Commented Feb 11 at 20:03
  • Yes, thanks, --config Release is what I was looking for. There's one more thing now: How do I specify the optimization level of the compiler? Is Release O2 or O3? Commented Mar 17 at 23:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.