Skip to content

Commit cd4ab87

Browse files
committed
Merge branch 'update/cmake' into 'develop'
Updating tools cmake for Windows See merge request njoy/tools!23
2 parents af4f1cb + 9e87e56 commit cd4ab87

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ cmake_dependent_option(
3131
"BUILD_TESTING AND NOT ${subproject}" OFF
3232
)
3333

34-
3534
cmake_dependent_option(
3635
tools.python
3736
"Build tools python bindings" ON
@@ -56,11 +55,6 @@ string( CONCAT prefix
5655
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
5756
)
5857

59-
string( CONCAT prefix
60-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src>"
61-
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
62-
)
63-
6458
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
6559
# tools : library
6660
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

cmake/unit_testing_python.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ enable_testing()
66

77
function( add_python_test name source )
88

9+
set(PYTHONPATH_PARTS ${TOOLS_PYTHONPATH} $ENV{PYTHONPATH})
10+
string( JOIN "${PATH_DELIM}" PYTHONPATH_VALUE ${PYTHONPATH_PARTS})
11+
912
set( test_name "tools.python.${name}.test" )
1013
add_test( NAME ${test_name}
1114
COMMAND ${PYTHON_EXECUTABLE} -m unittest -v test/${source}
1215
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/python )
1316
set_tests_properties( ${test_name}
1417
PROPERTIES ENVIRONMENT
15-
PYTHONPATH=${TOOLS_PYTHONPATH}:$ENV{PYTHONPATH})
18+
"PYTHONPATH=${PYTHONPATH_VALUE}")
1619

1720
endfunction()
1821

python/CMakeLists.txt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)