@@ -27,7 +27,14 @@ if(tools.python)
2727
2828 message ( STATUS "Building tools' python API" )
2929
30- set ( TOOLS_PYTHONPATH "${CMAKE_CURRENT_BINARY_DIR} " )
30+ set ( tools_PYTHONPATH "$<TARGET_FILE_DIR:njoy::tools.python>" )
31+
32+ # Windows and unix have different delimiter for paths
33+ if (WIN32 )
34+ set (PATH_DELIM "\; " )
35+ else ()
36+ set (PATH_DELIM ":" )
37+ endif ()
3138
3239 if ( tools.tests )
3340 include ( ${PROJECT_SOURCE_DIR} /cmake/unit_testing_python.cmake )
@@ -36,6 +43,9 @@ if(tools.python)
3643 # generate python stubs if possible
3744 find_program (pybind11stubgen_exe pybind11-stubgen)
3845
46+ set (PYTHONPATH_PARTS ${tools_PYTHONPATH} $ENV{PYTHONPATH} )
47+ string ( JOIN "${PATH_DELIM} " PYTHONPATH_VALUE ${PYTHONPATH_PARTS} )
48+
3949 set (stubdir "${CMAKE_CURRENT_SOURCE_DIR} /stubs/tools" )
4050 if (pybind11stubgen_exe)
4151 # the following command executes the pybind11-stubgen executable found via find_program
@@ -45,7 +55,7 @@ if(tools.python)
4555 # If the stubs fail to generate then this command exits gracefully and allows the build to continue.
4656 add_custom_command (
4757 TARGET tools.python POST_BUILD
48- COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${tools_PYTHONPATH} : ${tools_PYTHONPATH} : $ENV{PYTHONPATH} ${pybind11stubgen_exe} tools -o ${CMAKE_CURRENT_SOURCE_DIR} /stubs &> ${CMAKE_CURRENT_BINARY_DIR} /pybind11-stubgen.log || true
58+ COMMAND ${CMAKE_COMMAND} -E env " PYTHONPATH=${PYTHONPATH_VALUE} " ${pybind11stubgen_exe} tools -o ${CMAKE_CURRENT_SOURCE_DIR} /stubs &> ${CMAKE_CURRENT_BINARY_DIR} /pybind11-stubgen.log || true
4959 COMMAND ${CMAKE_COMMAND} -E rename ${stubdir} /__init__.pyi ${stubdir} /tools.pyi &> /dev/null || true
5060 COMMAND ${CMAKE_COMMAND} -E copy_directory ${stubdir} / ${CMAKE_CURRENT_BINARY_DIR}
5161 COMMENT "Building tools' python stub files via pybind11-stubgen. See pybind11-stubgen.log for details."
0 commit comments